细说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 ...
随机推荐
- java的一个简单死锁的例子
package com.deadlock; /* * 演示死锁:(由毕向东视频所得) * 一种解释:Thread—0拿到lock1锁,Thread—1拿到lock2锁,Thread—0想要lock2锁 ...
- view 视图生命周期
layout控制当前view的布局,onlayout控制子view的布局,容器ui会用到 onIntercept在父亲这执行拦截,子视图可通过requestDisallow请求父亲不要拦截
- 解决Android Studio Fetching Android SDK component information失败问题【转】
本文转载自:http://blog.csdn.net/isesar/article/details/41908089 Android Studio 安装完成后,如果直接启动,Android Studi ...
- Codeforces Round #258 (Div. 2) D. Count Good Substrings —— 组合数学
题目链接:http://codeforces.com/problemset/problem/451/D D. Count Good Substrings time limit per test 2 s ...
- 人生苦短之Python多线程
#encoding=utf-8 import threading import time ''' python多线程并不是真正意义上的多线程,通常我们所说的多线程是多个线程同时执行某功能,而在pyth ...
- 专网IP和公网IP的区别是什么
专网ip是自己网内用,公网的话就全球有效 最大区别是公网IP世界只有一个,私网IP可以重复,但是在一个局域网内不能重复 访问互联网是需要IP地址的,IP地址又分为公网IP和私网IP,访问互联网需要公网 ...
- uva 10881 Piotr's Ants 解题报告
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&pa ...
- C#中XML解析的增加修改和删除
01添加xml节点 private void AddXml(string image, string title) { XmlDocument xmlDoc = n ...
- jquery的跨域请求
项目中关于ajax jsonp的使用,出现了问题:可以成功获得请求结果,但没有执行success方法总算搞定了,记录一下 function TestAjax() { $.ajax({ ...
- C++之虚函数与虚继承详解
准备工作 1.VS2012使用命令行选项查看对象的内存布局 微软的Visual Studio提供给用户显示C++对象在内存中的布局的选项:/d1reportSingleClassLayout.使用方法 ...