提供Discuz ,ECShop ,PHPCMS ,帝国CMS ,CSS教程 ,PHP教程 ,DedeCMS ,WordPress ,HTML教程等cms问题查询.
当前位置: CSS教程 > CSS中overflow属性怎样运用【css教程】,overflow属性

CSS中overflow属性是常常能够用到的属性,接下来的这篇文章我们就来看看CSS中overflow属性的仔细用法。

我们起首来看一下overflow属性的值有哪些?

overflow 属性规定当内容溢出元素框时发作的事变。

overflow有以下四个属性值

visible:初始值,内容不会被修剪,会呈如今元素框以外。

scroll:内容会被修剪,然则浏览器会显现转动条以便检察其他的内容。

hidden:内容会被修剪,而且其他内容是不可见的。

auto:假如内容被修剪,则浏览器会显现转动条以便检察其他的内容。

下面我们来仔细说一说overflow属性的这四个值

我们来看仔细的示例

代码以下

HTML代码

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>CSS overflow</title>
    <link rel="stylesheet" type="text/css" href="sample.css">
  </head>
  <body>
    <div class="hid">
      <p>
        The European languages are members of the same family. Their separate existence is a myth. For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ in their grammar, their pronunciation and their most common words. Everyone realizes why a new common language would be desirable: one could refuse to pay expensive translators.
      </p>
    </div>
    <br>
    <div class="scr">
      <p>
        The European languages are members of the same family. Their separate existence is a myth. For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ in their grammar, their pronunciation and their most common words. Everyone realizes why a new common language would be desirable: one could refuse to pay expensive translators.
      </p>
    </div>
    <br>
    <div class="vis">
      <p>
        The European languages are members of the same family. Their separate existence is a myth. For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ in their grammar, their pronunciation and their most common words. Everyone realizes why a new common language would be desirable: one could refuse to pay expensive translators.
      </p>
    </div>
  </body>
</html>

CSS代码

/*hidden*/
div.hid{
  width: 200px;
  height: 100px;
  overflow: hidden;
  background-color: #FF9999;
}
/*scroll*/
div.scr{
  width: 200px;
  height: 100px;
  overflow: scroll;
  background-color: #99FF99;
}
/*visible*/
div.vis{
  width: 200px;
  height: 100px;
  overflow: visible;
  background-color: #9999FF;
}

在浏览器上显现以下结果

当overflow的属性值是hidden时,结果以下

在hidden的情况下,不会显现出剩下的部份,也不能转动显现剩下的内容。

当overflow的属性值是scroll时,结果以下

在scroll的情况下,没有显现的内容能够转动。默许的情况下,笔墨在横向上会折回,垂直方向显现转动栏。

在css中设置white-space : nowrap(不自动转业的意义),也能够向横向转动。

CSS代码

div.scr{
  width: 200px;
  height: 100px;
  white-space:nowrap;
  overflow: scroll;
  background-color: #99FF99;
}

结果以下

别的,也能够运用overflow-x和overflow-y属性对垂直和横向的转动条的显现举行更加仔细的设置。

当overflow的属性值是visible时,结果以下

visible的情况下,从盒子中溢出显现。紫色的部份是div盒子。默许的情况下,笔墨在div的横向width中被折回,并在纵向方向上显现。

这个也和scroll属性值一样,在css中设置white-space : nowrap,也能够横向转动。

别的,假如不设置盒子的高度,就会自动转变盒子的高度。

div.vis{
  width: 200px;
  /* height: 100px;  */
  overflow: visible;
  background-color: #9999FF;
}

结果以下

末了,我们来看看当overflow属性值是auto时的仔细情况

HTML代码

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>CSS overflow</title>
  <link rel="stylesheet" type="text/css" href="sample.css">
</head>
<body>
<div class="aut">
  <p>
    The European languages are members of the same family. Their separate existence is a myth. For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ in their grammar, their pronunciation and their most common words. Everyone realizes why a new common language would be desirable: one could refuse to pay expensive translators.
      </p>
    </div>
  </body>
</html>

CSS代码

div.aut{
	width: 200px;
	height: 100px;
	overflow: auto;
	background-color: red;
}

在浏览器上运转的结果和scroll类似

以上就是CSS中overflow属性怎样运用的仔细内容,更多请关注ki4网别的相干文章!

「梦想一旦被付诸行动,就会变得神圣,如果觉得我的文章对您有用,请帮助本站成长」

分享到:
赞(0) 打赏

支付宝扫一扫打赏

微信扫一扫打赏

标签:

上一篇:

下一篇:

相关推荐

0 条评论关于"CSS中overflow属性怎样运用【css教程】,overflow属性"

最新评论

    暂无留言哦~~

博客简介

看古风美女插画Cos小姐姐,素材合集图集打包下载:炫龙网,好看二次元插画应有尽有,唯美小姐姐等你来。

友情链接

他们同样是一群网虫,却不是每天泡在网上游走在淘宝和网游之间、刷着本来就快要透支的信用卡。他们或许没有踏出国门一步,但同学却不局限在一国一校,而是遍及全球!申请交换友链

服务热线:
 

 QQ在线交流

 旺旺在线