Heim  >  Artikel  >  Web-Frontend  >  CSS 指定选择器(十一)_html/css_WEB-ITnose

CSS 指定选择器(十一)_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:46:001059Durchsuche

一、指定选择器

有时个会希望控制某个元素在一定范围内的对象样式,这时就可以把元素与Class或者Id选择器结合起来使用

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>指定选择器</title><style type="text/css">span.red{    color:red;}div#top{    color:blue;    }</style></head><body><span class="red">这是个SPAN类名为CLASS</span><span>这是个SPAN</span><div id="top">这是个DIVID是TOP</div><div >这是个DIV</div></body></html>

指定选择器对象定义样式限定为class或者id属性的某种元素非常有用,它对元素的控制精度介于标签选择器与id或者类选择器之间,是一种非常实用的选择器类型

如下面模块中如何控制新闻的正文

<div><h2 class="news">新闻标题</h2><p class="news">新闻正文</p><span class="news">新闻说明</span><p>其它文件信息</p></div>

css

div p.news{    font-size:18px;    color:#FF00FF;    }

或者

p.news{    font-size:18px;    color:#00FFFF;    }

 

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn