背景综合案例
<style>
body {
background-color: #000;
}
/* a是行内块元素没有宽高,display:inline-block;转为行内块元素 inline块元素 */
a {
display:inline-block;
width: 200px;
height: 50px;
/* background-color: orange; */
text-align: center;
line-height: 50px;
/* line-height=height的高度是垂直居中 一行才能生效*/
color: #fff;
font-size: 22px;
text-decoration:none;
/* 文本装饰:line-through 删除线
none 无线
underline 下划线 a链接文本自带的
overline 上划线 */
}
a:hover {
color: orange;
}
</style>
</head>
<body>
<a href="#">专区说明</a>
<a href="#">申请资格</a>
<a href="#">奖励总换</a>
<a href="#">下载游戏</a>
</body>
导航栏案例
<style>
nav {
height: 41px;
background-color: rgb(236, 236, 236);
border-top: 3px solid #FF8500;
border-bottom: 1px solid #EDEF00;
}
nav a {
font-size: 16px;
color: #3a3a39;
text-decoration: none;
/* 取消下划线 */
padding:0 15px;
height: 41px;
background-color: rgb(116, 116, 116);
/* 因为链接是行内元素 转为行内块元素 */
display:inline-block;
line-height: 41px;
/* padding-top: 20px; */
}
nav a:hover {
background-color: blue;
}
</style>
</head>
<body>
<nav>
<a href="#">首页</a>
<a href="#">新浪网</a>
<a href="#">网站导航</a>
<a href="#">姜云升</a>
</nav>
</body>
盒子border
<style>
div {
font-size: 30px;
width: 200px;
height: 200px;
border-width: 5px;
/* 边框宽度 粗细 */
border-color: red;
/* 边框颜色 */
border-style: solid;
/* 边框样式: solid:单实线
dashed:虚线
dotted:电线
double:双实线
*/
}
input {
border: 0;
/* 取消border边框 */
}
.uesr {
border-width: 1px;
border-color: red;
border-style: solid;
}
.nc {
/* border-top: 1px;
border-color: blue;
border-style: solid; */
border-top: 1px solid green;
}
.js {
border-bottom: 1px;
border-color: rgb(0, 255, 98);
border-style: solid;
/* border-collapse: collapse;合并边框 */
}
</style>
</head>
<body>
<div>姜云升</div>
姜云升<input type="text" class="uesr" /><br />
姜云升<input type="text" class="nc" /><br />
姜云升<input type="text" class="js" /><br />
</body>
内边距padding
div {
width: 200px;
height: 200px;
border: 1px solid red;
font-size: 40px;
padding-left: 30px;
padding-right: 100px;
padding-top: 10px;
/* 左边距
padding:上 右 下 左*/
}
外边距margin
* {
margin:0;
padding:0;
}
div {
background-color: red;
width: 200px;
height: 200px;
margin: 30px 100px 50px 10px;
/* margin:上 右 下 左 */
}
图片背景文字盒子对齐的区别
div {
width: 300px;
height: 100px;
border: 1px solid red;
text-align: center;
/* 文字水平居中 */
margin: 10px auto;;
/* 盒子水平居中 左右auto */
}
</style>
</head>
<body>
1.文字水平居中 和 盒子水平居中
<div>文字水平居中</div>
2.插入图片和背景图片的区别
<section>
<p>插入图片用width height 直接改大小
用margin- 改位置</p>
<p>背景图片用background-size改大小
用background-position改位置
</p>
</section>
圆角边框
div {
width: 200px;
height: 200px;
border: 1px solid red;
}
div:first-child {
border-radius: 10px;
/* 圆角边框 可以变成圆
border-radius:左上 右上 右下 左下
*/
}
div:nth-child(2) {
border-radius: 100px;
/* 取宽度和高度的一半会变成圆形 或者 50%*/
}
div:nth-child(3) {
border-radius: 10px 110px ;
/* 取宽度和高度的一半会变成圆形 或者 50%*/
background-color: yellow;
border-style: none;
}
css层叠性就近原则
div {
color: orange;
font-size: 20px;
}
div {
color: blue; css层叠性就近原则
}
<div>王可可 dog</div>
根据就近原则文字会显示blue蓝色
css继承性
div {
color: blue;
font-size:100px;
}
<div>
<p>姜云升</p>
</div>
子标签会继承父标签的内容 p 继承 div 内容 字体显示blue蓝色
选择器小到大优先级
.batter :first-child同级 就近原则
div {
color: blue;
font-size: 30px;
}
.batter {
color: black;
}
:first-child {
color: rgb(192, 0, 0);
}
#wang {
color: rgb(255, 160, 200);
}
/* style="color: rgb(11, 255, 223); */
div {
color: rgb(174, 0, 255)!important;
}
<div class="batter" id="wang" style="color: rgb(11, 255, 223);">姜云升</div>