基本语法
border
- border-style(边框样式)常见样式有 : dashed(虚线)| dotted(点线)| solid(实线)| double(双线)。
- border-color(边框颜色)
- border-width(边框宽度)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
div {
width: 200px;
height: 200px;
border-width: 8px;
border-color: red;
border-style: double;
border: 10px solid pink;
}
</style>
</head>
<body>
<div>我是一个盒子</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
input {
border: 0;
}
.uname {
border-width: 1px;
border-style: solid;
border-color: green;
}
.nc {
border-top-width: 1px;
border-top-style: solid;
border-top-color: pink;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: brown;
}
.email {
border-left: 1px solid red;
border-right: 1px solid #ccc;
}
.tel {
border-left: 2px solid skyblue;
border-top: 2px solid skyblue;
border-right: 2px solid skyblue;
border-bottom: 2px solid skyblue;
}
</style>
</head>
<body>
<label for="">用户名:<input type="text" class="uname"></label><br /><br />
<label for="">昵称:<input type="text" class="nc"></label><br /><br />
<label for="">邮箱:<input type="email" class="email"></label><br /><br />
<label for="">手机:<input type="tel" class="tel"></label>
</body>
</html>
padding(填充)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
div {
width: 200px;
height: 200px;
border: 1px solid #0f0;
padding: 20px 10px 30px 10px;
}
</style>
</head>
<body>
<div>内边距代表内容到边框的距离</div>
</body>
</html>
margin(边界)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
div {
width: 200px;
height: 200px;
background-color: pink;
padding: 4px;
margin: 20px auto;
}
span {
margin: 0 auto;
}
header {
margin: 0 auto;
width: 400px;
}
</style>
</head>
<body>
<div></div>
<header>头部</header>
<span>span</span>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
}
.box {
width: 160px;
height: 160px;
background-color: red;
overflow: hidden;
}
.inner {
margin-top: 60px;
width: 80px;
height: 80px;
background-color: rgb(90, 90, 40);
}
.box1,
.box2 {
width: 100px;
height: 100px;
background-color: red;
}
.box1 {
margin-bottom: 60px;
}
</style>
</head>
<body>
<div class="box">
<div class="inner"></div>
</div>
<div class="box1"></div>
<div class="box2"></div>
</body>
</html>
其它
细线表格(合并相邻边框 border-collapse)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
table {
width: 700px;
height: 300px;
border: 1px solid #ccc;
border-collapse: collapse;
}
td {
border: 1px solid #ccc;
}
</style>
</head>
<body>
<table cellspacing="0">
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
</tr>
<tr>
<td>1111</td>
<td>2222</td>
<td>3333</td>
</tr>
</table>
</body>
</html>
圆角边框(border-radius)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
div {
width: 180px;
height: 180px;
border: 1px solid red;
}
div:first-child {
border-radius: 10px;
}
div:nth-child(2) {
border-radius: 50%;
}
div:nth-child(3) {
border-radius: 10px 30px;
}
div:nth-child(4) {
border-radius: 10px 30px 60px;
}
div:nth-child(5) {
border-radius: 10px 20px 30px 40px;
}
div:nth-child(6) {
border-radius: 90px;
height: 100px;
}
div:last-child {
border-radius: 100px 0;
}
</style>
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html>
新浪导航栏
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
nav {
height: 41px;
background-color: #fcfcfc;
border-bottom: 1px solid #edeef0;
border-top: 3px solid #ff8500;
}
nav a {
font-size: 14px;
color: #4c4c4c;
text-decoration: none;
padding: 0 15px;
display: inline-block;
height: 41px;
line-height: 41px;
}
nav a:hover {
background-color: #eee;
}
</style>
</head>
<body>
<nav>
<a href="#">设为首页</a>
<a href="#">手机新浪网</a>
<a href="#">移动客户端</a>
</nav>
</body>
</html>