如何使用CSS将 标记居中?
示例
<html>
<head>
<title>div in center without css</title>
</head>
<body>
<div>
THIS IS ONE PARAGRAPH. HERE WE ARE NOT USE ANY ALIGNMENT.
</div>
<div align="center" style="border: 2px solid blue">
THIS PARAGRAPH IS IN CENTER
</div>
</body>
</html>
示例
<html>
<head>
<title>div in center with css</title>
<link href="../../Content/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div>
THIS IS ONE PARAGRAPH. HERE WE ARE NOT USE ANY ALIGNMENT.
</div>
<div class="mydiv">
THIS PARAGRAPH IS IN CENTER
</div>
</body>
</html>
Style.css
body {
background-color:Gray;
}
.mydiv {
padding:10px;
margin:auto;
width:30%;
border:4px solid black;
}
如果您想在框内输入文字,请在CSS文件的.mydiv类中编写text-align:center。
热门推荐
示例
<html> <head> <title>div in center without css</title> </head> <body> <div> THIS IS ONE PARAGRAPH. HERE WE ARE NOT USE ANY ALIGNMENT. </div> <div align="center" style="border: 2px solid blue"> THIS PARAGRAPH IS IN CENTER </div> </body> </html>
示例
<html> <head> <title>div in center with css</title> <link href="../../Content/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div> THIS IS ONE PARAGRAPH. HERE WE ARE NOT USE ANY ALIGNMENT. </div> <div class="mydiv"> THIS PARAGRAPH IS IN CENTER </div> </body> </html>
Style.css
body { background-color:Gray; } .mydiv { padding:10px; margin:auto; width:30%; border:4px solid black; }
如果您想在框内输入文字,请在CSS文件的.mydiv类中编写text-align:center。