An html div is a block-level element that defines a horizontal section of a webpage. A block level element has an embedded carriage return before and after the element. Using styles, a div can be the best element to use for complex webpage layouts.
Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022

HTML DIV Basics

An html div is a block-level element that defines a horizontal section of a webpage. A block level element has an embedded carriage return before and after the element. A <div> is similar to a paragraph <p> element, except that paragraph elements have a semantic meaning that they should be used to create blocks of text, while a div is a generic box that is commonly used for layout purposes.

In the code shown below, I've defined two paragraphs above two divs. Note that the default margin for paragraphs is the height of the font, while the default margin for the divs is zero.

<p style="border-style:solid;">Being able to factor numbers is an important skill,
one that will be necessary later on to work with fractions and polynomials.</p>

<p style="border-style:solid;">Being able to factor numbers is an important skill,
one that will be necessary later on to work with fractions and polynomials.</p>

<div style="border-style:solid;">Being able to factor numbers is an important skill,
one that will be necessary later on to work with fractions and polynomials.</div>

<div style="border-style:solid;">Being able to factor numbers is an important skill,
one that will be necessary later on to work with fractions and polynomials.</div>

Being able to factor numbers is an important skill, one that will be necessary later on to work with fractions and polynomials.

Being able to factor numbers is an important skill, one that will be necessary later on to work with fractions and polynomials.

Being able to factor numbers is an important skill, one that will be necessary later on to work with fractions and polynomials.
Being able to factor numbers is an important skill, one that will be necessary later on to work with fractions and polynomials.

The div element has few html attributes. The align attribute specifies the alignment of the content inside a div element. Possible values are; left, right, center, or justify. However, this attribute is deprecated and styles should be used instead.

Divs make heavy use of styles, so Without knowledge of CSS, you'll have have a difficult time with all but the most basic use of divs. Even with good knowledge of CSS, because box model styles are inconsistent between browsers and browser versions, you'll have a difficult time using divs for page layout. It requires many work-arounds to get them to display constantly.

However, using styles, a div can be given a specific width and height and changed to an inline box which makes it the best element to use for complex webpage layouts. Especially useful for webpage layout is the ability to nest divs as in the code shown below.

<div style="border-style:solid; border-color:red; width:450px; padding:4px;">
<div style="border-style:solid; border-color:blue; width:200px; display:inline;">
Nested block</div>
<div style="border-style:solid; border-color:green; width:200px; display:inline;">
Nested block</div>
</div>
Nested block
Nested block

Another important styles concept to understand is that vertical margins collapse between adjacent elements. In other words, for adjacent vertical block-level elements, only the margin of the element with the largest margin value will be displayed. The margin of the element with the smaller margin value will be collapsed to zero. In order to become more skilled in the use of divs you should study the CSS box model.

RSS Feed RSS Feed


Follow Stephen Bucaro Follow @Stephen Bucaro


Web Design Sections

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2016 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268