CSS example: define the list of DL page elements and build a good structure with emphasis on semantics (reprinted 52css)

Source: Internet
Author: User

Everyone is learning CSS web page layout, studying CSS positioning, float, and the application and setting skills of various CSS attributes. This is not a problem. It is also worth studying. But it often ignores an important field, namely HTML. In my article on 52css.com, I emphasized more than once the semantics and structure. You may also get bored. I think this is nothing, and I think it is not important.

Without a good HTML document as the basis, it is often difficult for us to deploy CSS webpages. For example, quality problems exist in a one-stop building. There will be problems with how you do the decoration. In addition to consuming more materials and energy, the final decoration effect will be greatly reduced. The same is true for CSS webpage layout. If HTML documents have unreasonable structure and do not pay attention to semantics, We need to write more CSS styles to define them, which also makes HTML code cumbersome. This is contrary to the concept of web standards.

We will continue to discuss this with you on 52css.com today. Maybe you have read the following cases and you will have a new understanding of HTML. At the same time, we also hope to arouse your desire to learn and realize that CSS web page layout is more than just learning CSS.

  I. Introduction

On the 52css.com Forum, some netizens raised this question, saying that the page elements were misplaced in ff.

Original post:

Open his page and we can see the following results:

  

 

View the HTML source file and get the following code:

 
 

  1. <div id=product> 

  2.  

  3. <span><a href="/product/Stainless_Steel_runching_hole_mesh/">Stainless Steel runching hole mesh</a></span><br /> 

  4. <div id=list align="left"> 

  5. <a href="/product/Stainless_Steel_runching_hole_mesh/"></a> <em>We can provide perforated metals for decoration, screening, separation, sifting,..</em> 

  6. </div> 

  7.  

  8. <span><a href="/product/aluminim_plate_runching_hole_mesh/">aluminim plate runching hole mesh</a></span><br /> 

  9. <div id=list align="left"> 

  10. <a href="/product/aluminim_plate_runching_hole_mesh/"></a> <em>Weaving and Characteridtic :it is punched to mesh ,including:aluminim plate mesh..</em> 

  11. </div> 

  12.  

  13. <span><a href="/product/Expanded_Metal_Mesh/">Expanded Metal Mesh</a></span><br /> 

  14. <div id=list align="left"> 

  15. <a href="/product/Expanded_Metal_Mesh/"></a> <em>Material: Superior steel material Processing: Expanded with steel or other meta..</em> 

  16. </div> 

  17.  

  18. <span><a href="/product/crimped_wire_mesh/">crimped wire mesh</a></span><br /> 

  19. <div id=list align="left"> 

  20. <a href="/product/crimped_wire_mesh/"></a> <em>Material: Stainless steel wire 301 ,302 ,304, 304L ,316 ,316L, 321 Iron Wire Red..</em> 

  21. </div> 

  22.  

  23. <span><a href="/product/Punching_Hole_Mesh/">Punching Hole Mesh</a></span><br /> 

  24. <div id=list align="left"> 

  25. <a href="/product/Punching_Hole_Mesh/"></a> <em>Also named mine screen mesh, mechanic screen mesh. It can be supplied in folded ..</em> 

  26. </div> 

  27.  

  28. </div> 

Related CSS code:

 
 

  1. #product{  

  2. margin: 2px;  

  3. }  

  4. #product a{  

  5. color: #1A9CCE;  

  6. }  

  7. #product a:hover{  

  8. color: #EF8D3D;  

  9. }  

  10. #product span{  

  11. font-family: Arial, Helvetica, sans-serif;  

  12. font-size: 13px;  

  13. line-height: 25px;  

  14. font-weight: bold;  

  15. color: #5199DB;  

  16. float: left;  

  17. margin-left: 2px;  

  18. width: 250px;  

  19. text-align: left;  

  20. display: block;  

  21. }  

  22. .list{}  

  23. .list img{  

  24. float: left;  

  25. height: 50px;  

  26. width: 50px;  

  27. border: 1px solid #CCCCCC;  

  28. padding: 2px;  

  29. margin: 2px;  

  30. }  

  31. .list em{  

  32. clear: none;  

  33. float: left;  

  34. height: 50px;  

  35. font-family: Arial, Helvetica, sans-serif;  

  36. font-size: 12px;  

  37. line-height: normal;  

  38. color: #3587B3;  

  39. padding: 2px;  

  40. margin: 2px;  

  41. font-style: normal;  

The above Code may not be comprehensive.

1. The ID must be enclosed in quotation marks. For example, div id = product, should be, div id = "product"

2. The ID in the same page is unique. The landlord sets the ID of multiple Div to list

3. Completely separate styles into CSS, rather than in HTML files. Code like align = "Left" must be removed.

4. Do not pay attention to HTML structure semantics. The HTML Tag application is not standard. For example, the title is span, and the descriptive image and text are Div.

5. Let's talk about semantics. The structure of the page element is the list. You can use an unordered list or a defined list. Rather than the label organization method that the landlord understands.

6. The page may have the CSS definition with ID as list. The selector is. List, and the style does not work. It may also be caused by differences in width understanding.

  Ii. Thinking

The above code writing ideas are often considered correct and understandable when you are a beginner. As long as the content is organized with tags, and then the CSS style is applied for definition, so that the HTML document shows the desired effect in the browser, that is, the CSS webpage layout is carried out, the table layout is no longer in line with web standards.

Author: 52css.com If You Need To reprint please establish site Link (http://www.52css.com/), and do not arbitrarily modify the content of the article, retain the copyright statement text!

Otherwise, HTML tags and page elements must be set for CSS webpage layout. If these are not organized, powerful CSS knowledge may be powerless. The preceding Code makes CSS settings cumbersome and error-prone. Style itself is not easy to manage, and so on.

How can we define such page elements?

You may think of an unordered list ul. Each group of units is considered as a list item Li, which contains the title, thumbnail, and description text ..

  

 

Our HTML code can be like this:

 
 

  1. <Ul>

  2. <Li>

  3. <Strong> <a href = ""> CSS instance: a simple form search form </a> </strong>

  4. <P> <a href = ""> </a> </P>

  5. Forms are inevitable in CSS webpage layout. Some netizens raised this question. Form...

  6. </LI>

  7. </Ul>

However, this application is not appropriate. In XHTML, there is another form of list, defining the list DL.

You can refer to here:

DT -- indicates the title of the HTML custom list

The title can be considered as the title DT of the List Group in the definition list.

Dd -- indicates the description of the HTML custom list

Thumbnails and description text can be considered as the Title Description and meaning DD in the List Group.

.

  

 

Our encoding can be like this:

 
 

  1. <DL>

  2. <DT> <a href = ""> CSS instance: a simple form search form </a> </DT>

  3. <DD> <a href = ""> </a> forms are inevitable in CSS webpage layout. Some netizens raised this question. Form... </DD>

  4. </Dl>

  Iii. Solution

Based on the above thinking, we started to rewrite the page element. HTML encoding.

 
 

  1. <DL id = "product">

  2. <DT> <a href = ""> CSS instance: a simple form search form </a> </DT>

  3. <DD> <a href = ""> </a> forms are inevitable in CSS webpage layout. Some netizens raised this question. Form... </DD>

  4. <DT> <a href = ""> Use ul + Li to create a book catalog </a> </DT>

  5. <DD> <a href = ""> </a> the UL unordered list is an important HTML Tag, many elements in the page use it for organization. Library directory... </DD>

  6. <DT> <a href = ""> classic CSS skills: Text-indent hide text </a> </DT>

  7. <DD> <a href = ""> </a> image conversion is a very common method in CSS layout., because the image text is sometimes better than the optional text... </DD>

  8. <DT> <a href = ""> Create a floating layer with CSS translucent effect </a> </DT>

  9. <DD> <a href = ""> </a> CSS web page layout often encounters various problems, because of the needs of products and projects... </DD>

  10. <DT> <a href = ""> Chinese and English navigation menus with pure CSS </a> </DT>

  11. <DD> <a href = ""> </a> CSS navigation menus have always been a matter of interest to everyone. 52css has launched many instances. We will introduce them to you today... </DD>

  12. </Dl>

The preceding code is used to define CSS styles.

  

Reset the CSS style.

 
 

  1. * {  

  2.     margin:0;  

  3.     padding:0;  

Defines the width of the entire DL and sets the outer margin, inner margin, and border.

 
 

  1. #product {  

  2.     width:240px;  

  3.     margin:30px auto;  

  4.     padding:0 4px 8px 4px;  

  5.     border:1px solid #ccc;  

Define the style of the DT title, set the width and height, and define the top margin and line spacing. It is forcibly displayed on one row, and overflow is hidden. It can avoid the phenomenon that too many texts support DT.

 
 

  1. #product dt {  

  2.     width:240px;  

  3.     height:26px;  

  4.     margin-top:8px;  

  5.     line-height:26px;  

  6.     white-space:nowrap;  

  7.     overflow:hidden;  

Define the link style of the DT title.

 
 

  1. #product dt a {  

  2.     font-size:14px;  

  3.     color:#06f;  

  4.     text-decoration:none;  

  5. }  

  6. #product dt a:hover {  

  7.     color:#00f;  

  8.     text-decoration:underline;  

Define the CSS style described by DD, set the width and height, and define the text size and line spacing. Set overflow hiding. In this way, the CSS style of the text section in the description is compiled.

 
 

  1. #product dd {  

  2.     width:240px;  

  3.     height:64px;  

  4.     font-size:13px;  

  5.     line-height:21px;  

  6.     color:#333;  

  7.     overflow:hidden;  

Define the CSS style of link Element A in the DD description, float to the left, define the border, and define the right margin. Make the image and text at a certain distance.

Define the size of the thumbnail. The border connecting element a is 1 px away from the image, and the margin is set to 1 px. Set the border to 0.

Author: 52css.com If You Need To reprint please establish site Link (http://www.52css.com/), and do not arbitrarily modify the content of the article, retain the copyright statement text!

When hovering, the border color of link element a is blue.

The encoding is complete.

Final effect:

  

Related Article

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.