Div + CSS learning Day 1

Source: Internet
Author: User

1 column fixed width
2 column fixed width Center
Adaptive width of three columns
4-column adaptive width Center
Five columns, two columns, and multiple blocks

 

 

Using Dreamweaver to start webpage design, its main advantages include: Code prompts, visual development environment, perfect support for CSS + Div

Fixed width of a column

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/> <br/> <MCE: style type =" text/CSS "> <! -- <Br/> # layout {Height: 300px; width: 400px; Background: #99 ffcc ;}< br/> --> </MCE: style> <style type = "text/CSS" mce_bogus = "1"> # layout {Height: 300px; width: 400px; Background: #99 ffcc ;} </style> <br/> </pead> </P> <br/> <p> <body> <br/> <Div id = "layout"> displayed here content of ID "layout" </div> <br/> </body> <br/> </ptml>

 

 

Center a column with fixed width
Compared with a column with a fixed width, we need to solve the problem of center. Here we use the margin attribute of CSS: margin. In IE6 and later versions and standard browsers, when you set the margin: auto; of a box model, you can center the box model.
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/> <br/> <MCE: style type =" text/CSS "> <! -- <Br/> # layout {Height: 300px; width: 400px; Background: #99 ffcc; margin: auto ;}< br/> --> </MCE: style> <style type = "text/CSS" mce_bogus = "1"> # layout {Height: 300px; width: 400px; Background: #99 ffcc; margin: auto ;} </style> <br/> </pead> </P> <br/> <p> <body> <br/> <Div id = "layout"> displayed here content of ID "layout" </div> <br/> </body> <br/> </ptml>

 

One-column adaptive width

The adaptive width is different from the browser. The width of the box model changes with the browser width. The percentage of width is used. When the width of a box model is not set, it is displayed relative to the browser by default.
Here, the selector type is the easiest place for new friends to confuse. Class: Refers to defining a class that can be referenced by multiple objects. Label: Refers to redefining the default HTML Tag, for example, you can define the body {margin: 0}, which means to set the outer margin of the body to 0, while H2 {color: # f00} sets the text color of all H2 labels to red; in advanced mode, the ID and pseudo class are put together, which is an unreasonable place and has been separated in cs4. Id starts with #. ID can only act on one object and cannot act on multiple objects. Priority is higher than class, which is the difference between ID and class.
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/> <br/> <MCE: style type =" text/CSS "> <! -- <Br/> body {margin: 0 ;}< br/> # layout {Height: 300px; width: 80%; Background: #99 ffcc ;} <br/> --> </MCE: style> <style type = "text/CSS" mce_bogus = "1"> body {margin: 0 ;} <br/> # layout {Height: 300px; width: 80%; Background: #99 ffcc ;} </style> <br/> </pead> </P> <br/> <p> <body> <br/> <Div id = "layout"> displayed here content of ID "layout" </div> <br/> </body> <br/> </ptml>

 

Center an adaptive width Column
Similarly, as with the fixed width center, we only need to set the DIV's outer margin to auto to realize center.

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/> <br/> <MCE: style type =" text/CSS "> <! -- <Br/> body {margin: 0 ;}< br/> # layout {Height: 300px; width: 80%; Background: #99 ffcc; margin: auto ;} <br/> --> </MCE: style> <style type = "text/CSS" mce_bogus = "1"> body {margin: 0 ;} <br/> # layout {Height: 300px; width: 80%; Background: #99 ffcc; margin: auto ;} </style> <br/> </pead> </P> <br/> <p> <body> <br/> <Div id = "layout"> displayed here content of ID "layout" </div> <br/> </body> <br/> </ptml>

 

 

One column, two blocks at most
The General website can be divided into the upper and lower structures, that is, the header, the middle body, and the bottom. We can use three Div blocks to divide them into headers, maincontent, and footer ).

 

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/> <br/> <MCE: style type =" text/CSS "> <! -- <Br/> body {margin: 0; padding: 0 ;}< br/># header {margin: 5px auto; width: 500px; Height: 80px; Background: #9f9 ;}< br/># main {margin: 5px auto; width: 500px; Height: 400px; Background: # 9ff ;}< br/># footer {margin: 5px auto; width: 500px; Height: 80px; Background: #9f9 ;}< br/> --> </MCE: style> <style type = "text/CSS" mce_bogus = "1"> body {margin: 0; padding: 0 ;}< br/># header {margin: 5px auto; width: 500px; Height: 80px; Background: #9f9 ;}< br/># main {margin: 5px auto; width: 500px; Height: 400px; Background: # 9ff ;} <br/> # footer {margin: 5px auto; width: 500px; Height: 80px; Background: #9f9 ;} </style> <br/> </pead> </P> <br/> <p> <body> <br/> <Div id = "Header"> displayed here content of ID "Header" </div> <br/> <Div id = "Main"> the content of ID "Main" is displayed here </div> <br/> <Div id = "footer"> the content of ID "footer" is displayed here </div> <br/> </body> <br/> </ptml>

Note: Many may ask: why is the spacing between two adjacent containers not 10px, but 5px? According to our normal understanding, we think it should be the sum of two values. In fact, here is the maximum value after the two values are merged. In the CSS manual, vertical adjacent outer margins of block-level elements are merged, while intra-row elements do not actually occupy the upper and lower margins. The left and right margins of the element in the row are not merged. Similarly, the margins of floating elements are not merged. Allow negative margin value, but be careful when using

 

Summary

1. Visual CSS generation and formatting
2. CSS abbreviations

3. CSS syntax

CSS syntax consists of the following three parts: the selector can be ID, class, or tag; the attribute and value are used to define a feature of this object. For example, if the length of a table is 120, the width is 60, and the format of CSS is used, the table {length: 120; width: 60;} is not easy to understand.

 

4. ID and class selector

ID can only correspond to one element on the page, just like our ID card number. Each person has a different ID. Class is a class and can correspond to multiple elements, such as first-year and third-class students, it may correspond to 10 20 students.

The priority of ID is higher than that of class. For example, James stayed to clean the students in Class 3 today. Therefore, class 3 students have a physical education class, while Xiao Ming's cleaning is an ID. Although Xiao Ming is also a student in class 3, the ID is higher than the class, so xiao ming executes the cleaning task.

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.