Document directory
- 1. Define Div
- 2. css2 Box Model
- 3. background processing is used for all secondary images.
I have been looking for such a tutorial for a long time and finally found something similar!
Source: web designer
Responsible editor: Donger
The biggest difference between CSS layout and traditional table layout is that the original positioning uses tables to control the spacing of text layout sections through table spacing or colorless and transparent GIF images; currently, the layer (DIV) is used to locate and control the section spacing through attributes such as margin, padding, and border of the layer.
1. Define Div
Analyze a typical Div definition example:
# Sample {margin: 10px 10px 10px 10px;
Padding-left: 20px;
Padding-top: 20px;
Padding-Right: 10px;
Padding-bottom: 10px;
Border-Right: # CCC 2px solid;
Border-bottom: # CCC 2px solid;
Border-left: # CCC 2px solid;
Border-top: # CCC 2px solid;
Background: URL (images/bg_poem.jpg) # fefefefe no-repeat right bottom;
Color: #666;
Text-align: center;
Line-Height: 150%; width: 60% ;}
Description:
- The layer name is sample. You can call this style with <Div id = "sample"> on the page.
- Margin refers to the margin left outside the border of the layer. It is used for margin or to make a gap with other layers. "10px 10px 10px" represents "Top right bottom left" (clockwise direction) Four margins, if the same, can be abbreviated as "margin: 10px ;". If the margin is zero, it must be written as "margin: 0px ;". Note: When the value is zero, except for the RGB color value 0%, it must be followed by the percent sign. In other cases, it may not be followed by the unit "PX ". Margin is a transparent element and cannot define colors.
- Padding refers to the blank between the border of the layer and the content of the layer. "Padding-left" refers to the distance from the left border to the content, and so on. If they are all the same, it can be abbreviated as "padding: 0px ". Padding is a transparent element and cannot define colors.
- Border refers to the border of the layer, "border-Right: # CCC 2px solid;" defines the right border color of the layer as "# CCC", and the width is "2px ", the style is a "solid" straight line. To use the dotted line style, you can use "dotted ".
- Background is the background of the definition layer. Define the image background in two levels. Use "URL (../images/bg_logo.gif)" to specify the path of the background image, and then define the background color "# fefefe ". "On-repeat" indicates that the background image does not need to be repeated. If you need to repeat-x horizontally, repeat-y is used vertically ", repeat is used to repeatedly fill the entire background ". The following "right bottom;" indicates that the background image starts from the bottom right corner. If there is no background image, you can only define the background color background: # fefefefe
- Color is used to define the font color. It has been described in the previous section.
- Text-align is used to define the content arrangement in the layer. Center is centered, left is left, and right is right.
- Line-height defines the Row Height. 150% refers to 150% of the standard height. It can also be written as follows: Line-Height: 1.5 or line-Height: 1.5em.
- Width is the width of the defined layer. You can use a fixed value, for example, 500px, or a percentage, as shown in "60% ". Note that this width only refers to the width of your content, excluding margin, border, and padding. But in some browsers, this is not so defined. You need to try more.
The actual performance of this layer is as follows:
Here is the demo content, here is the demo content,
Here is the demo content, here is the demo content,
Here is the demo content, here is the demo content,
Here is the demo content...
We can see that the border is 2px Gray, the background image is not repeated in the lower right corner, the content is 20 PX away from the left border, the content is centered, everything is the same as expected. Hoho, although not easy to understand, is the most basic. If you master it, you have learned half of the CSS layout technology. That's it. It's not difficult! (What is the other half? The other half is the positioning between layers. I will explain it later .)
2. css2 Box Model
Since the release of css1 in 1996, W3C organizations have suggested placing all the images on webpages in a box. Designers can create definitions to control the attributes of this box, these objects include paragraphs, lists, titles, images, and layers. <div>. The box model mainly defines four areas: content, padding, border, and margin ). The sample layer mentioned above is a typical box. For beginners, it is often difficult to understand the levels, relationships, and mutual influences between margin, background-color, background-image, padding, content, and border. Here we provide a 3D box model for your understanding and memory.
3. background processing is used for all secondary images.
Using XHTML + CSS layout, there is a technology that you don't get used to at the beginning. It should be said that it is a different way of thinking from the traditional table layout, that is: all secondary images are implemented using the background. Similar to this:
Background: URL (images/bg_poem.jpg) # fefefefe no-repeat right bottom;
Although can be directly inserted into the content, this is not allowed. Here, "secondary images" refer to images that are not part of the content to be expressed on the page, but only used for modification, interval, and reminder. For example, pictures in photo albums, pictures in news, and 3D box model pictures above are all part of the content. They can be directly inserted into the page using the element, other similar logo, title image, and list prefix images must be displayed in the background or CSS mode.
There are two reasons for doing this:
- The presentation is completely separated from the structure, and CSS is used to control all the appearance, which facilitates the revision.
- Make the page more easy to use and more friendly. For example, if a blind person uses a screen reader, the pictures implemented by background technology will not be read out.