CSS horizontal, vertical, center alignment
Use CSS properties to achieve various alignments, such as left alignment, center alignment, right alignment, vertical center alignment, etc.
##Method 1: Use float attributes to set left and right alignment
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>实例</title>
<title>php.cn</title>
<style type="text/css">
.divcss5-left{float:left;width:250px;height:50px;border:1px solid #F00}
</style>
</head>
<body>
<div class="divcss5-left">此DIV靠左对齐显示</div>
</body>
</html>Method 2: Use margin attribute for center alignment
Only required Addmargin:0 auto to the style to be centered.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>实例</title>
<title>php.cn</title>
<style type="text/css">
.divcss5-cent{margin:0 auto;width:250px;height:50px;border:1px solid #F00}
</style>
</head>
<body>
<div class="divcss5-cent">此DIV居中对齐显示</div>
</body>
</html>Method 3: Use the position attribute to set left and right alignment
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>实例</title>
<title>php.cn</title>
<style type="text/css">
.divcss5-cent
{
position:absolute;
right:0px;
width:250px;
height:50px;
border:1px solid #F00
}
</style>
</head>
<body>
<div class="divcss5-cent">此DIV右对齐显示</div>
</body>
</html>Use Multi-attribute vertical center alignment:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>实例</title>
<title>php.cn</title>
<style type="text/css">
.wrp {
background-color: #b9b9b9;
width: 340px;
height: 260px;
}
.box {
color: white;
background-color: #3e8e41;
width: 200px;
height: 120px;
overflow: auto;
}
.wrp1 { position: relative; }
.box1 {
margin: auto;
position: absolute;
left: 0; right: 0; top: 0; bottom: 0;
}
</style>
<body>
<div class="wrp wrp1">
<div class="box box1">
<h3>完全居中:</h3>
<h3>利用css定位规则,设置左右、上下方向定位为0,margin为auto</h3>
</div>
</div>
</body>
</html>
new file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>实例</title>
<title>php.cn</title>
<style type="text/css">
.wrp {
background-color: #b9b9b9;
width: 340px;
height: 260px;
}
.box {
color: white;
background-color: #3e8e41;
width: 200px;
height: 120px;
overflow: auto;
}
.wrp1 { position: relative; }
.box1 {
margin: auto;
position: absolute;
left: 0; right: 0; top: 0; bottom: 0;
}
</style>
<body>
<div class="wrp wrp1">
<div class="box box1">
<h3>完全居中:</h3>
<h3>利用css定位规则,设置左右、上下方向定位为0,margin为auto</h3>
</div>
</div>
</body>
</html>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















