1
2
3
如何使整个页面内容居中,如何使高度自适应内容自动伸缩,这是学习CSS布局最常见的问题。
下面给出一个实际的列子,附详细说明。
首先可以将下列代码复制到html文件中运行一下,在mozilla、opera和ie浏览其中,均可达到居中且自适应高度的要求。
body
{
background:#999;
text-align:center;
color:#333;
font-family:Arial, Verdana, Sans-serif;
}
#header
{
width:776px;
margin-left:auto;
margin-right:auto;
padding:0px;
background:#eee;
height:60px;
text-align:center;
}
#container
{
margin-left:auto;
margin-right:auto;
width:776px;
}
#mainbg
{
width:776px;
padding: 0px;
background:#60A179;
float:left;
}
#right
{
float:right;
margin:2px 0px 2px 0px;
padding:0px;
width:574px;
background:#ccd2de;
text-align:left;
}
#left
{
float:left;
margin:2px 2px 0px 0px;
padding:0px;
background:#f2f3f7;
width:200px;
text-align:left;
}
#footer
{
clear:both;
width:776px;
margin-right:auto;
margin-left:auto;
padding:0px;
background:#eee;
height:60px;
}
.text
{
margin:0px;
padding:20px;
}
1
2
3
First we define the body and top area #header, the key here It is text-align: center in the body; and margin-left: auto and margin-right: auto in the header; the function is similar to centering the header area in the browser. Note: In IE, you only need to define text-align:center of the body to center it, but in mozilla (firefox), margin:auto is required.
Next are the left and right areas. In order to center these two columns, a container is now nested outside them, and margin: auto is set. The principle is the same as above. In this way, left and right are also centered as a whole.
You may be wondering why there is a layer of mainbg between the container and left and right. What is the role of this layer? This layer is used to define the background, so why not define the background directly in the container, but in multiple layers? The reason is that mozilla (firefox) is causing trouble (you don’t want the webpage you made to be displayed differently in firefox and ie). There is no need to nest one more layer in ie. In mozilla, the height value must be defined. The background can be displayed, but if the height is specified, the adaptive height requirement cannot be achieved, so an extra layer of mainbg is added. The trick lies in the float: left of the mainbg layer; defined in this way, the background can be displayed without specifying the height.
The last thing defined is the footer layer at the bottom. The key point of this layer is clear: both; the function of this sentence is to cancel the floating inheritance of the footer layer. Otherwise, you will see that the footer is displayed close to the header, or Mozilla is doing something weird :)
It is said that it is over here, but careful friends will see the difference between left and right. One layer is nested, and both layers use .text{margin:0px;padding:20px}. Why is this? The reason is that Mozilla and IE have different interpretations of the box model. Directly defining margin and padding will cause inconsistencies in the displays in Mozilla and IE. Therefore, when encountering inconsistencies between IE and Mozilla, adding an extra layer will often solve the problem.
The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.
Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.
HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform
TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.
HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.
ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc
The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.
HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.
AI-powered app for creating realistic nude photos
Online AI tool for removing clothes from photos.
Undress images for free
AI clothes remover
Swap faces in any video effortlessly with our completely free AI face swap tool!
Recommended: Win version, supports code prompts!
SublimeText3 Linux latest version
Integrate Eclipse with SAP NetWeaver application server.
God-level code editing software (SublimeText3)
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.