通过改变A的大小来改变当前页面字体的大小,这一块要怎么写
回复讨论(解决方案)
单纯的css不能完成这个任务需求,需要js的干预。
window.onload = function(){ var content = document.getElementById('content'); var btn = document.getElementById('btn'); var btns = btn.getElementsByTagName('button'); for(var i = 0; i < btns.length; i++){ btns[i].index = i; btns[i].onclick = function(){ changeSize(this.index); } } var arr = ['12px', '14px', '16px']; function changeSize(n){ content.style.fontSize = arr[n]; }};
完整的代码:
<!doctype html><html><head> <meta charset="UTF-8"> <title></title></head><body><div id="btn"> <button>小</button> <button>中</button> <button>大</button></div><div id="content"> <p>1. 健康</p> <ul> <li>你会精力充沛,呼吸顺畅</li> <li>你会患上肺癌、呼吸系统疾病、心脏病</li> </ul></div><script> window.onload = function(){ var content = document.getElementById('content'); var btn = document.getElementById('btn'); var btns = btn.getElementsByTagName('button'); for(var i = 0; i < btns.length; i++){ btns[i].index = i; btns[i].onclick = function(){ changeSize(this.index); } } var arr = ['12px', '14px', '16px']; function changeSize(n){ content.style.fontSize = arr[n]; } };</script></body></html>
“Ems”: em,大小不固定 ,成为相对单位(body则相对浏览器的默认字体设置,子集相对父级), 浏览器默认设置字体大小为16px , 则1em = 16px , 且其可扩展,2em = 32px , 目前常用的字体大小px换算成em , 他们把字体大小用em 来表示,通过改变bodyd的什么就可以改变字体的大小请问这种写法要怎么写??
“Ems”: em,大小不固定 ,成为相对单位(body则相对浏览器的默认字体设置,子集相对父级), 浏览器默认设置字体大小为16px , 则1em = 16px , 且其可扩展,2em = 32px , 目前常用的字体大小px换算成em , 他们把字体大小用em 来表示,通过改变bodyd的什么就可以改变字体的大小请问这种写法要怎么写??
不建议直接改body,改body容易问题,所有字体都会变成同一个大小。等明天写个实例给你。
“Ems”: em,大小不固定 ,成为相对单位(body则相对浏览器的默认字体设置,子集相对父级), 浏览器默认设置字体大小为16px , 则1em = 16px , 且其可扩展,2em = 32px , 目前常用的字体大小px换算成em , 他们把字体大小用em 来表示,通过改变bodyd的什么就可以改变字体的大小请问这种写法要怎么写??
不建议直接改body,改body容易问题,所有字体都会变成同一个大小。等明天写个实例给你。
谢谢!
我需要的效果是通过点击A的大小,来改变所有页面字体的大小
如果字体大小是可以改变的,我就用em表示,如果是固定大小的就有px写死
$("html").css("font-size","12px");
<HTML><HEAD><TITLE>特定区域文字控制</TITLE><STYLE type=text/css>BODY { MARGIN-TOP: 0px; FONT-SIZE: 9pt; MARGIN-LEFT: 0px; MARGIN-RIGHT: 0px; FONT-FAMILY: "宋体"}A { FONT-WEIGHT: 400; FONT-SIZE: 9pt; COLOR: black; TEXT-DECORATION: none}A:hover { FONT-WEIGHT: 400; FONT-SIZE: 9pt; COLOR: red; TEXT-DECORATION: underline}A:active { FONT: 9pt "宋体"; CURSOR: hand; COLOR: #ff0033}.STYLE1 { font-size: 40px; font-family: "华文行楷"; color: #990000;}.STYLE2 { font-size: 30px; font-weight: bold; font-family: "黑体"; color: #0000FF;}</STYLE><META http-equiv=Content-Type content="text/html; charset=gb2312"><META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD><BODY bgColor=#fef4d9><BR><BR><CENTER><TABLE borderColor=#993399 border=5 borderlight="green"> <TBODY> <TR> <TD align=middle> <SCRIPT language=JavaScript>function doZoom(size){ document.getElementById('zoom').style.fontSize=size+'px'}</SCRIPT> <TABLE style="BORDER-RIGHT: #336699 1px solid; BORDER-TOP: #336699 1px solid; BORDER-LEFT: #336699 1px solid; BORDER-BOTTOM: #336699 1px solid" cellSpacing=0 width=200 align=center bgColor=#93bee2 border=0> <TBODY> <TR> <TD style="BORDER-BOTTOM: #336699 1px solid" width="83%" bgColor=#00FFFF>[<A href="javascript:doZoom(20)">大字</A> <A href="javascript:doZoom(14)">中字</A> <A href="javascript:doZoom(9)">小字</A>] <DIV></DIV></TD></TR> <TR bgColor=#ffffff> <TD id=zoom colSpan=2><div align="center">文字大小变化哦</div></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER></BODY></HTML>

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment