display和visibility的区别
2016-07-12 18:05
465 查看
style.visibility和style.display都可以实现对页的隐藏,但visibility要占用域的空间,而display则不占用
将元素display属性设为 block,会在该元素后换行。
将元素display属性设为 inline,会消除元素换行。
将元素display属性设为 none,隐藏该元素内容,且不占用域的空间。
将元素visibility属性设为 hidden,隐藏该元素内容,但占用域的空间。
将元素visibility属性设为 visible,显示元素内容。
占不占用域有什么影响呢?但好像推荐都用display;
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>visibility and display different</title>
<style>
.test-display {
display:none;
}
.test-visibility {
visibility:hidden;
}
</style>
</head>
<body>
<h1>Twilight</h1>
<p>if you hard you will be more lucky!</p>
<p>next will display;none!</p>
<p class="test-display">so i will make this paragraph!</p>
<p>next will visibility;hidden;</p>
<p class="test-visibility">this paragraph use visibility;hidden</p>
<p>let's begin!</p>
</body>
</html>
运行结果是:
next will display;none!
next will visibility;hidden;
let's begin!
所以是visibility虽然隐藏了,但是还在占用位置,今天吴老师讲了,所以觉得应该试一下,以前都是看过而已
将元素display属性设为 block,会在该元素后换行。
将元素display属性设为 inline,会消除元素换行。
将元素display属性设为 none,隐藏该元素内容,且不占用域的空间。
将元素visibility属性设为 hidden,隐藏该元素内容,但占用域的空间。
将元素visibility属性设为 visible,显示元素内容。
占不占用域有什么影响呢?但好像推荐都用display;
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>visibility and display different</title>
<style>
.test-display {
display:none;
}
.test-visibility {
visibility:hidden;
}
</style>
</head>
<body>
<h1>Twilight</h1>
<p>if you hard you will be more lucky!</p>
<p>next will display;none!</p>
<p class="test-display">so i will make this paragraph!</p>
<p>next will visibility;hidden;</p>
<p class="test-visibility">this paragraph use visibility;hidden</p>
<p>let's begin!</p>
</body>
</html>
运行结果是:
Twilight
if you hard you will be more lucky!next will display;none!
next will visibility;hidden;
let's begin!
所以是visibility虽然隐藏了,但是还在占用位置,今天吴老师讲了,所以觉得应该试一下,以前都是看过而已
相关文章推荐
- Web布局连载——两栏固定布局(五)
- [div+css]晒晒最新制作专题推广页模板
- 盒子模型
- CSS选择器
- CSS样式优先权
- [css] line-height 百分比单位和数值单位的区别
- Apple官网研究之使用Justify布局导航
- 关于前端的思考与感悟
- rem : web app适配的秘密武器
- jquery高级应用之Deferred对象
- 移动端点击事件全攻略,这里的坑你知多少?
- $q 实例分析 Angular 中的 Promise
- 浏览器中唤起native app || 跳转到应用商城下载
- Angular directive 实例详解
- 关于浮动与清除浮动,你应该知道的
- 数组reduce方法的高级技巧
- 设计更快的网页(三):字体和 CSS 调整
- 纯CSS制作的新闻网站中的文章列表