CSS常用标签及属性学习使用技巧

橘子网 4,192

颜色属性

<div style="color:blueviolet">ppppp</div> //颜色少
<div style="color:#ffee33">ppppp</div>  //百度颜色代码可以查询更多
<div style="color:rgb(255,0,0)">ppppp</div> //三原色 红绿蓝256级
<div style="color:rgba(255,0,0,0.5)">ppppp</div> //比上一个 加了一个透明度

字体属性

font-size: 20px/50%/larger; //大小
font-style:oblique; //斜体 
font-family:"Time New Roman"; //字体格式 
font-weight: lighter/bold/border/; //字体粗细 
<h1 style="font-style: oblique"></h1>

背景属性

background-color: cornflowerblue; //背景颜色
background-image: url('1.jpg'); //背景图片
background-repeat: no-repeat/repeat-x/repeat=t; //(默认铺满,不重复,x重复,y重复)
background-size:600px 250px //大小
background-position: right top20px 20px);//(横向:left center right)(纵向:top center bottom) //简写:
<body style="background: 20px 20px no-repeat #ff4 url('1.jpg')">
<div style="width: 300px;height: 300px;background: 20px 20px no-repeat #ff4 url('1.jpg')">

注意:

  • 如果将背景属性加在body上,要记得给body加上一个height,否则结果异常,这是因为body为空,无法撑起背景图片;
  • 另外,如果此时要设置一个width=100px,你也看不出效果,除非你设置出html。

文本属性

font-size: 10px; text-align: center; //横向排列 center:居中
line-height: 200px; //文本行高 通俗的讲,文字高度加上文字上下的空白区域的高度 50%:基于字体大小的百分比
vertical-align:-4px; //设置元素内容的垂直对齐方式 ,只对行内元素有效,对块级元素无效
text-indent: 150px; //首行缩进
letter-spacing: 10px; //字母间隙
 word-spacing: 20px; //单词间隙
text-transform: capitalize; //单词大写

边框属性

border-style: solid; border-color: chartreuse; border-width: 20px; //简写:
border: 30px rebeccapurple solid;

列表属性

ul,ol{ list-style: decimal-leading-zero; list-style: none; <br>
 list-style: circle; list-style: upper-alpha; list-style: disc; }

dispaly属性

none //隐藏
block //调整成块属性
inline

display:inline-block可做列表布局,其中的类似于图片间的间隙小bug可以通过如下设置解决:

#outer{  border: 3px dashed; word-spacing: -5px; }

外边距和内边

  • margin: 用于控制元素与元素之间的距离;margin的最基本用途就是控制元素周围空间的间隔,从视觉角度上达到相互隔开的目的。
  • padding: 用于控制内容与边框之间的距离;
  • Border(边框) 围绕在内边距和内容外的边框。
  • Content(内容) 盒子的内容,显示文本和图像。

元素的宽度和高度:

  • 重要: 当您指定一个CSS元素的宽度和高度属性时,你只是设置内容区域的宽度和高度。要知道,完全大小的元素,你还必须添加填充,边框和边距。
    margin:10px 5px 15px 20px;-----------上   
  • margin:10px 5px 15px;----------------上 右左 
  • margin:10px 5px;---------------------上下 右左
  • margin:10px; ---------------------上右下左

上一篇:

下一篇:

相关阅读

分享