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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML: Building the Structure of Web Pages HTML: Building the Structure of Web Pages Apr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML vs. CSS vs. JavaScript: A Comparative Overview HTML vs. CSS vs. JavaScript: A Comparative Overview Apr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML vs. CSS and JavaScript: Comparing Web Technologies HTML vs. CSS and JavaScript: Comparing Web Technologies Apr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML: Is It a Programming Language or Something Else? HTML: Is It a Programming Language or Something Else? Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

What is the difference between <strong>, <b> tags and <em>, <i> tags? What is the difference between <strong>, <b> tags and <em>, <i> tags? Apr 28, 2025 pm 05:42 PM

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.

See all articles