Home > Article > Web Front-end > How to realize automatic hiding of content beyond html
htmlThe way to achieve content beyond automatic hiding is to add the overflow attribute to the text content and set the attribute value to hidden, such as [div{overflow: hidden;}].
The operating environment of this article: windows10 system, html 5, thinkpad t480 computer.
In actual work, we may need to display a long text, but the size of our text box may not be that large, so how should we do it? In fact, it is very simple, just hide the content beyond the text box. But to achieve this effect, how should we do it?
We only need to use the overflow attribute to achieve this effect.
The overflow attribute specifies what happens if content overflows an element's box.
Common attribute values:
visible default value. The content will not be trimmed and will be rendered outside the element box.
hidden The content will be trimmed and the remaining content will be invisible.
scroll The content will be trimmed, but the browser will display scroll bars to view the remaining content.
#auto If content is trimmed, the browser displays scroll bars to view the remaining content.
inherit Specifies that the value of the overflow attribute should be inherited from the parent element.
Code example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <style> div.ex1 { background-color: lightblue; width: 110px; height: 110px; overflow: scroll; } div.ex2 { background-color: lightblue; width: 110px; height: 110px; overflow: hidden; } div.ex3 { background-color: lightblue; width: 110px; height: 110px; overflow: auto; } div.ex4 { background-color: lightblue; width: 110px; height: 110px; overflow: visible; } </style> </head> <body> <h1>overflow 属性</h1> <p>如果元素中的内容超出了给定的宽度和高度属性,overflow 属性可以确定是否显示滚动条等行为。</p> <h2>overflow: scroll:</h2> <div class="ex1">php中文网提供大量免费、原创、高清的php视频教程,并定期举行公益php培训!可边学习边在线修改示例代码,查看执行效果!php从入门到精通,一站式php自学平台!</div> <h2>overflow: hidden:</h2> <div class="ex2">php中文网提供大量免费、原创、高清的php视频教程,并定期举行公益php培训!可边学习边在线修改示例代码,查看执行效果!php从入门到精通,一站式php自学平台!</div> <h2>overflow: auto:</h2> <div class="ex3">php中文网提供大量免费、原创、高清的php视频教程,并定期举行公益php培训!可边学习边在线修改示例代码,查看执行效果!php从入门到精通,一站式php自学平台!</div>
<h2>overflow: visible (默认):</h2> <div class="ex4">php中文网提供大量免费、原创、高清的php视频教程,并定期举行公益php培训!可边学习边在线修改示例代码,查看执行效果!php从入门到精通,一站式php自学平台!</div> </body> </html>
You can save the code running above to run locally and see the effect.
Related video sharing: html video tutorial
The above is the detailed content of How to realize automatic hiding of content beyond html. For more information, please follow other related articles on the PHP Chinese website!