一、常用css属性

(1) *block(区块)

行高 line-height:数值 | inherit | normal;
字间距 letter-spacing: 数值 | inherit | normal;
词间距 word-spacing: 数值 | inherit | normal;
空格 white-space: pre(保留) | nowrap(不换行) | normal;

  1. /*表格宽度自适应*/
  2. th {
  3. white-space: nowrap;
  4. }

显示 display:

  1. none; /*不显示,使用的场景非常多*/
  2. block; /*把内联标签变成块级标签*/
  3. inline; /*把块级标签变成内联标签*/
  4. list-item; /*列表项*/
  5. run-in; /*追加部分*/
  6. compact; /*紧凑*/
  7. marker; /*标记*/
  8. table;
  9. inline-table;
  10. table-raw-group;
  11. table-header-group;
  12. table-footer-group;
  13. table-raw;
  14. table-column-group;
  15. table-column;
  16. table-cell;
  17. table-caption; /*表格标题*/

(2) *box(盒子)

宽度 width: 长度 | 百分比 | auto;
高度 height: 长度 | 百分比 | auto;
清除 clear: none | left | right | both;
边界 margin: 上 右 下 左 ;
填充 padding: 上 右 下 左 ;
定位 position: absolute | relative | static;
透明度 visibility: inherit | visible | hidden;
溢出 overflow: visible | hidden | scroll auto;
裁切 clip: rect(12px,auto,12px,auto)

(3) float(漂浮)

漂浮 float: left | right | none; 在页面布局的时候用的最多

常见用法
  1. <div style='float:left;width: 50%;' >div1</div>
  2. <div style='float:right;width: 50%;' >div2</div>
一个问题

子标签使用了float时候,父标签的样式失效

  1. <div style='background-color:red;'>
  2. <div style="float: left">div1</div>
  3. <div style="float: left">div2</div>
  4. </div>

解决方案一:clear: both

  1. <div style='background-color:red;'>
  2. <div style="float: left">div1</div>
  3. <div style="float: left">div2</div>
  4. <div style="clear: both;"></div> <!--加上clear:both之后就正常了-->
  5. </div>

解决方案二:clearfix

  1. <div style='' class="clearfix">
  2. <div style="float: left">div1</div>
  3. <div style="float: left">div2</div>
  4. </div>
  1. .clearfix:after{
  2. content: ".";
  3. display: block;
  4. height: 0;
  5. clear: both;
  6. visibility: hidden;
  7. }

(4) position(定位)

fixed

一般用来写网页顶端的固定导航条,或者两侧的菜单。

  1. <!--对于块级标签来说加上position:fixed之后,该div就不会占一整行,一般需要手动定义宽度,如width:100%-->
  2. <div style="position:fixed;height:10%;color:white;width:100%;top:0px;">我是导航</div>
  3. <div style="">
  4. <div style="position:fixed;bottom: 0px;top:10%;float: left;width: 20%;我是菜单</div>
  5. <div style="float: right;width:80%;"><p>我是内容</p>
  6. <p>我是内容</p>
  7. <p>我是内容</p>
  8. <p>我是内容</p>
  9. <p>我是内容</p>
  10. <p>我是内容</p>
  11. <p>我是内容</p>
  12. <p>我是内容</p>
  13. <p>我是内容</p>
  14. <p>我是内容</p>
  15. <p>我是内容</p>
  16. <p>我是内容</p>
  17. <p>我是内容</p>
  18. <p>我是内容</p>
  19. <p>我是内容</p>
  20. <p>我是内容</p>
  21. <p>我是内容</p>
  22. <p>我是内容</p>
  23. <p>我是内容</p>
  24. <p>我是内容</p>
  25. <p>我是内容</p>
  26. <p>我是内容</p>
  27. <p>我是内容</p>
  28. <p>我是内容</p>
  29. <p>我是内容</p>
  30. <p>我是内容</p>
  31. <p>我是内容</p>
  32. <p>我是内容</p>
  33. </div>
  34. </div>
absolute与relative

这两者一般配合使用,用于调整div之间的相对位置

  1. <div style="position:relative;width: 300px;height: 150px;">
  2. <div style="position:absolute;float: left;width: 20%;bottom: 0px;right: 0px;">我是菜单</div>
  3. </div>

(5) 透明度

  1. .image{
  2. opacity: 0.5
  3. }
  1. <img src="http://www.jotlab.com/wp-content/uploads/2008/08/python.jpg" style="opacity: 0.5; width:50%; height:50%; ">

(6) font(字体)

颜色 color: 数值;
大小 font-size: 数值;
字体 font-family: "Courier New", Courier, monospace, "Times New Roman", Times, serif, Arial, Helvetica, sans-serif, Verdana
样式 font-style: oblique;(偏斜体) italic;(斜体) normal;(正常)
粗细 font-weight: bold;(粗体) lighter;(细体) normal;(正常)
变体 font-variant: small-caps;(小型大写字母) normal;(正常)

(4) background(背景)

背景 background: transparent; /透视背景*/
颜色
图片 background-image: url() | none;
重复 background-repeat: inherit | no-repeat | repeat | repeat-x | repeat-y;

  1. background-repeat : repeat; /*重复排列-网页默认*/
  2. background-repeat : no-repeat; /*不重复排列*/
  3. background-repeat : repeat-x; /*在x轴重复排列*/
  4. background-repeat : repeat-y; /*在y轴重复排列*/

滚动 background-attachment: fixed | scroll;
位置 background-position:数值 | top | bottom | left | right | center;

  1. background-position : 90% 90%; /*背景图片x与y轴的位置*/
  2. background-position : top; /*向上对齐*/
  3. background-position : buttom; /*向下对齐*/
  4. background-position : left; /*向左对齐*/
  5. background-position : right; /*向右对齐*/
  6. background-position : center; /*居中对齐*/

简写 background:背景颜色 | 背景图象 | 背景重复 | 背景附件 | 背景位置 ;

(7) text(文本)

大小写 text-transform: capitalize | uppercase | lowercase | none;
修饰 text-decoration: underline;(下划线) overline;(上划线) line-through;(删除线) blink;(闪烁)
排列 text-align: justify | left | right | center;
缩进 text-indent: 数值 | inherit;
阴影 text-shadow:数值;

(8) border(边框)

边框样式 border-style: dotted;(点线) dashed;(虚线) solid; double;(双线) groove;(槽线) ridge;(脊状) inset;(凹陷) outset;
边框宽度 border-width: ;
边框颜色 border-color: top值 right值 bottom值 left值;
简写 border: width style color;

  1. 边  框 {border:border-width border-style color}
  2. {border-top:border-top-width border-style color}
  3. {border-right:border-right-width border-style color}
  4. {border-bottom:border-bottom-width border-style color}
  5. {border-left:border-left-width border-style color}

(9) list-style(列表样式)

类型 list-style-type: disc | circle | square | decimal | lower-roman | upper-roman | lower-alpha | upper-alpha | none;

  1. list-style-type:none; /*不编号*/
  2. list-style-type:decimal; /*阿拉伯数字*/
  3. list-style-type:lower-roman; /*小写罗马数字*/
  4. list-style-type:upper-roman; /*大写罗马数字*/
  5. list-style-type:lower-alpha; /*小写英文字母*/
  6. list-style-type:upper-alpha; /*大写英文字母*/
  7. list-style-type:disc; /*实心圆形符号*/
  8. list-style-type:circle; /*空心圆形符号*/
  9. list-style-type:square; /*实心方形符号*/

位置 list-style-position: outside | inside;
图像 list-style-image: URL;
简写 list-style:目录样式类型 | 目录样式位置 | url;

(10) margin(边界)

margin-top:10px; (上边界)
margin-right:10px; (右边界)
margin-bottom:10px; (下边界值)
margin-left:10px; (左边界值)
margin-inside:;
margin-outside:;

(11) padding(填充)

  1. padding-top:10px; /*上边框留空白*/
  2. padding-right:10px; /*右边框留空白*/
  3. padding-bottom:10px; /*下边框留空白*/
  4. padding-left:10px; /*左边框留空白

(12) vertical(垂直)

  1. vertical-align:sub; /*下标字*/
  2. vertical-align:super; /*上标字*/
  3. vertical-align:top; /*垂直向上对齐*/
  4. vertical-align:bottom; /*垂直向下对齐*/
  5. vertical-align:middle; /*垂直居中对齐*/
  6. vertical-align:text-top; /*文字垂直向上对齐*/
  7. vertical-align:text-bottom; /*文字垂直向下对齐*/

(13) a(链接)

  1. a /*所有超链接*/
  2. a:link /*超链接文字格式*/
  3. a:visited /*浏览过的链接文字格式*/
  4. a:active /*按下链接的格式*/
  5. a:hover /*鼠标转到链接*/

(14) cursor(光标)

光标形状 cursor:hand | crosshair | text | wait | move | help | e-resize | nw-resize | w-resize | s-resize | se-resize | sw-resize;

  1. /*也可以自定义*/
  2. cursor: hand; /*链接手指*/
  3. cursor: crosshair /*十字体 */
  4. cursor: s-resize /*箭头朝下 */
  5. cursor: move /*十字箭头, 朝右*/
  6. cursor: help /*加一问号 */
  7. cursor: w-resize /*箭头朝左 */
  8. cursor: n-resize /*箭头朝上 */
  9. cursor: ne-resize /*箭头朝右上 */
  10. cursor: nw-resize /*箭头朝左上 */
  11. cursor: text /*文字型*/
  12. cursor: se-resize /*箭头斜右下 */
  13. cursor: sw-resize /*箭头斜左下*/
  14. cursor: wait /*漏斗*/

二、css实践

(1) css的三种写法

行内样式:写在对应标签的style属性里面

  1. <html>
  2. <head>
  3. <title>Test</title>
  4. </head>
  5. <body>
  6. <div style='123</div>
  7. </body>
  8. </html>

内页样式:写在HTML页面里面的style标签里面

  1. <html>
  2. <head>
  3. <title>Test</title>
  4. <style>
  5. .logo{
  6. background-color:red;
  7. }
  8. </style>
  9. </head>
  10. <body>
  11. <div class='logo'>123</div>
  12. </body>
  13. </html>

外部样式:通过link标签引入CSS样式

  1. <html>
  2. <head>
  3. <title>Test</title>
  4. <link rel='stylesheet' href='common1.css'/>
  5. </head>
  6. <body>
  7. <div class="logo">123</div>
  8. </body>
  9. </html>
  1. .logo {
  2. background-color: red;
  3. color: white;
  4. }

(2) 常规用例

  1. p {font-family: "sans serif";} /*值为若干单词,则要给值加引号*/
  2. .logo {background-color: red;}
  3. .logo a,.logo p {background-color: red;}
  4. #morra {background-color: green;}
  5. a, div { color: red;} /*a或div都使用这个css*/
  6. a div { color: red;} /*只有a下面的div使用该css*/

注:css 对大小写不敏感。不过存在一个例外:如果涉及到与 HTML 文档一起工作的话,class 和 id 名称对大小写是敏感的。

三、Demo

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>This is a demo</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  6. <style type="text/css">
  7. body {
  8. background-color: #e1ddd9;
  9. font-size: 12px;
  10. font-family: Verdana, Arial, Helvetica, SunSans-Regular, Sans-Serif;
  11. color: #564b47;
  12. padding: 0px;
  13. margin: 0px;
  14. }
  15. #inhalt {
  16. position: absolute;
  17. height: 200px;
  18. width: 400px;
  19. margin: -100px 0px 0px -200px;
  20. top: 50%;
  21. left: 50%;
  22. text-align: center;
  23. padding: 0px;
  24. background-color: #f5f5f5;
  25. border: 1px dotted #000000;
  26. overflow: auto;
  27. }
  28. p, h1 {
  29. margin: 0px;
  30. padding: 10px;
  31. }
  32. h1 {
  33. font-size: 11px;
  34. text-transform: uppercase;
  35. text-align: center;
  36. color: #564b47;
  37. background-color: #90897a;
  38. }
  39. a {
  40. color: #ff66cc;
  41. font-size: 11px;
  42. background-color: transparent;
  43. text-decoration: none;
  44. }
  45. </style>
  46. </head>
  47. <body>
  48. <div id="inhalt">
  49. <p>
  50. <h1>Morra's Demo</h1><br/><br/>
  51. This area should be horizontally and vertically centered.<br/>
  52. This text stays left aligned<br/>
  53. <a href="http://www.cnblogs.com/whatisfantasy/">what is fantasy?</a>
  54. </p>
  55. <p>
  56. </div>
  57. </body>
  58. </html>

常用css属性的更多相关文章

  1. css基础--常用css属性02

    上篇地址:css基础--常用css属性01 本文参考菜鸟教程和w3school 1  浮动和清除浮动 在上篇的第十一节--定位中说道: CSS 有三种基本的定位机制:普通流.浮动和绝对定位. 普通流和 ...

  2. html5--6-59 其他常用CSS属性

    html5--6-59 其他常用CSS属性 实例 学习要点 了解opacity属性:透明度设定 了解cursor属性:自定义鼠标样式 了解CSS新单位rem和em的区别 了解轮廓outline的设置 ...

  3. 常用css属性记录

    CSS常用属性: 字体属性:(font)大小 font-size: x-large;(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD样式 font-style: ...

  4. 常用css属性拓展

    text-overflow:clip | ellipsis(默认值:clip)clip:当内联内容溢出块容器时,将溢出部分裁切掉.ellipsis:当内联内容溢出块容器时,将溢出部分替换为(...). ...

  5. day 40 文本属性 常用css属性 定位

    一. 浮动的特性 1.浮动的元素脱标 2.浮动的元素互相贴靠 3.浮动的元素由"字围"效果 4.收缩的效果 前提是标准文档流,margin的垂直方向会出现塌陷问题. 如果盒子居中: ...

  6. 界面设计常用CSS属性

    CSS常用属性整理: 1 字体属性 font-family 设置使用的字体 font-style 设置字体的样式,是否斜体 font-variant 设置字体的大小写 font-weight 设置字体 ...

  7. css基础--常用css属性01

    1  背景相关 背景颜色 background-color     = 颜色名称/rgb值/十六进制值 背景图片 background-image = url('') 背景图片平铺方式 backgro ...

  8. 常用css属性总结

    边框修饰:border------>top,bottom,left,right上下左右边框 分为:color,类型style{ groove,dashed,ridge,solid}一个值---- ...

  9. css属性(常用属性整理)

    摘要:本文是我在学习前端的过程中整理的一些常用css属性,部分是css3新增的,因能力有限,文中如有错误,欢迎提出,我会及时修改.希望对大家有帮助! CSS属性 CSS属性 1 1. css颜色属性 ...

随机推荐

  1. 严苛模式 strictmode

    参考链接 http://blog.csdn.net/brokge/article/details/8543145 一.严苛模式-虚拟机策略 虚拟机策略(VmPolicy)能检查内存泄漏,譬如,当关闭一 ...

  2. Python访问MongoDB,并且转换成Dataframe

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/7/13 11:10 # @Author : baoshan # @Site ...

  3. pom.xml文件详解

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  4. 导出不带.svn的文件夹或者是不含.class的文件

    转载自:http://blog.csdn.net/z278718149/article/details/21537395 如何导出不带.svn的文件夹或者是不含.class的文件 在工作环境中,有的时 ...

  5. ssh-remote-port-forwarding

    1.ssh免密码登录(A登录到B) 1.1.在A上执行并在~/.ssh下生成id_rsa和id_rsa.pub两个文件 ssh-keygen -t rsa -P '' 1.2.拷贝id_rsa.pub ...

  6. ( 转 )超级惊艳 10款HTML5动画特效推荐

    今天我们要来推荐10款超级惊艳的HTML5动画特效,有一些是基于CSS3和jQuery的,比较实用,特别是前几个HTML5动画,简直酷毙了,现在将它们分享给大家,也许你能用到这些HTML5动画和jQu ...

  7. 网络协议TCP/IP、IPX/SPX、NETBEUI简介

    网络中不同的工作站,服务器之间能传输数据,源于协议的存在.随着网络的发展,不同的开发商开发了不同的通信方式.为了使通信成功可靠,网络中的所有主机都必须使用同一语言,不能带有方言.因而必须开发严格的标准 ...

  8. Tip 18 – How to decide on a lifetime for your ObjectContext

    Alex D James 7 May 2009 3:44 PM One of the most common questions we get is how long should an Object ...

  9. python进行数据分析

    1.  python进行数据分析----线性回归 2. python进行数据分析------相关分析 3. python进行数据分析---python3卡方 4. 多重响应分析,多选题二分法思路 5. ...

  10. iLBC

    iLBC是一种专为包交换网络通信设计的编解码,优于目前流行的G.729.G.723.1,对丢包进行了特有处理,即使在丢包率 相当高的网络环境下,仍可获得非常清晰的语音效果.