search
HomeWeb Front-endHTML TutorialHTML Structured: Getting Started Guide to Practicing DIV+CSS Web Page Layout_html/css_WEB-ITnose

Webpage production skills------Applying CSS style design in DIV tags

You are learning CSS layout? Are you still unable to fully master pure CSS layout? There are usually two situations that hinder your learning:

The first possibility is that you have not yet understood the principles of CSS processing pages. Before you consider the overall performance of your page, you should first consider the semantics and structure of the content, and then add CSS for the semantics and structure. This article will tell you how to structure HTML.

Another reason is that you are at a loss for those very familiar presentation layer attributes (such as cellpadding, hspace, align="left", etc.) and don't know what CSS statements to convert them into. Once you have solved the first problem and know how to structure your HTML, I will give you a list detailing what CSS to use to replace the original presentation attributes.

Structured HTML

When we first learn to make web pages, we always consider how to design them first, considering the pictures, fonts, colors, and layout plans. Then we use Photoshop or Fireworks to draw it and cut it into small pictures. Finally, edit the HTML to restore all the designs to the page.

If you want your HTML page to be laid out with CSS (it is CSS-friendly), you need to go back and start over. Don't think about "appearance" first, but first think about the semantics and structure of your page content.

Appearance is not the most important thing. A well-structured HTML page can be presented in any appearance, and CSS Zen Garden is a classic example. CSS Zen Garden helps us finally realize the power of CSS.

HTML is not just for reading on a computer screen. Your carefully designed images in Photoshop may not be displayed on PDAs, mobile phones, and screen readers. But a well-structured HTML page can be displayed anywhere and on any network device through different definitions of CSS.

Start thinking

First learn what "structure" is, which some writers also call "semantics". What this term means is that you need to analyze your content blocks and the purpose each piece of content serves, and then build the corresponding HTML structure based on these content purposes.

If you sit down and carefully analyze and plan your page structure, you might end up with a few pieces like this:

Logo and site name

Main page content

Site navigation (main menu)

Submenu

Search box

Ritual area (e.g. shopping cart, checkout)

Footer ( Copyright and related legal statements)

We usually use DIV elements to define these structures, similar to this:

<div id="header"></div>

<div id="content"></div>

<div id="globalnav"></div>

<div id="subnav"></div>

<div id="search"></div>

<div id="shop"></div>

<div id="footer">< /div>

This is not a layout, but a structure. This is a semantic description of content blocks. When you understand your structure, you can add the corresponding ID to the DIV. Any content block can be contained within a DIV container, and another DIV can be nested within it. Content blocks can contain any HTML element---titles, paragraphs, images, tables, lists, etc.

According to the above, you already know how to structure HTML, and now you can define layout and style. Each content block can be placed anywhere on the page, and the color, font, border, background, alignment properties, etc. of the block can be specified.

Using selectors is a wonderful thing

The name of the id is a means of controlling a certain content block. By wrapping this content block with a DIV and adding a unique id, you can Use CSS selectors to precisely define the appearance of each page element, including titles, lists, images, links, paragraphs, etc. For example, if you write a CSS rule for #header, it can be completely different from the image rule in #content.

Another example is: you can define link styles in different content blocks through different rules. Something like this: #globalnav a:link or #subnav a:link or #content a:link. You can also define different styles for the same element in different content blocks. For example, define the style of p in #content and #footer through #content p and #footer p respectively. Structurally speaking, your page is composed of pictures, links, lists, paragraphs, etc. These elements themselves do not affect which network device they are displayed on (PDA, mobile phone or Internet TV). They can be defined as Any performance appearance.

A carefully structured HTML page is very simple, and every element is used for structural purposes. When you want to indent a paragraph, you don't need to use the blockquote tag. Just use the p tag and add a CSS margin rule to p to achieve the indentation purpose. p is a structured tag and margin is a presentation attribute. The former belongs to HTML and the latter belongs to CSS. (This is the separation of structure and expression.)

There are almost no tags expressing attributes in a well-structured HTML page. The code is very clean and concise. For example, the original code

can now only write
in HTML, and all things that control the performance are written in CSS In structured HTML, table is a table, not anything else (such as being used for layout and positioning).

Practice the structure yourself

The above is just the most basic structure. In actual application, you can adjust the content blocks as needed. DIV nesting often occurs, and you will see that there are other layers in the "container" layer, with a structure similar to this:

<div id="navcontainer">

<div id ="globalnav">

<ul>a list</ul>

</div>

<div id="subnav">

<ul>another list</ul>

</div>

</div>

Nested div elements allow you to define more CSS rules to control Performance, for example: you can give #navcontainer a rule to center the list to the right, give #globalnav a rule to center the list to the left, and give #subnav a completely different behavior for the list.

Replace traditional methods with CSS

The following list will help you replace traditional methods with CSS:

HTML attributes and corresponding CSS methods

HTML Property

CSS method description

align="left"

align="right" float: left;

float: right; You can float using CSS Any element: picture, paragraph, div, title, table, list, etc.

When you use the float attribute, you must define a width for the floating element.

marginwidth="0" leftmargin="0" marginheight="0" topmargin="0" margin: 0; Using CSS, margin can be set on any element, not just the body element. More importantly , you can specify the margin values ​​​​of the top, right, bottom and left elements respectively.

vlink="#333399" alink="#000000" link="#3333FF" a:link #3ff;

a:visited: #339;

a :hover: #999;

a:active: #00f;

In HTML, the color of the link is defined as an attribute value of the body. The link style is the same throughout the page. Using CSS selectors, link styles can be different in different parts of the page.

bgcolor="#FFFFFF" background-color: #fff; In CSS, the background color can be defined for any element, not just body and table elements.

bordercolor="#FFFFFF" border-color: #fff; Any element can set a border (boeder), you can define top, right, bottom and left respectively

border="3 "cellspacing="3" border-width: 3px; Using CSS, you can define the border of the table to have a unified style, or you can define the color, size and style of the top, right, bottom and left borders respectively.

You can use table, td or th selectors.

If you need to set a borderless effect, you can use CSS definition: border-collapse: collapse;

< br clear="left">

<br clear="right">

<br clear="all">

clear: left;

clear: right;

clear: both;

Many 2-column or 3-column layouts use the float attribute for positioning. If you define a background color or background image in the floating layer, you can use the clear attribute.

cellpadding="3"

vspace="3"

hspace= "3" padding: 3px; Using CSS, the padding attribute can be set on any element. Similarly, padding can be set on top, right, bottom and left respectively. padding is transparent.

align="center" text-align: center;

margin-right: auto; margin-left: auto;

Text-align only works for text.

Block levels like div, p can be horizontally centered through margin-right: auto; and margin-left: auto;

Some regrettable techniques and working environment

Due to the imperfect support of CSS by browsers, we sometimes have to adopt some techniques (hacks) or establish an environment (Workarounds) to allow CSS to achieve the same effect as traditional methods. For example, block-level elements sometimes need to use horizontal centering techniques, box model bug techniques, etc. All of these techniques are detailed in Molly Holzschlag’s article Integrated Web Design: Strategies for Long-Term CSS Hack Management.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between an HTML tag and an HTML attribute?What is the difference between an HTML tag and an HTML attribute?May 14, 2025 am 12:01 AM

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software