Home > Web Front-end > HTML Tutorial > 元素多个类名,应该采用哪个呢_html/css_WEB-ITnose

元素多个类名,应该采用哪个呢_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 09:45:02
Original
1433 people have browsed it

CSS HTML


  ...
  ...
  ...

  
  上面div有2个类名,
   在CSS中,如果同时存在
   #class1
  {
    font-weight:bold;   ...
  }

  #class2
  {
    font-weight:normal;   ...
  }
   且有2个相同属性时,会匹配哪个属性呢

回复讨论(解决方案)

按定义的先后顺序,也就是class2中的font-weight:normal; 会被应用

<!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">.a{	background-color:#f00;}.b{	background-color:#ddd;	}</style></head><body><div class="b a">处档大</div></body></html>
Copy after login

网页中的定义(a)优于外部连接的定义(style.css中的a).元素属性(ele )的定义优于style中的定义

一般一个元素有两个class,两个class都会用上,如果有冲突,采取后面的那个,也就是class2

以后这样的情况  一试便知

一看就知道 用了那个

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template