Home Web Front-end HTML Tutorial overflow 属性_html/css_WEB-ITnose

overflow 属性_html/css_WEB-ITnose

Jun 24, 2016 am 11:18 AM

写在前面的话:

2016年5月4日青年节,作为一名正青春的学生党,开始了博客生涯,励志做个勤奋上进的好青年。幻想着毕业后月薪W+ 、走上人生巅峰的职场生活......

然而 然而 然而 ,自制力有限的我昨天还是没有控制住,追起了《欢乐颂》,啊啊啊啊啊,一看就是一整天啊,简直是大写的颓废!!!

哈哈,我相信很多人也在追这部剧,在这部剧里,每个人应该都能够找到自己喜欢的角色,也应该能够从她们身上找到点点相似的地方,个人感觉是一部很值得看的剧。

不过话又说回来,剧里的故事都是别人的,还应该及时回到现实生活中,做好自己的主角,想清楚自己想要什么样的生活,或者是不要什么样的生活,踏踏实实往前走。。。

啊啊啊,请不要打翻这碗鸡汤,勿喷 勿喷 勿喷,跪谢!

还有,今天是母亲节,记得给自己母亲打个电话。。。来自

 

overflow 有以下四个属性(来自W3School)

1、overflow:visible

代码如下:

<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><title>Examples</title><meta name="description" content=""><meta name="keywords" content=""><link href="" rel="stylesheet">    <style type="text/css">        .box{margin: auto;            width: 150px;            height: 50px;            border: 1px solid red;            overflow: visible;        }    </style></head>    <body>        <div class="box">            <img  src="/static/imghw/default1.png"  data-src="img/flower.png"  class="lazy"/ alt="overflow 属性_html/css_WEB-ITnose" >        </div>    </body></html>
Copy after login

效果如下:

overflow:visible 也是overflow 默认的属性值,如上图效果所示,超出父元素的部分会依旧显示出来,同时超出部分不会撑开父元素的高。

2、overflow:hidden

代码如下:

<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><title>Examples</title><meta name="description" content=""><meta name="keywords" content=""><link href="" rel="stylesheet">    <style type="text/css">        .box{margin: auto;            width: 150px;            height: 50px;            border: 1px solid red;            overflow: hidden;        }    </style></head>    <body>        <div class="box">            <img  src="/static/imghw/default1.png"  data-src="img/flower.png"  class="lazy"/ alt="overflow 属性_html/css_WEB-ITnose" >        </div>    </body></html>
Copy after login

效果如下:

如图所示,子元素会显示在父元素内,超出父元素的部分会被隐藏。同时,在上一次清除浮动问题中也讲到过,可以给父元素加overflow:hidden,来达到清除浮动的效果。

3、overflow:scroll

代码如下:

<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><title>Examples</title><meta name="description" content=""><meta name="keywords" content=""><link href="" rel="stylesheet">    <style type="text/css">        .box{margin: auto;            width: 150px;            height: 50px;            border: 1px solid red;            overflow: scroll;        }    </style></head>    <body>        <div class="box">            <img  src="/static/imghw/default1.png"  data-src="img/flower.png"  class="lazy"/ alt="overflow 属性_html/css_WEB-ITnose" >        </div>    </body></html>
Copy after login

效果如下:

如上图所示,此时设置的是overflow:scroll ,x和y方向都会产生滚动条,及时父元素的宽足够子元素的宽,也会产生滚动条,如果设置overflow-y: scroll;水平方向就不会产生滚动条,效果如下:

4、overflow: auto

代码如下:

<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><title>Examples</title><meta name="description" content=""><meta name="keywords" content=""><link href="" rel="stylesheet">    <style type="text/css">        .box{margin: auto;            width: 150px;            height: 50px;            border: 1px solid red;            overflow: auto;        }    </style></head>    <body>        <div class="box">            <img  src="/static/imghw/default1.png"  data-src="img/flower.png"  class="lazy"/ alt="overflow 属性_html/css_WEB-ITnose" >        </div>    </body></html>
Copy after login

效果如下:

此时浏览器会根据父元素和子元素的宽和高,自动设置滚动条。

当然,以上overflow 的属性都是在父元素固定宽和高的基础上实现的效果。

 

希望以上的介绍对您能有所帮助,同时这也是我自己只是内化的过程,感谢博客园平台!----来自

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

See all articles