HTML5 and css3 tutorials

Source: Internet
Author: User

Web designers can use html4 and css2.1 to do something cool. We can complete the logical structure of the document and create a website with rich content without using the old table-based layout. We can add beautiful and exquisite style styles to the website without using the inline <font> and <br> labels. In fact, our current design capabilities have moved us away from the terrible age of browser wars, proprietary protocols, and ugly web pages that are full of flashing, rolling, and flashing.
Although html4 and css2.1 are already widely used, we can do better! We can reorganize the structure of our code and make our page code more semantic. We can reduce the amount of code that brings beautiful page styles and make them more scalable. Now HTML5 and css3 are waiting for you. Let's see if they can really bring our design to the next height...

You can also refer to the following css3 tutorials and resources:
New css3 technology for improving your design level
Learn endless CSS (XHTML + CSS skills tutorial resource Daquan)

Summary of the most comprehensive Browser/CSS selector compatibility
Five new css3 technologies you should know
Say goodbye to <div>. Welcome to semantic tags.

Once, designers often used table-based la s without any semantics. However, in the end, I would like to thank the innovative idea like Jeffrey zeldman and Eric Meyer. The SMART designers gradually accepted the relatively more semantic <div> layout instead of the table layout, and start calling the external style sheet. Unfortunately, complex web design requires a large number of different tag structure code. We call it "<div>-Soup" syndrome. You may be familiar with the following code:
<Divid = "news">
<Divclass = "section">
<Divclass = "article">
<Divclass = "Header">
<H1> Div soup demonstration <P> posted on July 11th, 2009 </P>
</Div>
<Divclass = "content">
<P> lorem ipsum text blah. </P>
<P> lorem ipsum text blah. </P>
<P> lorem ipsum text blah. </P>
</Div>
<Divclass = "footer">

</Div>
</Div>
<Divclass = "aside">
<Divclass = "Header">
<H1> tangential Information </Div>
<Divclass = "content">
<P> lorem ipsum text blah. </P>
<P> lorem ipsum text blah. </P>
<P> lorem ipsum text blah. </P>
</Div>
<Divclass = "footer">
<P> tags: hmtl, code, demo </P>
</Div>
</Div>
</Div>
</Div>

Despite this reluctance, the above example still shows that HTML 4 is too bloated after coding a complex design (in fact, xhtml1.1 is also so ). But it is exciting that HTML5 solves the "<div>-Soup" syndrome and brings us a new set of structural elements. These new HTML5 elements have more detailed semantics to replace the <div> labels without semantics, and provide "natural" CSS hooks for CSS calls. The following is an example of the HTML5 solution:
<Section>
<Section>
<Article>
<Header>
<H1> Div soup demonstration <P> posted on July 11th, 2009 </P>
</Header>
<Section>
<P> lorem ipsum text blah. </P>
<P> lorem ipsum text blah. </P>
<P> lorem ipsum text blah. </P>
</Section>
<Footer>
<P> tags: hmtl, code, demo </P>
</Footer>
</Article>
<Aside>
<Header>
<H1> tangential Information </Header>
<Section>
<P> lorem ipsum text blah. </P>
<P> lorem ipsum text blah. </P>
<P> lorem ipsum text blah. </P>
</Section>
<Footer>
<P> tags: hmtl, code, demo </P>
</Footer>
</Aside>
</Section>
</Section>

As we have seen, HTML5 allows us to replace a large number of meaningless <div> labels with a lot of more semantic Structured code labels. This semantic feature not only improves the quality and semantics of our web pages, but also greatly reduces the class and ID attributes that must be called by CSS in code. In fact, css3 can ignore all classes and IDs.
Again with the class attribute

As we have seen, HTML5 allows us to replace a large number of meaningless code tags with a lot of more semantic Structured code labels.
Label. This semantic feature not only improves the quality and semantics of our web pages, but also greatly reduces the class and ID attributes that must be called by CSS in code. In fact, css3 can ignore all classes and IDs. Again with the class attribute
See. Welcome to the neat labels.

Combined with HTML5 with new semantic tags, css3 provides powerful power for web designers. With HTML5 energy, we will gain more control over the document code. With css3 energy, our control will become infinitely infinite!

Without those advanced CSS selectors, we can still use powerful HTML5 bars to call different containers without the class and ID attributes. Like the previous Div layout, we may need to call it in CSS as follows:
1
2
3
4
5
6
7

Div # news {}
Div. Section {}
Div. Article {}
Div. header {}
Div. Content {}
Div. footer {}
Div. aside {}

Let's take a look at HTML5-based instances:
1
2
3
4
5

Section {}
Article {}
Header {}
Footer {}
Aside {}

This is an improvement, but some problems still need to be solved. In the <div> instance, we need to call the elements on the page through the class or ID attribute. This logic will allow us to apply styles to any element in the document, whether overall or individual. For example, in the <div> instance, The. Section and. content elements are easy to locate. However, in HTML5 instances, there are many section elements in the actual document. In fact, we can add some specific attribute selectors to call those different section elements, but I am not able to use a small number of advanced CSS selectors to locate different section elements.
Positioning HTML-5 elements without class and ID

Next let's take a look at how to locate an HTML5 page element instance without using the class and ID. We can use three CSS selectors to locate and identify elements in the instance. As follows:

* Descendant selector: [CSS 2.1]: ef
* Sibling selector: [CSS 2.1]: E + F
* Sub-element selector: [CSS 2.1]: E> F

Let's take a look at how to locate the section elements in the document without using the class and ID:

Locate the <section> element of the outermost layer

Considering that our example is not a complete set of HTML5 code, we assume that the <nav> element and <section> element under the <body> element are sibling elements. In this way, we can locate the outermost <section> as the code below:
1

Body nav + section {}

Locate the next <section> element
It is the unique subset element under the <section> element of the outermost layer. This <section> element may be located like this:
1

Section> section {}

Locate the <Article> element
There are many methods to locate the <Article> element, but the simplest method is the descendant selector:
1

Section section Article {}

Locate the These three elements appear in both places. One is in the <Article> element, and the other is in the <aside> element. This difference allows us to easily locate each element.
1
2
3

Article header {}
Article section {}
Article footer {}

Or define them together:
1
2
3

Section section header {}
Section section Section {}
Section section footer {}

So far, we have used the css2.1 selector to exclude all classes and IDs. So why do we still need to use css3? I'm glad you asked this question...
Use css3 for advanced positioning of HTML5 Elements

Although we have used the css2.1 selector to exclude all classes and IDs, it is clear that there are still many more complex cases that need to be solved by the advanced selector of css3. Let's take a look at the example to learn how to use css3 to locate page elements without using useless class and ID attributes.

Use a unique log (post) ID to locate all logs

WordPress provides us with a source code output that contains the ID of each log. This information is usually used for navigation and/or understanding the intent of the data, but css3 can use these unique IDs to define the style of these logs. Of course, you can also add attributes such as class = "Post" for each log as usual, but this is in conflict with the intent of our practice (plus it does not have any fun ). With the "substring matching selector", we can locate all logs and their different elements as follows.
1
2
3

Article [ID * = post-] {}/* locate all logs */
Article [ID * = post-] header H1 {}/ * locate the H1 tag in all logs */
Article [ID * = post-] section P {}/* locate the P tag in all logs */

I can't still locate the comment elements and their child elements in the same way.
1
2
3

Article [ID * = comment-] {}/* locate all comments */
Article [ID * = comment-] header H1 {}/* locate the H1 tag in all comments */
Article [ID * = comment-] section P {}/* locate the P tag in all comments */

Locate specified sections or articles)
Many blogs have a large volume of logs and comments. html 5 may make up of <section> or <Article> elements. To locate the specified <section> or <Article> elements, we need to use the powerful ": Nth-Child" selector:
1
2
3
4
5

Section: Nth-Child (1) {}/ * select the first <section> */
Article: Nth-Child (1) {}/ * select the first <Article> */

Section: Nth-child (2) {}/ * select the second <section> */
Article: Nth-child (2) {}/ * select the second <Article> */

Similarly, we can use the ": Nth-last-Child" selector to locate some elements in reverse order.
1
2
3
4
5

Section: Nth-last-Child (1) {}/ * select the last <section> */
Article: Nth-last-Child (1) {}/ * select the last <Article> */

Section: Nth-last-child (2) {}/ * select the second to last <section> */
Article: Nth-last-child (2) {}/ * select the second to last <Article> */

Select a specified element in more ways
Another method for selecting specific elements (such as header, section, and footer) in HTML5 is to take advantage of the ": only-of-type" selector. Because these HTML5 elements usually appear more than once in many places, this method is very convenient when we want to locate the tag that appears only once under the parent element. For example, we want to select only one element in an element, as shown in the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14

<Section>
<Section> </section>
<Section>
<Section> locate the section element </section>
</Section>
<Section>
<Section> locate the section element </section>
</Section>
<Section>
<Section> but this section element is not located </section>
<Section> and this section element </section>
</Section>
<Section> </section>
</Section>

We can only use the following row selector:
1

Section> section: only-of-type {}

Once again, you can stubbornly add ID attributes for each element, but you will lose the scalability, maintainability, and absolute conciseness of the Code. Css3 allows us to quickly and conveniently locate almost all page elements without ID and class attributes.
If you want to know about the browser support of the css3 selector, refer to this article (instant update ):
Summary of the most comprehensive Browser/CSS selector compatibility
Summary

I believe that with time advances and more browser support, HTML5 and css3 will become more and more popular. They will bring more endless energy to web designers and bring our Web Front-end to a higher level.

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.