Solo div Self-adapting width layout CSS instance and expanding application scope

Source: Internet
Author: User

DIVCSS5 first introduce the Independent column of adaptive width, that is, the individual line width of the adaptive div layout. CSS self-adapting width layout method through the div CSS instance, and then the common use to fully grasp the adaptive exclusive row of a column of layout skills.

Key points: Adaptive, this time can not use a fixed CSS width value, this time can only use the width of a percentage of the expression width.

Key code: width:?% The Percent value in percent, and the natural object automatically calculates the width of the object based on the percentage set.

Instance CSS code:

      1. . box{width:60%; height:80px; border:1px solid #F00; margin:0 Auto}

Note: Here the width is set to 60%, in order to facilitate the observation of the effect, so set the height and red border, because the independent setting of a div box is generally centered, so set margin:0 auto

Full HTML source code (including HTML and CSS):

    1. <! DOCTYPE HTML>
    2. <html>
    3. <head>
    4. <Meta http-equiv= "content-type" content= "text/html; Charset=utf-8 " />
    5. <title> Independent One-width adaptive instance </title>
    6. <style>
    7. . box{width:60%; height:80px; border:1px solid #F00; margin:0 Auto}
    8. </style> Shanghai See STD Hospital
    9. </head>
    10. <body>
    11. <div class="box"> Content </div>
    12. </body>
    13. </html>

Instance effect:


Single row Adaptive Width instance

The above is a complete instance of the independent row adaptive width.

DIVCSS5 Expansion thinking:
1, in the General page layout, the general subject content is fixed width, so the specific setting width are determined by the artwork, but sometimes do not rule out the width is adaptive at this time can not set the fixed width style.
2, in the local div CSS layout, because the outermost layer is set specific width, and the lone child sometimes do not need to set the width style, so that the default div width is 100%, if an object set width fixed, While the subset does not set the width and set paddding-left or Padding-right (or two are set) this time the browser interpretation renders this subset of the div width will still be very smart to use the total width to subtract the padding occupied width. Shanghai Dermatosis Std Hospital General Situation when the layout is local, a single column of the div can be used without a float to set the specific width or percent width, because the browser will handle the width according to the parent of this layer intelligently.

Solo div Self-adapting width layout CSS instance and expanding application scope

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.