[Note-front-end] div + css layout basics, as well as error records, divcss

Source: Internet
Author: User

[Note-front-end] div + css layout basics, as well as error records, divcss

Currently, the website does not use <table> for front-end layout, but uses div + css.

The biggest advantage of using this method is that you can only maintain css while maintaining the page without modifying html. However, this method may not be easy for beginners to understand. Therefore, we will briefly describe the basics of using div + css layout. Is an example of using div + css layout: html and css: Body {font-size: 20px; font-weight: bold; color: white ;} . Back {background-color: gray; width: 1000px; height: 500px ;} . Top {background-color: orange; width: 500px; height: 100px; margin: 1% auto ;} . Middle {background-color: yellow; width: 500px; height: 100px; margin: 0 auto ;} . Middle_a {background-color: red; width: 30%; height: 100%; margin: 0 auto; float: left ;} . Middle_ B {background-color: green; width: 38%; height: 100%; margin: 0 1%; float: left ;} . Middle_c {background-color: blue; width: 30%; height: 100%; margin: 0 auto; float: left ;} . Bottom {background-color: purple; width: 500px; height: 100px; margin: 1% auto ;}</Style> Class = "back"> <Div Class = "top"> TOP </div> <div Class = "middle"> <Div Class = "middle_a"> The MIDDLE-A </div> <div Class = "middle_ B"> The MIDDLE-B </div> <div Class = "middle_c"> MIDDLE-C </div> <div Class = "bottom"> BOTTOM </div> </body> Error 1: mixed use of block div and floating divAt the same time, avoid the mixed use of block div and floating div in parallel div, otherwise it will easily cause display confusion. To cancel the effect of the green block float: left effect. Error 2: An error occurred while adding width to 100%.Here we use the background color to distinguish blocks, but this problem may occur if the border line is used to distinguish blocks. When the width values of middle_a, middle_ B, and middle_c both use percentages, when the sum is exactly 100%, the third block is automatically changed to the next row because the values in the middle cannot be placed. The main reason is that the border line also has width, so the width in <div class = 'middle'> is deemed to exceed the border line width because it exceeds the border line width.         

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.