1.overflow属性
这个属性规定了当内容比盒子设置的大小要大时,发生的事情
语法:overflow:visible | hidden | scroll | inherit;
visible:默认值,文本内容不会被裁剪,全部显示在盒子中,显示不下时,会呈现在盒子外。
hidden:只显示盒子内部的内容,盒子显示不下的内容会被隐藏。
scoll:盒子内的内容如果超出盒子能够显示的部分,那么就会出现滚动条。可以滚动查看。
inherit:继承父盒子的overflow的属性。
2.overflow-wrap属性
这个属性在长度溢出容器时,浏览器允许换行。
语法:overflow-wrap:normal | break-word ;
normal:盒子中如果存在特别长的单词,长度已经达到了盒子的宽度,那么该单词在normal属性下不会换行,超出盒子的部分会在盒子后正常显示。只会在断点处换行,如空格、符号。
break-word:盒子内容会在盒子宽度承受不住时,自动换行。
3.盒子边框重叠问题
这个问题也是我今天练习时遇到的问题。
1.如果使用的是table表格,那么边框之间就可以选用border-collapse属性
以上两图为同一个表格,第二表格在第一张表格的基础上,给table标签加了条样式。border-collapse:collapse;
border-collapse该样式属性一共包括三个值:separate、collapse、inherit;
这里的separate其实就是默认值,表示边框分离开,就如上面的左图所示。然后inherit还是继承属性。
2.如果使用的是普通盒子之间的border叠加问题。那么可以选用margin属性。
讲到这里说一点,盒子就算设置了display:inline-block;想要在一行内显示,盒子之间也会存在一点空白间隙。这时候就需要我们设置一个font-size:0;来消除这个间隙。就我而言我一般在通配符中连同消除系统自带的内外边距时,一起设置了。设置后,文中有文字的部分都需要在其样式下都设置一下大小,否则会被通配符中设置的值给覆盖掉而不显示。
然后我们消除盒子边框叠加的效果,明显感觉到叠加的部分更粗。 下图就是放大后的效果,明显可以看到盒子1、盒子2边框叠加部分是比盒子的其他边的黑边框更粗。这是,我们需要给左边盒子一个margin-right:-1px;或者给右边的盒子一个margin-left:-1px;这里的外边距的值是根据我们设置的边框来定的。
我设置了边框为1px,叠加部分为2px,那么我只需要左右的一个盒子向另一个盒子的方向移动一个边框的距离就可以消除重叠的影响。不需要多移动,再移动盒子的边框就会移出来了。
最后附上今天写小练习。源码也附上。那连个小图就不附了,想练手的可以自行找图替代或者私聊我要。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<div class="root">
<div class="title">新书热卖榜</div>
<div class="content">
<ul class="header">
<li>
<a href="#">总榜</a>
</li>
<li>
<a href="#">童书</a>
</li>
<li>
<a href="#">励志</a>
</li>
<li>
<a href="#">保健</a>
</li>
<li>
<a href="#">美食</a>
</li>
</ul>
<div class="first">
<div>
1
</div>
<div>
<img src="./img/book.jpg" alt="">
</div>
<div>
<span>
<a href="#">基地重生沙克尔顿南极</a>
</span>
<span>¥40.10</span>
<span>¥68.00</span>
<span>333条评论</span>
</div>
</div>
<div class="line"></div>
<div class="content-item">
<span class="one">2</span>
<span class="two">
<a href="#">奇幻梦境:-本漫游奇境的手绘</a>
</span>
</div>
<div class="line"></div>
<div class="content-item">
<span class="one">3</span>
<span class="two">
<a href="#">奇幻梦境:-本漫游奇境的手绘</a>
</span>
</div>
<div class="line"></div>
<div class="content-item">
<span class="one">4</span>
<span class="two">
<a href="#">奇幻梦境:-本漫游奇境的手绘</a>
</span>
</div>
<div class="line"></div>
<div class="content-item">
<span class="one">5</span>
<span class="two">
<a href="#">奇幻梦境:-本漫游奇境的手绘</a>
</span>
</div>
<div class="line"></div>
<div class="content-item">
<span class="one">6</span>
<span class="two">
<a href="#">奇幻梦境:-本漫游奇境的手绘</a>
</span>
</div>
<div class="line"></div>
</div>
</div>
</body>
</html>
*{
margin: 0;
padding: 0;
list-style: none;
font-size: 0;
}
.root{
width: 245px;
margin: 0 auto;
}
.title{
height: 40px;
font-size: 18px;
font-weight: 700;
line-height: 40px;
padding-left: 30px;
margin-bottom: 5px;
background: url('../img/sprite.png') no-repeat 3px 5px;
}
.content{
width: 100%;
margin: 0 auto;
border: 1px solid lightgray;
}
.header{
/* display: flex; */
/* justify-content: space-around; */
margin-bottom: 10px;
}
.header li{
display: inline-block;
width: 50px;
height: 25px;
font-size: 14px;
text-align: center;
line-height: 20px;
border: 1px solid lightgray;
box-sizing: border-box;
border-spacing: 0;
border-collapse: collapse;
margin-left: -1px;
margin-top: -1px;
}
.header li:last-child{
border-right: 0px;
}
.header li a {
color: black;
text-decoration: none;
font-size: 14px;
}
.header li:hover {
border-bottom: 0px;
}
.header li:hover a{
color: green;
font-weight: 700;
text-decoration: underline;
}
.first div{
display: inline-block;
}
.first div:nth-child(1){
color: red;
font-size: 15px;
vertical-align: top;
padding-left: 5px;
}
.first div:nth-child(3){
width: 80px;
vertical-align: top;
}
.first span{
font-size: 15px;
display: inline-block;
padding-left: 5px;
}
.first div:nth-of-type(3) span a{
font-size: 15px;
text-decoration: none;
color: #000;
}
.first div:nth-of-type(3) span:hover a{
color:darkcyan
}
.first div span:nth-of-type(2){
color: #C0353F;
font-weight: 700;
margin-top: 5px;
}
.first span:nth-of-type(3){
margin: 3px 0px;
font-weight: 700;
color: gray;
text-decoration: line-through;
}
.first span:nth-of-type(4){
margin: 3px 0px;
color: rgb(11, 106, 11);
}
.content-item{
height: 30px;
}
.content-item span{
display: inline-block;
}
.one{
font-size: 15px;
line-height: 30px;
padding-left: 5px;
}
.content div:nth-of-type(3) .one,
.content div:nth-of-type(5) .one,
.content div:nth-of-type(7) .one
{
color: red;
}
.two{
height: 30px;
line-height: 30px;
padding-left: 15px;
}
.two a{
font-size: 15px;
text-decoration: none;
color: #000;
}
.two:hover a{
color:darkcyan
}
.line {
width: 230px;
height: 0px;
border-top: 1px solid lightgray;
margin: 5px auto;
box-sizing: border-box;
box-shadow: 2px 2px 2px #F0F0F0;
}