9 Div display: the magic of Block

Source: Internet
Author: User
Let's talk about block elements first. Elements in HTML can be divided into block and inline elements. The default display attribute of block elements is block, and the default display attribute of inline elements is inline. inline elements include:

A, abbr, acronym, B, BDO, big, BR, button, cite, code, dfn, Em, I, IMG, input, KBD, label, MAP, object, Q, SAMP, script, select, small, span, strike, strong, sub, sup, textarea, TT, VAR

Basefont, Font, S, U

Block elements include Address, BLOCKQUOTE, Div, DL, fieldset, form, h1-h6, HR, noframes, NoScript, ol, P, pre, table, UL center, Dir, isindex, menu.

By default, block elements occupy the position of one row, and the next element is forced to appear in the Next row. This is not the case for inline elements. inline elements make the next element automatically pasted to its own edge display, such as span and textbox...

Some inline elements are displayed as block elements for some design purposes. For example, element. After the element is displayed: block, it becomes a block element from the inline element, and then you can set attributes such as margin, padding, and border for this element. Refer to the design of this navigation bar:

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Style>
# Nav {

}
# Nav Li {
Float: left;
}
# Nav Li {
Color: #000000;
Text-Decoration: none;
Padding-top: 4px;
Display: block;
Width: 97px;
Height: 22px;
Text-align: center;
Background-color: # ececec;
Margin-left: 2px;
}
</Style>

</Head>

<Body>
<Ul id = "nav">
<Li> <a href = "#"> first page </a> </LI>
<Li> <a href = "#"> chapter </a> </LI>
<Li> <a href = "#"> Participation </a> </LI>
<Li> <a href = "#"> blog </a> </LI>
<Li> <a href = "#"> discussion </a> </LI>
<Li> <a href = "#"> contact </a> </LI>
</Ul>

</Body>
</Html>

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.