Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to judge different resolutions and display different widths by CSS

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how CSS judges different resolutions to display different widths". In daily operation, I believe many people have doubts about how CSS judges different resolutions to display different widths. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions of "how CSS judges different resolutions to display different widths". Next, please follow the editor to study!

1. Applicable domain description

In CSS DIV web pages, when the resolution is less than 1024px (pixels), the DIV structure object displays the 1000px width, and when the resolution is greater than 1024px, it shows the 1200px width and other requirements. The CSS is used to tamper with the reader exposure width to change the constructed web page width message (the web page width passively widens and narrows as the predator reveals the performance width).

With the development, more and more computer users flash screen discrimination rate is getting higher and higher, but some users are still using 1024px discrimination rate of the emergence screen (according to several browser resolution statistics platform lost data that will use 1200 discrimination rate the following users are few, but we still need to think about CSS structure at most 1024px discrimination rate users), if the web page structure width is static to 1200px 1024 Discriminant rate when users browse the web, a transfer bar appears at the bottom of the reader. In order to solve this problem, everyone can misappropriate the consistent agency width by using the CSS3 style to determine the width of the user's predator.

Second, apply CSS words and grammar

@ media screen and (arbitrary attribute) {CSS decision maker}

Notice here that the curly braces contain the CSS style selector to be changed.

Third, the unqualified identification rate shows the fancy case of different width.

1. DIVCSS small case description

We first set up a DIV box CSS named ".abc", configure its height to 300pxMagneCss frame as black, and set the equipment to center the margin:0 auto mechanism. At first, the two designs were configured to facilitate inspection.

We expose the width by manually dragging the browser, and then observe the box width transformation, when the browser width is adjusted to no more than 500px, the corresponding box width reveals 100px; when the reader width is not greater than 901px, the corresponding box width displays 200px; when the predator width is greater than 1201px, the box object width displays 1200px; when it is less than 1200px, the flash width is 900px.

2. CSS code

.abc {height:300px; border:1px solid # 000 Margin:0 auto} @ media screen and (min-width: 1201px) {.abc {width: 1200px}} / * css statement: abc reflects 1200px width when the device width is not less than 1201px (max-width: 1200px) {.abc {width: 900px}} / * abc reveals 900px width when reader width is not greater than 1200px * / @ media screen and ( Max-width: 901px) {.abc {width: 200px }} / * abc appears 200px width when the dabbler width is not greater than 901px * / @ media screen and (max-width: 500px) {.abc {width: 100px;}}

/ * abc shows 100px width when browser width is not greater than 500px * /

The need to hope is the pace of CSS code, from large to small typesetting CSS (judging that the larger the width of the reader, the more before), how because of logic, @ media determines that CSS troubleshooting will lead to judgment effective.

3. HTML code

No problem documentation .abc{ height:300px; border:1px solid # 000000 Margin:0 auto} @ media screen and (min-width: 1201px) {.abc {width: 1200px}} / * set the equipment to display the 1200px width when the reader width is not less than 1201px * / @ media screen and (max-width: 1200px) {.abc {width: 900px}} / * set the abc display 900px width * / @ media screen and (max-width: 900px) {.abc {width: 200px when the width of the hunter is not greater than 1200px }} / * abc reflects 200px width when reader width is not greater than 900px * / @ media screen and (max-width: 500px) {.abc {width: 100px;}} / * abc indicates 100px width when reader width is not greater than 500px * / CSS5 instance: my DIV width will change with browser width, try tampering with reader width

4. In order to be compatible with the following versions of IE9, it is important to refer to a google JS, or download html.

Just put the JS code into the tag, here directly introduce google online JS, you can download this JS file and HTML again.

5. Meimei is compatible with the HTML+CSS+JS source code of major readers.

No problem documentation .abc{ height:300px; border:1px solid # 000000 Margin:0 auto} @ media screen and (min-width: 1201px) {.abc {width: 1200px}} / * css explanation: set the equipment to display the 1200px width when the reader width is not less than 1201px * / @ media screen and (max-width: 1200px) {.abc {width: 900px}} / * set the equipment to represent the 900px width when the width of the predator is not greater than 1200px. Media screen and (max-width: 900px) {.abc {width: 200px }} / * abc shows 200px width when the dabble width is not greater than 900px * / @ media screen and (max-width: 500px) {.abc {width: 100px }} / * when the width of the predator is not greater than 500px, abc reveals the performance of the 100px width * / CSS5 instance: my DIV width will change with the width of the predator. Try rotating the reader width so that the study on "how CSS judges different resolutions to display different widths" is over. I hope you can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report