CSS一---选择器

一:规范

实现结构(html)、样式(css)、行为的分离(js)

二:css在html中的声明

如果直接写css

<style type="text/css">
p{font-size:9pt;}
</style>
如果链接css文件

<link rel="stylesheet" id="css_widthauto" type="text/css" href="mystyle.css" />

三:选择器

1:类选择器

选择元素.类名

html文件

<h1 class="center">
This heading will be center-aligned
</h1>
<p class="center">
This paragraph will also be center-aligned.
</p>
css文件
h1.center {
	color: #f60;
	background: #666;
}
2:id选择器

选择元素#id值

html文件

<p id="red">这个段落是红色。</p>
<p id="green">这个段落是绿色。</p>
css文件

#red {color:red;}
#green {color:green;}
3:派生选择器

html文件

<h1 class="center">
<strong class="a"> This heading will be center-aligned</strong>
</h1>

<p class="left">
<strong class="a">This paragraph will also be center-aligned.</strong>
</p>
css文件

h1.center strong.a {
	color: #f60;
	background: #666;
}
4:属性选择器

input[type="text"]
{
  width:150px;
  display:block;
  margin-bottom:10px;
  background-color:yellow;
  font-family: Verdana, Arial;
}
注:font-family是对字体的列举,各种浏览器会按各自的优先级来选取字体

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值