Table of Contents
Div Soup Demonstration
Tangential Information
Home Web Front-end H5 Tutorial HTML5、CSS3应用教程之 跟DIV说Bey!Bey!

HTML5、CSS3应用教程之 跟DIV说Bey!Bey!

May 17, 2016 am 09:09 AM
admin

Web设计师可以使用HTML4和CSS2.1完成一些很酷的东西。我们可以在不使用陈旧的基于table布局的基础上完成文档逻辑结构并创建内容丰富的网站。我们可以在不使用内联
标签的基础上对网站添加漂亮而细腻的风格样式。事实上,我们目前的设计能力已经让我们远离了那个可怕的浏览器战争时代、专有协议和那些充满闪动、滚动和闪烁的丑陋网页。

  虽然我们现在已经普遍使用了HTML4和CSS2.1,但是我们还可以做得更好!我们可以重组我们代码的结构并能让我们的页面代码更富有语义化特性。我们可以缩减带给页面美丽外观样式代码量并让他们有更高的可扩展性。现在,HTML5和CSS3正跃跃欲试的等待大家,下面让我们来看看他们是否真的能让我们的设计提升到下一个高度吧…

曾经,设计师们经常会跟频繁使用基于table的没有任何语义的布局。不过最终还是要感谢像Jeffrey Zeldman和Eric Meyer这样的思想革新者,聪明的设计师们慢慢的接受了相对更语义化的

布局替代了table布局,并且开始调用外部样式表。但不幸的是,复杂的网页设计需要大量不同的标签结构代码,我们把它叫做“
-soup” 综合症。也许你很熟悉下面的代码:



  

     

        

           

Div Soup Demonstration


           

Posted on July 11th, 2009


        

        

           

Lorem ipsum text blah blah blah.


           

Lorem ipsum text blah blah blah.


           

Lorem ipsum text blah blah blah.


        

        
     

     

        

           

Tangential Information


        

        

           

Lorem ipsum text blah blah blah.


           

Lorem ipsum text blah blah blah.


           

Lorem ipsum text blah blah blah.


        

        
     

  




尽管这有些勉强,但上面这个实例还是可以说明使用HTML4对一个复杂的设计进行代码化后依然过于臃肿(其实xHTML1.1也不过如此)。不过值得激动的是,HTML5解决“
-soup” 综合症并带给我们一套新的结构化元素。这些新的HTML5元素富有更细致的语义从而代替了那些毫无语义的
标签,并同时为CSS的调用提供了”自然”的CSS钩子。

下面是HTML5的解决方案实例:



  

     

        

           

Div Soup Demonstration


           

Posted on July 11th, 2009


        

        

           

Lorem ipsum text blah blah blah.


           

Lorem ipsum text blah blah blah.


           

Lorem ipsum text blah blah blah.


        

        

           

Tags: HMTL, code, demo


        

     

     
  




        正如我们所见,HTML5可以让我们用很多更语义化的结构化代码标签代替那些大量的无意义的
标签。这种语义化的特性不仅提升了我们网页的质量和语义,并且大量减少了曾经代码中用于CSS必须调用的class和id属性。事实上,CSS3也是可以然通过我们忽略掉所有class和id的。

跟class属性说再见,欢迎整洁的标签  

       结合了富有新的语义化标记的HTML5,CSS3为web设计师们的网页提供了神一般的力量。有了HTML5的能量,我们将得到更多的对文档代码的控制权,有了CSS3的能量,我们的控制权将趋于无穷大!

  即使没有那些高级的CSS选择器,我们仍然可以通过强大的HTML5条调用不同的容器而不劳驾class和id这类属性。像以往的DIV布局,我们在css中可能要这样调用:


div#news    {}
div.section {}
div.article {}
div.header  {}
div.content {}
div.footer  {}
div.aside   {}

我们再来看看基于HTML5的实例:

section {}
article {}
header  {}
footer  {}
aside   {}

这是个进步,但仍有一些问题需要解决。在
实例中,我们需要通过class或id属性来调用页面中的元素。这种逻辑将允许我们将样式应用到文档中的任何一个元素上,无论是整体还是个体。例如在
实例中,.section 和 .content元素很容易定位。但是在HTML5实例中,实际文档中会有很多个section元素。其实我们可以添加一些特定的属性选择器来调用那些不同的section元素,不过谢天谢地,我没现在可以用少量的高级CSS选择器来定位不同的section元素。

不使用class和id定位HTML-5元素

  下面让我们来看看如何在不使用class和id的情况下定位HTML5页面元素的一个实例,我们可以使用三种CSS选择器来定位和辨别实例中的元素。如下:

后代选择器:[CSS 2.1]: EF
兄弟选择器:[CSS 2.1]: E + F
子元素选择器:[CSS 2.1]: E > F

      下面让我们来看看如何不使用class和id而完成对文档中的那些section元素的定位吧:

定位最外层的
元素

  考虑到我们的例子并不是一套完整的HTML5代码,所以我们假定在元素下有个

Statement of this Website
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

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

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
What Does H5 Refer To? Exploring the Context What Does H5 Refer To? Exploring the Context Apr 12, 2025 am 12:03 AM

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

H5: The Evolution of Web Standards and Technologies H5: The Evolution of Web Standards and Technologies Apr 15, 2025 am 12:12 AM

Web standards and technologies have evolved from HTML4, CSS2 and simple JavaScript to date and have undergone significant developments. 1) HTML5 introduces APIs such as Canvas and WebStorage, which enhances the complexity and interactivity of web applications. 2) CSS3 adds animation and transition functions to make the page more effective. 3) JavaScript improves development efficiency and code readability through modern syntax of Node.js and ES6, such as arrow functions and classes. These changes have promoted the development of performance optimization and best practices of web applications.

H5 Code: Best Practices for Web Developers H5 Code: Best Practices for Web Developers Apr 16, 2025 am 12:14 AM

Best practices for H5 code include: 1. Use correct DOCTYPE declarations and character encoding; 2. Use semantic tags; 3. Reduce HTTP requests; 4. Use asynchronous loading; 5. Optimize images. These practices can improve the efficiency, maintainability and user experience of web pages.

Is H5 a Shorthand for HTML5? Exploring the Details Is H5 a Shorthand for HTML5? Exploring the Details Apr 14, 2025 am 12:05 AM

H5 is not just the abbreviation of HTML5, it represents a wider modern web development technology ecosystem: 1. H5 includes HTML5, CSS3, JavaScript and related APIs and technologies; 2. It provides a richer, interactive and smooth user experience, and can run seamlessly on multiple devices; 3. Using the H5 technology stack, you can create responsive web pages and complex interactive functions.

H5 and HTML5: Commonly Used Terms in Web Development H5 and HTML5: Commonly Used Terms in Web Development Apr 13, 2025 am 12:01 AM

H5 and HTML5 refer to the same thing, namely HTML5. HTML5 is the fifth version of HTML, bringing new features such as semantic tags, multimedia support, canvas and graphics, offline storage and local storage, improving the expressiveness and interactivity of web pages.

Understanding H5 Code: The Fundamentals of HTML5 Understanding H5 Code: The Fundamentals of HTML5 Apr 17, 2025 am 12:08 AM

HTML5 is a key technology for building modern web pages, providing many new elements and features. 1. HTML5 introduces semantic elements such as, , etc., which enhances web page structure and SEO. 2. Support multimedia elements and embed media without plug-ins. 3. Forms enhance new input types and verification properties, simplifying the verification process. 4. Offer offline and local storage functions to improve web page performance and user experience.

Deconstructing H5 Code: Tags, Elements, and Attributes Deconstructing H5 Code: Tags, Elements, and Attributes Apr 18, 2025 am 12:06 AM

HTML5 code consists of tags, elements and attributes: 1. The tag defines the content type and is surrounded by angle brackets, such as. 2. Elements are composed of start tags, contents and end tags, such as contents. 3. Attributes define key-value pairs in the start tag, enhance functions, such as. These are the basic units for building web structure.

H5: How It Enhances User Experience on the Web H5: How It Enhances User Experience on the Web Apr 19, 2025 am 12:08 AM

H5 improves web user experience with multimedia support, offline storage and performance optimization. 1) Multimedia support: H5 and elements simplify development and improve user experience. 2) Offline storage: WebStorage and IndexedDB allow offline use to improve the experience. 3) Performance optimization: WebWorkers and elements optimize performance to reduce bandwidth consumption.

See all articles