对于非元素内联的样式需要定义样式选择器,通俗的说就是这个样式适合哪些元素,样式选择器有:标签选择器,class选择器,id选择器,关联选择器,组合选择器,伪选择器

1.标签选择器

对于指定标签采用统一的标签;

<head>
<style type="text/css">
input{border-color:Yellow;color:Red}
</style>
</head>
2.class选择器

以定义一个命名的样式,然后在用它的时候设定元素的class属性为样式,还可以同时设定多个class,名称之间加空格。


<head>
<style type="text/css">
.warning{background:Yellow}
.highlight{font-size:xx-large;cursor:help;}
</style>
</head>

其中.waringhe .highlight是给元素定义了名称,这个名称不作用于任何元素,除非引用它。

对该样式进行引用;


<body>
<table><tr><td class="highlight">aaa</td>
<td class="warning">keleyi.com</td>
<td class="warning highlight">ccc</td>
</tr> 
</table> 
</body>

标签+class选择器:
class选择器也可以针对不同的标签,实现同样的样式名对于不同标签有不同的形式,只要在前面加上标签名称即可。


<head> 
  <style type="text/css">    
input.accountno{text-align:right;color:Red}
    label.accountno{font-style:italic;}  
</style>
</head>

3.id选择器:为指定的id的元素设定样式。代码如下:

<head>
<style type="text/css">
#UserName{font-size:xx-large;}
</style>
</head>
在body中对该样式进行使用:

<body>
<input >柯乐义</a>
</body>

相关文章:

  • 2021-12-28
  • 2022-12-23
  • 2022-02-08
  • 2021-05-11
  • 2021-11-04
  • 2022-12-23
  • 2021-06-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
  • 2021-10-31
  • 2021-08-21
相关资源
相似解决方案