CSS样式和选择器

一、CSS样式:


 1.   样式分类:


        优先级   外部样式< 内部样式< 行内样式
            

  1.     行内样式:写在标签内的样式,作用为一行
  2.     内部样式:写在style标签内,作用整个页面
  3.     外部样式:单独写一个css文件,作用整个页面

        使用外部样式:
            <link rel="stylesheet" type="text/css" href="文件路径"/>

   <style>标签声明标签内为CSS
        多条样式规则
        1.多个属性间用分号分隔
        2.用冒号声明对应属性值

2. 属性

文本属性:

  •     字体、字号:

        font(缩写形式)
        font-weight(粗细) 
        font-size(大小) 
        font-family(字体)  

  •     行距、对齐等:

        line-height (行高) 
        text-align (对齐) 
        letter-spacing (字符间距)
        text-decoration (文本修饰 )
        white-space (空白处理 )


背景属性:


    background (缩写形式)
    background-color(背景色 )
    background-image(背景图 )
    background-repeat(背景图重复方式 )
    background-position(位置坐标、偏移量)

列表(li)常用属性 :

        
二、    选择器:

  •         标签选择器:根据 标签名
  •         类选择器:class属性,属性值可相同

               使用方法:.class属性值
     

   /* 类选择器 */
        .p1{
            /* 设置字体大小 */
            font-size: 26px;
        }

  •         id选择器:id属性,唯一标识符,属性值不同

            使用方法:#id属性名


        优先级:   标签选择器< 类选择器< id选择器

范围越小,优先级越高!!!

div 分块写,作用效果控制方便,层次清晰


三、案例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>样式</title>
		<!-- 内部样式 -->
		<style>
			h1{
				font-size: 44px;/* 字体大小 */
				background-color: bisque;/* 背景颜色 */
			}
			p{
				font-size: 40px;
			}
		</style>
		
		<!-- 使用 外部样式 -->
		<link rel="stylesheet" type="text/css" href="css/外部样式.css"/>
	</head>
	
	<body>
		<!-- 行内样式 -->
		<h1 style="color: plum;">昨天朱朱来啦</h1>
		<h3>是凌晨两点诶</h3>
		<hr />
		
		<!-- 文本属性 -->
		<h2><p>静夜思</p></h2>
		<!-- 下划线、上划线,删除线 -->
		<p style="text-decoration: underline;text-decoration: overline;text-decoration: line-through;">床 前明月光,</p>
		<!-- 行高 -->
		<p style="line-height: 30px;" >疑是 地上霜。</p>
		<!-- white-space: pre-wrap  啥用,没看到效果 -->
		<p  style="white-space: pre-wrap;" >举头望 明月,</p>
		<p>低头思故乡。</p>
	</body>
</html>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>行内样式</title>
		<link rel="stylesheet" type="text/css" href="../img/风格复试.css"/>
	</head>
	
	<body>
		<div class="two">
			<ul>
				 <li><a href="#">家用电器</a></li>
				 <li><a href="#">手机数码</a></li>
				 <li><a href="#" style="color: red;">日用百货</a></li>
			</ul>
		</div>
	</body>
</html>

css文件 

h3{
	font-family: 草书;
	font-size: 20px;
}

li{
	color: black;
	text-decoration: none;
	float: left;
	width: 190px;
}

p{
	color: red;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

youdabi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值