Home > Web Front-end > CSS Tutorial > How to hide content that overflows a DIV

How to hide content that overflows a DIV

php中世界最好的语言
Release: 2017-11-23 14:17:32
Original
4863 people have browsed it

Usually when we lay out the web page, there is always a problem with too much text content, which exceeds the height that exceeds our limit. Then there will be some pictures that will break the DIV and make the web page misaligned and confusing. Then How do we solve this?

We need to solve how to use CSS to automatically hide content that exceeds the set CSS width and CSS height without breaking the DIV layout.

Especially in IE6, if the content exceeds the height and width of the object, it will be burst and increased in height. At this time, we can use the following solutions.

Solution to CSS style

At this time we can use CSS overflowStyle solution:

Corresponding style overflow:hidden

Div{ overflow:hidden}

After setting like this, if the DIV object is set to a certain width and height, adding overflow:hidden at this time will hide the content including pictures that exceeds the width and height of the DIV.

Related reading: css implements overflow and exceeds the text content to display ellipses

Hide the excess content case

1. Hide the text content that exceeds the width and height of the object

If we In order to align the object beautifully in a layout, sometimes we need to set the height and width of the object and then fix it. At this time, we need to realize that no matter how much content and text there is, the layout should not exceed the set width and height. At this time, we need the help of overflow:hidden.

CSS code:

<style> 
.div{ width:300px; height:50px; line-height:25px; overflow:hidden} 
/* 设置对象高度宽度,同时设置overflow:hidden */ 
</style>
Copy after login
Copy after login

Html code:

<div class="div">欢迎,
Copy after login

Here you can learn CSS and download the resources you need,

At the same time you can find yourself FAQAnswer

Solution to broken content

Set overflow:hidden in this way, no matter how much content there is, the object will be hidden. The width and height are set so that they cannot fit outside. Content.

Here, set an object box with a certain CSS width and CSS height, place a large picture, and then use overflow:hidden to hide the excess part.

Css code

<style> 
.div{ width:300px; height:50px; line-height:25px; overflow:hidden} 
/* 设置对象高度宽度,同时设置overflow:hidden */ 
</style>
Copy after login
Copy after login

Html code

<div class="div"> 
<img src="http://www.php.cn" /> 
</div>
Copy after login

So, if you want the content to not exceed the width and height limit set by the object, then use overflow:hidden to hide the excess part. .

There are so many overflow hidden tips, please pay attention to php Chinese website for more exciting Other related articles!

Related reading:

How to use DIV in HTML

##How to use HTML5

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template