目录
1. margin负值的运用
- 让每个盒子margin往左侧移动-1px 正好压住相邻盒子的边框
- 鼠标经过某个盒子的时候,提高当前盒子的层级即可,如果没有定位则加相对定位(保留位置),如果有定位则加z-index
<style> ul li { position: relative; float: left; list-style: none; width: 150px; height: 200px; border: 1px solid red; /* 原本margin-left为0,两个盒子相邻间的边框显现出来的结果为2px */ /* 使相邻间的线变细,压住相邻盒子的边框 */ margin-left: -1px; } /* 相邻盒子的边框被margin-left压住了,应该提高盒子的层级,使边框显现出来 */ /* ul li:hover { 1.如果盒子没有定位,给盒子加相对定位 position: relative; border: 1px solid green; } */ ul li:hover { /* 2.如果盒子有定位,则加z-index提高盒子的层级 */ z-index: 1; border: 1px solid green; } </style> </head> <body> <ul> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> </body>
显示的效果如图:
2. 文字围绕浮动元素
<style>
.box {
width: 300px;
height: 80px;
background-color: pink;
margin: 0 auto;
padding: 5px;
}
.pic {
float: left;
width: 102px;
height: 68px;
margin-top: 5px;
margin-right: 5px;
}
.pic img {
width: 100%;
}
</style>
</head>
<body>
<div class="box">
<div class="pic">
<img src="images/data.png" alt="">
</div>
<p>杨国福要上市了,我也要吃不起了。</p>
</div>
</body>
显示的效果如图:
3. 行内块的巧妙运用
<style>
* {
margin: 0;
padding: 0;
}
.box {
text-align: center;
}
.box a {
/* 行内块元素,可以设置宽度和高度 */
display: inline-block;
width: 36px;
height: 36px;
background-color: #f7f7f7;
border: 1px solid #ccc;
text-decoration: none;
line-height: 36px;
color: #333;
font-size: 14px;
}
.box .current,
.box .lep {
background-color: #fff;
border: none;
}
.box .prev,
.box .next {
width: 85px;
}
input {
width: 45px;
height: 36px;
border: 1px solid #ccc;
outline: none;
}
button {
width: 45px;
height: 36px;
border: 1px solid #ccc;
outline: none;
}
</style>
</head>
<body>
<div class="box">
<a href="#" class="prev"><<上一页</a>
<a href="#">1</a>
<a href="#" class="current">2</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#" class="lep">...</a>
<a href="#" class="next">>>下一页</a>
到第
<input type="text">
页
<button>确定</button>
</div>
</body>
显示的效果如图:
4. css三角强化
<style>
.box {
width: 0;
height: 0;
/* 1.把上边框的宽度放大 */
border-top: 100px solid pink;
border-right: 50px solid red;
/* 2.左边框和下边框的宽度变为0 */
border-bottom: 0px solid green;
border-left: 0px solid blue;
}
</style>
</head>
<body>
<div class="box">
</div>
</body>
显示的效果如下:
<style>
.box {
width: 0;
height: 0;
/* 1.把上边框的宽度放大 */
/* border-top: 100px solid pink;
border-right: 50px solid red; */
/* 2.左边框和下边框的宽度变为0 */
/* border-bottom: 0px solid green;
border-left: 0px solid blue; */
/* 1.只保留右边的边框有颜色 */
border-color: transparent red transparent transparent;
/* 2.样式都是solid */
border-style: solid;
/* 3.上边框宽度变大,右边框小一点,下边框和左边框宽度都为0 */
border-width: 100px 50px 0 0;
}
</style>
</head>
<body>
<div class="box">
</div>
</body>
显示的效果如下:
<style>
.price {
width: 160px;
height: 24px;
line-height: 24px;
border: 1px solid red;
margin: 0 auto;
}
.now {
position: relative;
float: left;
width: 90px;
height: 100%;
background-color: red;
text-align: center;
font-weight: 700;
color: #fff;
margin-right: 8px;
}
.price i {
position: absolute;
right: 0;
top: 0;
width: 0;
height: 0;
border-color: transparent #fff transparent transparent;
border-style: solid;
border-width: 24px 10px 0 0;
}
.prev {
width: 70px;
text-align: center;
font-size: 12px;
color: gray;
text-decoration: line-through;
}
</style>
</head>
<body>
<!-- <div class="box"></div> -->
<div class="price">
<span class="now">
¥1899
<i></i>
</span>
<span class="prev">¥2399</span>
</div>
</body>
显示的效果如下: