CSS基础2

1.CSS中常用的属性设置

     1.1关于字体的css属性设置

          color--设置字体颜色[颜色单词/颜色码【#0000ff】]

          font-family---设置字体名称[黑体.....]

          font-size --设置字体大小【数字px】

          font-style--设置字体倾斜【normal | italic | oblique 】

          font-weight--设置字体粗细【整百的数字【100~900】】

          text-decoration--设置字体的修饰线【none || underline下划线 || overline上划线 || line-through贯穿线 】

          text-shadow--文本的文字是否有阴影及模糊效果

          text-transform--文本的大小写转换【none | capitalize | uppercase | lowercase 】

          line-height--行高【数字px】

          letter-spacing--文字之间的间隔 normal | length 【数字px】

          word-spacing--单词之间插入的空隔normal | length 【数字px】

          例如:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>关于字体的css属性设置</title>
		<style>
			p{
				color:red;
				font-family:楷体;
				font-size:30px;
				font-style:italic;
				font-weight:900;
				text-decoration:underline;
				text-transform:uppercase;
				letter-spacing:10px;
				word-spacing:20px;
				text-shadow:10px 10px 20px red;
				line-height: 30px;
			}
		</style>
	</head>
	<body>
		<h1>关于字体的css属性设置</h1>
		<h2 >color--设置字体颜色[颜色单词/颜色码【#0000ff】]</h2>
		<h2>font-family---设置字体名称[黑体.....]</h2>
		<h2>font-size --设置字体大小【数字px】</h2>
		<h2>font-style--设置字体倾斜【normal | italic | oblique 】</h2>
		<h2>font-weight--设置字体粗细【整百的数字【100~900】】</h2>
		<h2>text-decoration--设置字体的修饰线【none || underline下划线 
		|| overline上划线 || line-through贯穿线 】</h2>
		<h2>text-shadow--文本的文字是否有阴影及模糊效果</h2>
		<h3>text-shadow:10px 0px 0px red;</h3>
		<h3>第一个值:水平移动距离 0px 0px red;</h3>
		<h3>第二个值:前后移动距离 0px 0px red;</h3>
		<h3>第三个值:模糊效果</h3>
		<h3>第四个值:阴影颜色</h3>
		<h2>text-transform--文本的大小写转换【none | 
		capitalize | uppercase | lowercase 】</h2>
		<h2>line-height--行高【数字px】</h2>
		<h2>letter-spacing--文字之间的间隔 normal | length 【数字px】</h2>
		<h2>word-spacing--单词之间插入的空隔normal | length 【数字px】</h2>
		<p>测试关于字体的test css属性设置</p>
		<p>测试文字是否有阴影及模糊效果</p>
		<p>测试文字是否有阴影及模糊效果测试文字是否有阴影及模糊效果测试文字是否
		有阴影及模糊效果测试文字是否有阴影及模糊效果测试文字是否有阴影及模糊效果
		测试文字是否有阴影及模糊效果测试文字是否有阴影及模糊效果测试文字是否有阴影及模糊效果
		测试文字是否有阴影及模糊效果测试文字是否有阴影及模糊效果测试文字是否有阴影及模糊效果
		测试文字是否有阴影及模糊效果测试文字是否有阴影及模糊效果</p>
	</body>
</html>

     1.2关于文本属性设置

          text-indent :文本的缩进 length 【数字px】

          vertical-align:垂直对齐方式top  middle bottom

          text-align :水平对齐方式left | right | center

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>关于文本属性设置</title>
		<style>
			#p1{
				font-size: 20px;
				text-indent:30px;
			}
			#p2{
				font-size: 20px;
				text-indent:50px;
			}
			tr{
				text-align:right;
				vertical-align:bottom;
			}
		</style>
	</head>
	<body>
		<h1>关于文本属性设置</h1>
		<h2>text-indent :文本的缩进 length 【数字px】</h2>
		<h2>vertical-align:垂直对齐方式top  middle bottom </h2>
		<h2>text-align :水平对齐方式left | right | center </h2>
		<p id="p1">关于文本属性设置关于文本属性设置关于文本属性设置</p>
		<p id="p2">关于文本属性设置关于文本属性设置关于文本属性设置</p>
		<table border="1px" width="600px" height="200px">
			<tr>
				<td>text-align</td>
				<td>水平对齐方式left | right | center</td>
			</tr>
			<tr>
				<td>vertical-align</td>
				<td>垂直对齐方式top  middle bottom</td>
			</tr>
		</table>
	</body>
</html>

     1.3关于背景的设置

        整个网页的背景设置

          1. 整个网页的背景颜色【在body元素中设置bgcolor】

          2. 整个网页的背景图片【在body元素中设置background】

        Html元素的背景设置

          1.  Html元素的背景颜色【background-color】

          2. Html元素的背景图片【background-image:url("imgs/banner1.png");】

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>关于背景的设置</title>
		<style>
			div{
				width: 300px;
				height: 300px;
				background-color: red;
			}
			p{
				font-size: 40px;
				color: yellow;
				background-color: blue;
				
			}
			table{
				background-image:url("imgs/banner1.png");
			}
			tr{
				font-size: 20px;
				color: #FFFF00;
			}
		</style>
	</head>
	<body background="imgs/timg.jpg">
		<h1>关于背景的设置</h1>
		<h2>1. 整个网页的背景颜色【在body元素中设置bgcolor】</h2>
		<h2>2. 整个网页的背景图片【在body元素中设置background】</h2>
		<h1>关于HTML元素背景的设置</h1>
		<div></div>
		<p>关于HTML元素背景的设置--背景颜色</p>
		<table border="1px" width="600px" height="200px">
			<tr>
				<td colspan="2">关html元素的背景设置</td>
			</tr>
			<tr>
				<td>HTML元素的背景颜色</td>
				<td>background-color:颜色单词/颜色码</td>
			</tr>
			<tr>
				<td>HTML元素的背景图片</td>
				<td>background-image:url("图片路径")</td>
			</tr>
		</table>
	</body>
</html>

     1.4关于html元素的尺寸设置

          width : 设置元素的宽度 auto | length 

          height : 设置元素的高度auto | length

     1.5关于边框设置

          border-width:边框粗细

          border-style :边框样式

          border-color : 边框颜色

       上面这三个属性可以分为4组:

          border-top-color,border-right-color,border-bottom-color,border-left-color

          border-top-style,border-right-style,border-bottom-style,border-left-style

          border-top-width,border-right-width,border-bottom-width,border-left-width

       我们可以通过border属性设置4边的边框: border---粗细  样式  颜色。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>关于边框设置</title>
		<style>
			div{
				width: 200px;
				height: 200px;
				border: 10px solid red;
			}
			#img1{
				border-top-width:5px ;
				border-top-style: double;
				border-top-color: black;
				border-right-width:10px ;
				border-right-style: solid;
				border-right-color: blue;
				border-bottom-width:15px ;
				border-bottom-style: dashed;
				border-bottom-color: red;
				border-left-width:20px ;
				border-left-style: dotted;
				border-left-color: green;
			}
			#img2{
				border-top:5px double black;
				border-right:10px solid blue;
				border-bottom:15px dashed red;
				border-left:20px dotted green;
			}
		</style>
	</head>
	<body>
		<h1>关于边框设置</h1>
		<div></div>
		<br>
		<img id="img1"  src="imgs/avatar2.png" />
		<br>
		<img id="img2" src="imgs/avatar2.png" />
	</body>
</html>

     1.6 关于列表的设置

          列表--1.有序列表 <ol><li></li></ol>

                    2.无序列表 <ul><li></li></ul>

                    3.自定义列表<dl><dt><dd></dd></dt></dl>

          列表的设置就是改变一下列表的前面的标识。

            list-style-image : 设置标识图标none | url ( url )

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>关于列表的设置</title>
		<style>
			ul li a{
				font-size: 50px;
				text-decoration: none;
				color: black;
			}
			ul{
				list-style-image:url("imgs/home.PNG");
			}
		</style>
	</head>
	<body>
		<h1>关于列表的设置</h1>
		<h2>list-style-image : 设置标识图标none | url ( url ) </h2>
		<ul>
			<li><a href="#">用户信息管理</a></li>
			<li><a href="#">部门信息管理</a></li>
			<li><a href="#">职位信息管理</a></li>
		</ul>
	</body>
</html>

      1.7关于表格的设置

          border-collapse :设置表格单元格之间的边框合并[ separate | collapse相邻边被合并] 

          border-spacing :表格边框独立时,行和单元格的边在横向和纵向上的间距。 【数字px】

          empty-cells :当单元格中没有内容时,单元格的边框是否显示 show | hide

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>表格属性设置</title>
		<style>
			table{
				width: 800px;
				height: 400px;
				border-collapse:separate;
				border-spacing:10px;
				empty-cells:show;
			}
			table tr{
				font-size: 20px;
				text-align: right;
				vertical-align: bottom;
			}
			
		</style>
	</head>
	<body>
		<h1>表格属性设置</h1>
		<h2>border-collapse :设置表格单元格之间的边框合并[ separate | collapse相邻边被合并] </h2>
		<h2>border-spacing :表格边框独立时,行和单元格的边在横向和纵向上的间距。 【数字px】</h2>
		<h2>empty-cells :当单元格中没有内容时,单元格的边框是否显示 </h2>
		<table border="1px">
			<tr>
				<td colspan="3"><h1>表格属性设置</h1></td>
			</tr>
			<tr>
				<td>border-collapse</td>
				<td>设置单元格是否合并</td>
				<td>separate | collapse相邻边被合并</td>
			</tr>
			<tr>
				<td>border-spacing</td>
				<td>框独立时,单元格之间的间距</td>
				<td>数字px</td>
			</tr>
			<tr>
				<td>empty-cells</td>
				<td>当单元格中没有内容时,单元格的边框是否显示</td>
				<td></td>
			</tr>
		</table>
	</body>
</html>

      1.8关于补丁的设置

          补丁--子元素和父元素之间的距离

          如果设置的是父元素---内补丁【padding】

          如果设置的是子元素---外补丁【margin】

          padding:12px 15px  28px  35px     四个参数值,将按上-右-下-左的顺序作用于四边。

          提供一个,将用于全部的四边     padding:12px

          两个,第一个用于上-下,第二个用于左-右     padding:12px 15px

          提供三个,第一个用于上,第二个用于左-右,第三个用于下     padding:12px 15px  28px

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>补丁设置</title>
		<style>
			div{
				width: 500px;
				height: 400px;
				background-color: black;
			}
			#div1{
				padding: 50px;
			}
			#img2{
				margin: 50px;
			}
		</style>
	</head>
	<body>
		<div id="div1">
			<img id="img1" src="imgs/avatar2.png" />
		</div>
		<br>
		<div id="div2">
			<img id="img2" src="imgs/avatar5.png" />
		</div>
	</body>
</html>

2.关于布局的属性设置

     1.float:html元素是否及如何浮动【none没有 | left{左浮动} | right{右浮动} 】

        块级元素:其元素的前后会自动折行

        行内元素:按照由左向右一次排列,除非使用<br>元素强制换行。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>设置元素浮动</title>
		<style>
			span{
				float: right;
			}
			ul{
				list-style-type: none;
			}
			ul li{
				float: left;
				padding-left:50px;
			}
			ul li a{
				font-size: 30px;
				text-decoration: none;
				color: darkgrey;
			}
			ul li a:hover{
				color: red;
			}
		</style>
	</head>
	<body>
		<font size="7">设置元素浮动</font>
		<ul>
			<li><a href="http://news.baidu.com/" target="_blank">新闻</a></li>
			<li><a href="#">hao123</a></li>
			<li><a href="#">地图</a></li>
			<li><a href="#">视频</a></li>
			<li><a href="#">贴吧</a></li>
			<li><a href="#">学术</a></li>
			<li><a href="#">更多</a></li>
		</ul>
	</body>
</html>

     2.设置html元素的隐藏和显示

          display:html元素是否及如何显示

          block:显示

          none:隐藏

          visibility:是否显示html元素

          visible:显示

          hidden:隐藏

        display与visibility的区别?

          Display隐藏元素之后,元素的物理空间也会消失,

          Visibility:隐藏元素之后,元素的物理空间不会消失,会留出空白。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>设置html元素的隐藏和显示</title>
		<script>
			function test1(){
				document.getElementById("img1").style.display="none";
			}
			function test2(){
				document.getElementById("img1").style.display="block";
			}
			function testvisibility1(){
				document.getElementById("img2").style.visibility="hidden";
			}
			function testvisibility2(){
				document.getElementById("img2").style.visibility="visible";
			}
		</script>
	</head>
	<body>
		<h1>设置html元素的隐藏和显示</h1>
		<h2>display:html元素是否及如何显示</h2>
		<h3>block:显示</h3> 
		<h3>none:隐藏</h3>
		<h1 onmouseover="test1();" onmouseout="test2();">图片的隐藏和显示</h1><br>
		<img id="img1" src="imgs/avatar2.png" /><br>
		<img id="img2" src="imgs/avatar5.png" />
		<h2>visibility:是否显示html元素</h2>
		<h3>visible:显示</h3> 
		<h3>hidden:隐藏</h3>
		<h1 onmouseover="testvisibility1();" onmouseout="testvisibility2();">图片的隐藏和显示</h1><br>
	</body>
</html>

3.关于定位的属性设置

     position:设置HTML元素的定位方式

     static:默认值。无特殊定位,html元素遵循HTML定位规则

        absolute:绝对定位。脱离HTML默认的定位规则,使用left , right , top , bottom 等属性相对于其最接近的一个最有定位设置的父对象进行绝对定位。

        relative:相对定位。不脱离HTML默认的定位规则,但将依据 left , right , top , bottom 等属性在正常文档流中偏移位置

     left【左距】,right【右距】 , top【上距】 , bottom【下距】 

     必须定义 position 属性值为 absolute 或者 relative 此取值方可生效。 HTML默认的定位规则,html元素在HTML文件中按照从左上角向右下角一次排列,遇见块级元素折行。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>absolute:绝对定位</title>
		<style>
			#div1{
				width: 200px;
				height: 200px;
				background-color: black;
				position: absolute;
			}
			#div2{
				width: 200px;
				height: 200px;
				background-color: blue;
				position: absolute;
				top:1200px;
				left: 1200px;
			}
		</style>
	</head>
	<body>
		<h1>absolute:绝对定位。脱离HTML默认的定位规则</h1>
		<h1>使用left , right , top , bottom 等属性相对于其最接近的一个最有定位设置的父对象进行绝对定位</h1>
		<div id="div1"></div>
		<div id="div2"></div>
	</body>
</html>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>relative:相对定位</title>
		<style>
			#div1{
				width: 200px;
				height: 200px;
				background-color: black;
			}
			#div2{
				width: 200px;
				height: 200px;
				background-color: blue;
				position: relative;
				top:200px;
				left:200px;
			}
		</style>
	</head>
	<body>
		<h1>relative:相对定位。不脱离HTML默认的定位规则,</h1>
		<h2>但将依据 left , right , top , bottom 等属性在正常文档流中偏移位置</h2>
		<div id="div1"></div>
		<div id="div2"></div>
		
	</body>
</html>

     z-index:设置对象的层叠顺序

         较大 number 值的对象会覆盖在较小 number 值的对象之上

         注意:z-index属性是的有效性与position属性有关。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>设置元素的层叠</title>
		<style>
			#div1{
				width: 300px;
				height: 200px;
				background-color: red;
				position: absolute;
				left: 100px;
				top: 100px;
				z-index: 1;
			}
			#div2{
				width: 300px;
				height: 200px;
				background-color: blue;
				position: absolute;
				left: 150px;
				top: 160px;
				z-index: 2;
			}
			#div3{
				width: 300px;
				height: 200px;
				background-color: yellow;
				position: absolute;
				left: 200px;
				top: 220px;
				z-index: 3;
			}
			#div4{
				width: 300px;
				height: 200px;
				background-color: green;
				position: absolute;
				left: 250px;
				top: 280px;
				z-index: 4;
			}
			div p{
				font-size: 20px;
			}
		</style>
	</head>
	<body>
		<div id="div1">
			<p align="right">div1--[z-index=1]</p>
		</div>
		<div id="div2">
			<p align="right">div2--[z-index=2]</p>
		</div>
		<div id="div3">
			<p align="right">div3--[z-index=3]</p>
		</div>
		<div id="div4">
			<p align="right">div4--[z-index=4]</p>
		</div>
	</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值