CSS如何将超出的内容隐藏:
有时候容器中的内容会超出容器的边界,显得非常的不好看,所以需要将超出的部分隐藏,下面简单介绍一下实现此效果的方法。
代码实例如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.51texiao.cn/" />
<title>蚂蚁部落</title>
<style type="text/css">
.parent {
width: 200px;
height: 200px;
border: 1px solid red;
}
.children {
width: 240px;
height: 250px;
border: 1px solid blue;
}
</style>
</head>
<body>
<div class="parent">
<div class="children"></div>
</div>
</body>
</html>
以上代码中的内容超出了边界,那么我们可以使用将容器的overflow属性值设置为hidden即可。
上面的设置的是将所有超出的内容都隐藏,我们也可以设置横向或者纵向超出内容的隐藏。代码实例如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.51texiao.cn/" />
<title>蚂蚁部落</title>
<style type="text/css">
.parent {
width: 200px;
height: 200px;
border: 1px solid red;
overflow: hidden
}
.children {
width: 240px;
height: 250px;
border: 1px solid blue;
}
</style>
</head>
<body>
<div class="parent">
<div class="children"></div>
</div>
</body>
</html>
以上代码中,子div无论是纵向还是横向都超出了边界。如果我们只想隐藏横向超出的内容,可以使用如下代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.51texiao.cn/" />
<title>蚂蚁部落</title>
<style type="text/css">
.parent {
width: 200px;
height: 200px;
border: 1px solid red;
overflow-x: hidden
}
.children {
width: 240px;
height: 250px;
border: 1px solid blue;
}
</style>
</head>
<body>
<div class="parent">
<div class="children"></div>
</div>
</body>
</html>