hi,你好!欢迎访问本站!登录
本站由简数采集腾讯云宝塔系统阿里云强势驱动
当前位置:首页 - HTML - 正文 请牢记本站网址www.sosophp.cn

CSS中overflow属性怎样运用【html5教程】

2019-11-26HTML搜搜PHP网56°c
A+ A-
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网别的相干文章!

  选择打赏方式
微信赞助

打赏

QQ钱包

打赏

支付宝赞助

打赏

  选择分享方式
  移步手机端
CSS中overflow属性怎样运用【html5教程】

1、打开你手机的二维码扫描APP
2、扫描左则的二维码
3、点击扫描获得的网址
4、可以在手机端阅读此文章
标签: