Heim  >  Artikel  >  Web-Frontend  >  CSS如何将超出的内容隐藏_html/css_WEB-ITnose

CSS如何将超出的内容隐藏_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:40:311166Durchsuche

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>

原文地址是:http://www.51texiao.cn/div_cssjiaocheng/2015/0507/905.html

最为原始地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=4648

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn