This is an article I saw on the web designer website. It is very suitable for people who are new to div+css layout. I copied it and saved it. Hoho~~ Are
you learning CSS layout? Are you still unable to fully master pure CSS layout? There are usually two situations that hinder your learning:
the first may be that you have not yet understood the principle 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 based on the semantics and structure. This article will tell you how to structure HTML.
Another reason is that you
are helpless , and don’t know what corresponding CSS statements to convert. When you solve the first problem and know how to structure your HTML, I
will give a list of what CSS to use to replace the original presentation attributes.
Structuring HTML When we first learn to make web pages, we always consider how to design first, consider those pictures, fonts, colors, and layout plans. Then
we use Photoshop or Fireworks to draw and cut into small pictures. Finally, we restore all the designs to the page by editing HTML
.
If you want your HTML page to be laid out with CSS (CSS-friendly), you need to go back and
think about the semantics and structure of your page content instead of "appearance".
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 only read on computer screens. The pictures you carefully designed with photoshop may not be displayed on PDAs, mobile phones and screen
readers. But a well-structured HTML page can be displayed anywhere, on any network device through different definitions of CSS
.
To start thinking, first learn what "structure" is, which some writers also call "semantics". This term means that you need to analyze your content blocks and
the purpose each block serves, and then build the corresponding HTML structure according to these content purposes.
If you sit down and carefully analyze and plan your page structure, you may end up with blocks like this:
Logo and site name Home page Content Site navigation (main menu) Submenus Search box Functional area (such as shopping cart, checkout) Footer (copyright and related legal notices) We usually use DIV elements to define these structures, like 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 layout, it is structure. This is a semantic description of the content block. When you understand your structure, you can add the corresponding ID to the DIV
. The DIV container can contain any content block, and can also nest another DIV. The content block can contain any HTML element---headings
, paragraphs, images, tables, lists, etc.
Based on the above, you already know how to structure HTML, and now you can define the layout and style. Each content block
can be placed anywhere on the page and have its own color, font, border, background, alignment, etc.
Selectors are a wonderful thing. ID names are a means of controlling a content block. By wrapping a DIV with a unique ID, you can use CSS selectors to
precisely define the appearance of each page element, including headers, lists, images, links, paragraphs, etc. For example
, you can write a CSS rule for #header that is completely different from the rules for images in #content.
Another example is that you can define different rules for links in different content blocks. Something like #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 styles of the p in #content and #footer p respectively. Structurally, your page
is made up of images, links, lists, paragraphs, etc. These elements themselves have no effect on what network device they are displayed on (PDA, mobile phone
or network TV). They can be defined to look and feel in any way.
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 the p to achieve the indentation purpose. p is a structural
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 presentation.)
A well-structured HTML page has almost no tags with presentation attributes. The code is very clean and concise. For example, the original code <table width="80%" cellpadding="3" border="2" align="left">
can now be written only in HTML <table>
, and all things that control presentation are written in CSS. In structured HTML, a table is a table, not anything else (such as being used
for layout and positioning).
Practice structuring yourself. The above is only the most basic structure. In actual applications, you can adjust the content blocks as needed. DIVs are often nested
, and you will see other layers in the "container" layer. The structure is 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 the behavior. For example, you can give #navcontainer a rule to align the list
to the right, another rule to align the list to the left for #globalnav, and a completely different behavior for the list in #subnav.
Replace traditional methods with CSSThe following list will help you replace traditional methods with CSS:
HTML attributes and their corresponding CSS methodsHTML attributeCSS methodDescriptionalign
="left"
align="right"float: left;
float: right;Using CSS, you can float any element: images, paragraphs, divs, headings, tables, lists, etc.When
you use the float property, you must define a width for the floated 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 top, right, bottom and left margin values
of an element separately . vlink="#333399" alink="#000000" link="#3333FF" a:link #3ff; a:visited: #339; a:hover: #999; a:active: #00f; In HTML, the color of a link is defined as an attribute value of the body. The link style is the same for the entire page. Using CSS selectors, the link styles can be different for different parts of the page. bgcolor="#FFFFFF" background-color: #fff; In CSS, any element can have a background color defined, not just the body and table elements. bordercolor="#FFFFFF" border-color: #fff; Any element can have a border (boeder), you can define top, right, bottom and left border="3" cellspacing="3" border-width: 3px; Using CSS, you can define a table border with a uniform style, or you can define . You can use table, td or th selectors. If you need to set a borderless effect, you can use CSS to define it: 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 property to position them. If you define a background color or background image in the floating layer, you can use the clear property. cellpadding="3" vspace="3" hspace="3" padding: 3px; With CSS, any element can have a padding property set. Similarly, padding can be set top, right, bottom and left separately. Padding is transparent. align="center" text-align: center; margin-right: auto; margin-left: auto; Text-align only applies to text. Block-level elements like div and p can be horizontally centered using margin-right: auto; and margin-left: auto; Some unfortunate techniques and workarounds Due to the incomplete browser support for CSS, we sometimes have to resort to some hacks or build an environment (workarounds) to make CSS 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 these techniques are detailed in Molly Holzschlag's article "Integrated Web Design: Strategies for Long-Term CSS Hack Management". Another resource site for CSS techniques is "Position is Everything" by Big John and Holly Bergevin. Understanding floating behavior Eric Meyer's "Containing Floats" will help you master how to use float attributes for layout. Float elements sometimes need to be cleared , and reading "How To Clear Floats Without Structural Markup" will be very helpful. More Help The existing CSS Discussion list is a great resource that collects information from a WikiA discussion group, including CSS Layout Summary (css-discuss.incutio.com/?page=CssLayouts), CSS Tips Summary (css-discuss.incutio.com/?page=CssLayouts), and more.com/? page=CssHack) and more
Well, yes, I was going to simulate this in FreeUI's UI configuration. Of course, I changed my mind later (why? 0011) What else was I going to use? I should have mentioned that (0083)
Details
Published on 2017-11-12 00:31
Well, yes, I was going to simulate this in FreeUI's UI configuration. Of course, I changed my mind later (why? 0011) What else was I going to use? I should have mentioned that (0083)