细说CSS中的display属性
相信大部分奋战在前端的,尤其在前端攻城的过程中,有一种越陷越深的感觉,不错,一如前端深似海,从此妹子是浮云啊,前端上手容易,深入难啊!下面我就CSS中的display属性讲下我自己所积累的,与大家共享下,大神勿喷,我只是路过的。
css中display属性在W3C教程上有简要说明:http://www.w3school.com.cn/cssref/pr_class_display.asp;当然我是觉得讲的不够详细,也有部分可能没深度用过的。
display属性取值有:block,inline-block;table;inline-table,table-row,table-cell,table-caption;list-item等,这都是基本的用法,相信大家在写一些弹出框效果的时候用的最多的就是通过display:block和none属性来显示与隐藏弹窗。
如:在JQuery中可以:
$("#div").css("display":"block");来显示隐藏想要的DOC对象;
1、block与inline-block属性其实都是块级元素,不过inline-block一个是行内的块级元素;
2、table,table-row,table-cell,table-caption,list-item;
相信大部分的很少去了解这些属性值,其实这些都是对应的在表格table中的对应项跟ul标签中的li项,其中display:table其实就是一个table表格,而table-row与table-cell分别对应table表格中的tr跟td标签,list-item就是li标签;其实这些属性在移动前端开发中用的也挺多的,而且对应的也符合table标签的一些属性,如在td中vertical-align用div
display:table-cell同样可以实现,这样可以帮我们解决一些较前卫的浏览器中减少很多不必要的困扰。
ps:如果规定了 !DOCTYPE,则 Internet Explorer 8 (以及更高版本)支持属性值 "inline-table"、"run-in"、"table"、"table-caption"、"table-cell"、"table-column"、"table-column-group"、"table-row"、"table-row-group"、以及
"inherit"。
还有: 今天同学问我在table元素中想通过js来实现表格的一行的隐藏和显示,结果他用了上述Jquery代码,结果页面乱了,后来我用了$("#div").css("display":"table-row");达到了理想效果。
当然还有一些取值,先暂时讲这么多,下次更新,我们来看一些代码及效果图:
源代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>display属性详解</title>
<style type="text/css">
.table {
width: 500px;
height: 200px;
margin-left: 100px;
table-layout: fixed;
border-collapse: collapse;
}
.table td {
border: 1px solid green;
background-color: #e2e2e2;
}
.table_model {
width: 500px;
height: 20px;
margin: 0 auto;
}
.display_table {
display: table;
}
.display_caption {
width: 100%;
height: 30px;
line-height: 30px;
text-align: center;
color: blue;
display: table-caption;
}
.display_row_tr {
width: 100%;
height: 50px;
display: table-row;
}
.display_cell_td {
width: 98px;
height: 48px;
display: table-cell;
background-color: pink;
border: 1px solid yellow;
}
</style>
</head>
<body>
<table class="table">
<caption>我是表格做的</caption>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<div class="table_model display_table">
<div class="display_caption">我是DIV模拟表格,不用float哟!!</div>
<div class="display_row_tr">
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
</div>
<div class="display_row_tr">
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
</div>
<div class="display_row_tr">
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
</div>
<div class="display_row_tr">
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
<div class="display_cell_td"></div>
</div>
</div>
</body>
</html>
细说CSS中的display属性的更多相关文章
- CSS中的display属性
CSS中的display属性 display:block是可以把非块级元素强制转换为块级元素显示,如内嵌元素span,原来不支持设置宽高,宽度是由内容撑开的,几个span元素是在同一行内的,如果给sp ...
- 理解与应用css中的display属性
理解与应用css中的display属性 display属性是我们在前端开发中常常使用的一个属性,其中,最常见的有: none block inline inline-block inherit 下面, ...
- CSS中的display属性(none,block,inline,inline-block,inherit)
css中的display属性(none,block,inline,inline-block,inherit) display属性是我们在前端开发中常常使用的一个属性,其中,最常见的有: none bl ...
- 转: 详解css中的display属性
在一般的CSS布局制作时候,我们常常会用到display对应值有block.none.inline这三个值.下面我们来分别来认识和学习什么时候用什么值.这里通过CSS display知识加实例讲解方法 ...
- 细说css中的position属性
有过css开发经验的同学,对于position这个属性一定不会陌生,然而这个熟悉的属性确是面试题中的常客,也就说明了该属性在css的世界是有一定的江湖地位的,那么我们就来详细的说说position这个 ...
- 深入理解css中的margin属性
深入理解css中的margin属性 之前我一直认为margin属性是一个非常简单的属性,但是最近做项目时遇到了一些问题,才发现margin属性还是有一些“坑”的,下面我会介绍margin的基本知识以及 ...
- CSS 中关于background 属性功能
background 是 css中的核心属性,我们对他应该充分了解. background-image 定义背景图像 这个属性是我们用的最多的属性 设置背景图像有两个方式 background: ...
- Css中的Position属性
Css中的Position属性 Css属性在线查询地址: http://www.css88.com/book/css/properties/index.htm CSS 中的 position 属性 在 ...
- css中background背景属性概
css中background背景属性概 background:url(背景图片路径) no-repeat;/*不重复默认在左上方*/background:url(背景图片路径) no-repeat ...
随机推荐
- maven的坑: Exception in thread "pool-1-thread-1" java.lang.NoClassDefFoundError: org/eclipse/aether/spi/connector/Transfer$State
搭建ReboletricSample的环境: 搭建完成,执行的时候报错: Exception in thread "main" java.lang.NoClassDefFoundE ...
- jquery动态加载脚本
如果你使用的是jQuery,它里面有一个内置的方法可以用来加载单个JS文件.当你需要延迟加载一些js插件或其它类型的文件时,可以使用这个方法. 一.jQuery getScript()方法加载java ...
- secureCRT与vim配置
折腾了一天,给服务器新装了centos系统,用crt连接,vim用着很不习惯. 修改配色,快捷键啥的都不怎么起效. 后来发现.crt里的会话选项-终端-仿真 里配成xtream,使用颜色方案就可以了.
- Spring中的JDBC操作
一.Spring模板JdbcTemplate 为了使 JDBC 更加易于使用, Spring 在 JDBC API 上定义了一个抽象层, 以此建立一个 JDBC 存取框架JdbcTemplate. 作 ...
- sort_action
li, r = [23,8, 45, 5, 0, -6, 745,8, 8], [] while (len(li) > 0): loop_, min, tag = len(li), li[0], ...
- 虚拟化(五):vsphere高可用群集与容错(存储DRS是一种可用于将多个数据存储作为单个数据存储群集进行管理的功能)
vsphere高级功能需要vcenter server和共享存储的支持才能实现.vsphere的高级功能有 vmotion.storage vmotion.vsphere HA.vsphere DRS ...
- 8.JS数据类型
① 数据类型:字符串,数字,布尔,数组,对象,Null,Undefined ② JavaScript拥有动态类型.这意味着相同的变量可用作不同的类型: 实例 var x: //x为undefine ...
- Mac下通过命令行安装npm install -g 报错,如何解决?
1, 使用 sudo npm install -g n2, 或者 sudo chmod -R 777 /usr/local/lib,然后 npm install -g
- appium导入哪些java模块
简单介绍 讲解一个appium测试脚本需要导入哪些java模块. 导入的java模块 明确两点信息: 一个脚本需要讲清楚测试环境:1.自动化平台方面,测试的平台是什么(appium或者selendro ...
- leetcode leetcode 783. Minimum Distance Between BST Nodes
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the ...