Home > Article > Web Front-end > Do you know the centering attribute of the html body tag? Definition and usage of html body tag
html Do you know the centering attribute of the body tag? The definition and usage of html body tag. The following article mainly explains to you the definition of the html body tag and the two methods of centering attributes, as well as the definition and use of the html body tag
The definition and use of the html body tag Usage:
The body element defines the body of the document.
The body element contains all the content of the document (such as text, hyperlinks, images, tables, lists, etc.)
HTML 6c04bd5ca3fcae76e30b72ad730ca86d tag example
A simple HTML document with the most basic required elements:
<html> <head> <title>文档的标题</title> </head> <body> 文档的内容... ... </body> </html>
html The centered attribute of the body tag
html body tag The centering attribute (1):
How to use basic centering:
<html> <head> <title>居中</title> </head> <body style="text-align:center;"> <h2>居中</h2> </body> </html>
html The centering attribute of the body tag (2):
## How to use the #div tag to center it horizontally and vertically in the body: Horizontal centering: The method of centering the div tag in the entire body can be controlled with CSS, body{text-align:center;}.box{margin: 0 auto;} The class box is centered horizontally in the entire body Vertical centering: The vertical centering of div in the body is not very effective with CSS control, so it is more effective to use js to control, the code is as follows (jQuery ):function SetPostion(){ var wheight = $(window).height(); //浏览器的高度 var boxheight = $(“.box”).height(); //box的高度 //浏览器的高度若大于box的高度,才设置box垂直居中 if(wheight > boxheight){ var h = (wheight -boxheight)/2; //计算box距顶端的距离 $(“.box”).css(“margin-top” ,h+”px”) //设置box的margin-top属性 } }The css class named box is vertically centered
Browser support
All major browsers support 6c04bd5ca3fcae76e30b72ad730ca86d Label. [Related recommendations]Is the HTML del tag a block-level element? Specific application method of html del tag
#What are the attributes of html hr tag? Detailed explanation of the style of HTML hr tag
The above is the detailed content of Do you know the centering attribute of the html body tag? Definition and usage of html body tag. For more information, please follow other related articles on the PHP Chinese website!