Classic REM Layout

Source: Internet
Author: User

1. Effects of REM and em

Q. Em?
It is a unit of length, relative unit, and the unit of font-size relative to the parent element.
If the parent element font-size = 16px, 1em = 16px
Q. What is Rem?
It is a unit of length, which is a relative unit. It is a unit of font-size relative to the root element of the document. The root element is generally an HTML element.
If the HTML element font-size = 16px, 1rem = 16px
Q. How to use it?
As the interface grows, the DIV, text, and image become larger, and the REM layout is used.

2. How to automatically set the REM Value

Use js to monitor events with screen size changes. Generally, set 1rem = 100px,
If the design draft is 750px
Rule: The whole screen width is 7.5rem.

3. Write a rem use case


Classic Layout
Navigation Bar
Content
Label bar

 

HTML section

<Div class = "navbar"> <Div class = "nav-left"> [#] </div> <Div class = "nav-title"> title </div> <Div class = "nav-Right"> Settings </div> <Div class = "content"> <Div class = "S1"> carousel images </Div> <Div class = "box"> <Div class = "S2"> popular 1 </div> <Div class = "S3"> popular 2 </div> </Div> <ul> <li> Item 1 </LI> <li> Item 2 </LI> <li> Item 3 </LI> </ul> </div> <div class = "tabbar"> <ul> <li> homepage </LI> <li> Category </LI> <li> shopping cart </LI> <li> my </LI> </ul> </div>

CSS Section

 1 body{ 2     padding: 0; 3     margin: 0; 4     font-size: 0.32rem; 5 } 6 ul,li{ 7     list-style: none; 8     margin: 0; 9     padding: 0;10 }11 .navbar{12     width: 7.5rem;13     height: 0.88rem;14     background-color: #eaeaea;15     border-bottom: 1px solid #333;16 }17 .navbar>div{18     float: left;19     font-size: 0.32rem;20     height: 0.88rem;21     line-height: 0.88rem;22     text-align: center;23 }24 .navbar .nav-left{25     width: 1rem;26 }27 .navbar .nav-title{28     width: 5.5rem;29 }30 .navbar .nav-right{31     width: 1rem;32 }33 .tabbar{34     width: 7.5rem;35     height: 0.98rem;36     background-color: #eaeaea;37     border-top: 1px solid #333;38     position: fixed;39     bottom: 0;40 }41 .tabbar ul li{42     display: block;43     float: left;44     width: 1.825rem;45     text-align: center;46     line-height: 0.98rem;47 }48 .box>div{49     float: left;50     overflow: hidden;51 }52 .s1{53     width: 7.5rem;54     height: 3.75rem;55     background-color: lightblue;56 }57 .s2{58     width: 3.75rem;59     height: 3.75rem;60     background-color: lightcoral;61 }62 .s3{63     width: 3.75rem;64     height: 3.75rem;65     background-color: lightgoldenrodyellow;66 }67 .content ul li{68     height: 0.80rem;69     width: 7.5rem;70     display: block;71     float: left;72     border-bottom: 1px solid #555;73     line-height: 0.80rem;74     padding-left: 0.1rem;75 }    

JS Section

1 var doc = document.querySelector("html")2 doc.style.fontSize = "13.33333333vw"

 

Classic REM Layout

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.