css学习笔记

css学习笔记

css可以理解为用于修饰HTML的语言

1.嵌入HTML的方法

1.1.内联定义
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>内联定义</title>
	</head>
	<body>
		<div id="div1" style="background-color: aliceblue;
							width: 300px;
							height:300px;
							position: absolute;
							top: 100px;
							left: 100px;
							border-style: solid;
							border-color: aquamarine;
							border-width: thick;">
			
		</div>
	</body>
</html>

1.2.定义内部样式块对象
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>内联定义</title>
		<!-- 定义样式块对象 -->
		<style type="text/css">
			/*可以这样注释*/
			/*标签选择器*/
			div{
				background-color:aliceblue;
				width:200px;
				height:100px;
				position:absolute;
				top:100px;
				left:100px;
				border-style:solid;
				border-color:aquamarine;
				border-width:thick;
			}
			/*id选择器*/
			#username{
				width:400px;
				height: 30px;
				border-color: black;
				border-style: solid;
				border-width: 1px;
			}
			
			/*类选择器*/
			.student{
				font-size: 12px;
				color: #FF0000;
				/*注意优先级*/
			}
		</style>
	</head>
	<body>
		<div>
		</div>
		<div id="username">
			
		</div>
		
		<font class="student">woshi</font>
	</body>
</html>

1.3.链接css文件

在同一个目录下建立css文件

#div1{
	background-color: #555500;
	width: 100px;
	height: 100px;
}

input{
	border: solid red 1px;
}

然后HTML文件如下

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="new_file.css" />
	</head>
	<body>
		<div id="div1">
			
		</div>
		<input type="button"/>
	</body>
</html>

1.4.隐藏样式
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#city{
				display: none;
                list-style-type: none;
			}
			input{
				display: none;
			}
		</style>
	</head>
	<body>
		<ul>
			<li>中国
				<ul id="city">
					<li>不显示的条目</li>
				</ul>
			</li>
		</ul>
		<ul>
			<li>中国
				<ul>
					<li>显示的条目</li>
				</ul>
			</li>
		</ul>
		<input type="text"/>
	</body>
</html>

1.5.文本装饰样式
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#z1{
				text-decoration: underline;
			}
			#z2{
				text-decoration: overline;
			}
			#z3{
				text-decoration: line-through;
			}
			#z4{
				text-decoration: blink;
			}
		</style>
	</head>
	<body>
		<div id="z1">text1</div>
		<font id="z2">text2</font>
		<span id="z3">text3</span><br />
		<a id="z4" href="rabbitttt.com">博客</a>
	</body>
</html>

1.6.设置鼠标悬停效果
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			p:hover{
				color: red;
				font-size: 10px;
			}
			
			/*冒号两边不允许空格*/
			input:hover{
				border-color: black;
			}
		</style>
	</head>
	<body>
		<p>text1</p>
		<br />
		<input type="text" />
	</body>
</html>

1.7.内补丁与外补丁
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#div{
				width: 300px;
				height: 300px;
				background-color: #555500;
				border: solid 1px red;
				/*内补丁*/
				padding-left: 200px;
				/*外补丁*/
				margin-left: 300px;
			}
		</style>
	</head>
	<body>
		<div style="
		border: solid 1px red;
		width:1000px;
		height: 1000px;">
			<div id="div">
				<div style="border: solid 1px red;
				width: 100px;
				height: 100px;">
					
				</div>
			</div>
		</div>
	</body>
</html>

1.8.浮动效果
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			img{
				float: right;
			}
		</style>
	</head>
	<body>
		<p>
			<img src="img.gif"/>
			text...
		</p>
			</body>
</html>

1.9.定位样式
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#div1{
				background-color: red;
				border: solid 1px black;
				width: 100px;
				height: 100px;
				
				/*定位*/
				position: absolute;
				top: 100px;
				left:100px;
			}
			#div1:hover{
				cursor: pointer;
				text-decoration: underline;
				color: blue;
			}
		</style>
	</head>
	<body>
		<div id="div1">
			rsdemon
		</div>
	</body>
</html>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值