search
HomeWeb Front-endHTML TutorialPlay with CSS3 (1) CSS3 realizes page layout_html/css_WEB-ITnose

Summary:

CSS3 adds some new layout methods compared to CSS2: multi-column layout and box layout. In this article, we will briefly recall the layout of CSS2 and summarize the layout methods of CSS3.


DIV CSS is actually a wrong name

Regarding the current page layout, many people are used to calling it DIV CSS. In fact, this is A wrong name, the standard name should be called XHTML CSS.
Why is this? The traditional page layout uses Table layout, that is, Table CSS. Later, the layout method using DIV appeared, so people called it DIV CSS, and some people think that pages made with DIV CSS are standard pages. In fact, this sentence The words are relatively narrow.
So what is a standard page? WEB standards consist of three parts: structure, performance and behavior. Among them, the standard languages ​​for structure are XHTML and XML, and the standard language for expression is CSS. Because XML is relatively complex and most browsers do not fully support it, XML is not used to implement page layout. Therefore, the standard page layout should be a page layout that conforms to WEB standards, that is, XHTML CSS.
XHTML not only has DIV tags, but also tags such as a, p, ul, li, dl, dt, etc., so even if DIV tags are not used, the page produced is a standard page. Each tag of XHTML has its own function does not mean that only DIVs can be used to implement page layout (there is a saying in a book: If the whole screen is filled with DIVs, it cannot be considered a standard page)
So, in the future, we must try our best to It is possible to say XHTML CSS, not DIV CSS.


Layout method in the CSS2 era

To put it simply, in the CSS2 era, the floating attribute of float is used. Implement layout.

layout.css


/* CSS Document *//*基本信息*/body{margin:0px;  /*外边距*/text-align:center; /*文字居中对齐*/background:#E1D0BB;  /*背景色*/}/*页面层容器*/#container{     width:80%;height:100%;margin-left:10%;margin-right:10%;background:#ABE0F1;}/*头部*/#header{width:100%;height:15%;margin:0px;background:#FF0000;}#logo{float:left;    /*浮动属性,居左对齐,使其可以在同一行显示*/width:60%;height:80%;margin:0px;background:#E18CDD;clear:left;     /*取消左侧浮动*/}#banner{float:right;   /*浮动属性,居右对齐,使其可以在同一行显示*/width:38%;height:80%;margin:0px;background:#8376D8;clear:right;    /*取消右侧浮动*/}#menu{width:100%;height:5%;margin:0px;background:#00FF00;}#pageBody{width:100%;height:70%;margin:0px;background:#00FFFF;}#footer{width:100%;height:10%;margin:0px;background:#FFFF00;}


layout.html


<meta charset="utf-8"><title>布局</title><link href="style/layout.css" rel="stylesheet" type="text/css"><div id="container">   <div id="header">       <div id="logo">	     logo	   </div>	   <div id="banner">	   banner	   </div>	   container   </div>   <div id="menu">   menu   </div>   <div id="pageBody">   </div>   <div id="footer">   footer   </div>
</div>



However, using float to implement layout will have some disadvantages, because each div is mutually exclusive Independent, so adding some content to a div will make it impossible to align. CSS3 provides multi-column layout and box layout to make up for this shortcoming.


Multi-column layout

layout.css

/* CSS Document *//*基本信息*/body{margin:0px;  /*外边距*/text-align:center; /*文字居中对齐*/background:#E1D0BB;  /*背景色*/}/*页面层容器*/#container{     width:80%;height:100%;margin-left:10%;margin-right:10%;background:#ABE0F1;}/*头部*/#header{width:100%;height:15%;margin:0px;background:#FF0000;}#logo{float:left;    /*浮动属性,居左对齐,使其可以在同一行显示*/width:60%;height:80%;margin:0px;background:#E18CDD;clear:left;     /*取消左侧浮动*/}#banner{float:right;   /*浮动属性,居右对齐,使其可以在同一行显示*/width:38%;height:80%;margin:0px;background:#8376D8;clear:right;    /*取消右侧浮动*/}#menu{width:100%;height:5%;margin:0px;background:#00FF00;}#pageBody{width:100%;height:70%;margin:0px;background:#00FFFF;-moz-column-count:4;       /*多栏布局:火狐浏览器中需要的格式,表示列数*/-moz-column-gap:10px;      /*列之间的间隔*/-moz-column-rule:1px solid red;   /*在列之间加一条红色的线*/-webkit-column-count:4;    /*多栏布局:safari和chrome需要的格式*/-webkit-column-gap:10px;   /*列之间的间隔*/-webkit-column-rule:1px solid red;   /*在列之间加一条红色的线*/}#footer{width:100%;height:10%;margin:0px;background:#FFFF00;}

layout.html

<meta charset="utf-8"><title>布局</title><link href="style/layout.css" rel="stylesheet" type="text/css"><div id="container">   <div id="header">       <div id="logo">	     logo	   </div>	   <div id="banner">	   banner	   </div>	   container   </div>   <div id="menu">   menu   </div>   <div id="pageBody">    内容省略   </div>   <div id="footer">   footer   </div>
</div>

Rendering:



Box layout

hezi.css

/* CSS Document *//*基本信息*/body{margin:0px;  /*外边距*/text-align:center; /*文字居中对齐*/background:#E1D0BB;  /*背景色*/}/*页面层容器*/#container{     display:-moz-box;display:-webkit-box;}#left_side{width:200px;height:200px;margin:20px;padding:50px;background-color:#FF0000}#center_side{width:200px;height:200px;margin:20px;padding:50px;background-color:#00FF00}#right_side{width:200px;height:200px;margin:20px;padding:50px;background-color:#FFFF00;}#left_side,#center_side,#right_side{      /*实现盒子布局*/-moz-box-sizing:border-box;-webkit-box-sizing:border-box;}#down_left{-moz-box-flex:1;        /*可根据内容自动调整大小,实现弹性盒子,此为火狐下的格式*/-webkit-box-flex:1;padding:20px;margin:20px;background-color:blue;}#down_left{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;}
hexi.html

<meta charset="utf-8"><title>布局</title><link href="style/hezi.css" rel="stylesheet" type="text/css"><div id="container">  <div id="left_side">  百度  </div>  <div id="center_side">  谷歌  </div>  <div id="right_side">  淘宝  </div>    <div id="down_left">  亚马逊  </div>
</div>

Rendering:


If you want the box to be divided vertically, you can After changing the container to:

#container{     display:-moz-box;display:-webkit-box;-moz-box-orient:vertical;   /*垂直分布*/-webkit-box-orient:vertical;}


Only a rough layout is given here. For more attributes, you can read related books and information.




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
HTML vs. CSS vs. JavaScript: A Comparative OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS, and JavaScript: Essential Tools for Web DevelopersHTML, CSS, and JavaScript: Essential Tools for Web DevelopersApr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

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.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor