body
{
text-align: center
}
#content
{
text-align: left;
width: 700px;
margin: 0 auto
}
这会把网页内容都居中,所以在Content中又加入了
text-align: left 。
8. 用CSS来处理垂直对齐
垂直对齐用表格可以很方便地实现,设定表格单元 vertical-align: middle 就可以了。但对CSS来说这没用。如果你想设定一个导航条是2em高,而想让导航文字垂直居中的话,设定这个属性是没用的。
CSS方法是什么呢?对了,把这些文字的行高设为 2em:line-height: 2em ,这就可以了。
9. CSS在容器内定位
CSS的一个好处是可以把一个元素任意定位,在一个容器内也可以。比如对这个容器:
#container
{
position: relative
}
这样容器内所有的元素都会相对定位,可以这样用:
If you want to locate 30 points from the left and 5 points from the top, what can you do? BR>
#navigation
{
position: absolute;
left: 30px;
top: 5px
}
Of course, you can also do this:
margin: 5px 0 0 30px
Note that the order of the 4 numbers is: up, right, down, left. Of course, sometimes positioning rather than margins is better.
10. Background color straight to the bottom of the screen
Control in the vertical direction is beyond the capabilities of CSS. If you want the navigation bar to go straight to the bottom of the page like the content bar, using a table is very convenient, but if you only use CSS like this:
#navigation
{
background: blue;
width: 150px
}
A shorter navigation bar will not go straight to the bottom, it will end when the content ends halfway. What to do?
Unfortunately, the only way to cheat is to add a background image to the shorter column, with the same width as the column width, and make it the same color as the set background color.
body
{
background: url(blue-image.gif) 0 0 repeat-y
}
You cannot use em as the unit at this time, because then the trick will be revealed once the reader changes the font size, and you can only use px.
11. Comparison between Block and inline elements
All HTML elements are either block or inline. The characteristics of the block element are:
Always start on a new line;
Height, line height and top and bottom margins can all be controlled;
The width defaults to 100% of its container unless a width is set
,
,

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

