class =“”做什么?

时间:2011-04-19 17:08:17

标签: html css class

如果引号之间没有引用任何内容,那么class =“”会怎么做?

它来自http://careers.stackoverflow.com/

的HTML
<a class="" href="/cv>my profile</a>

我正在试图弄清楚如何在灰色按钮后面创建纹理。

image from navigation menu careers.stackoverflow.com

11 个答案:

答案 0 :(得分:4)

这意味着它没有课程。实际上,它等同于根本没有class属性。

也就是说, may 已被明确定义为空,因为生成链接的服务器端代码不会向引号之间的class属性输出任何内容。

  

我正在试图弄清楚如何在灰色按钮后面创建纹理。

那只是一张背景图片。

答案 1 :(得分:3)

他们没有从class =“”变成灰色。只要忽略它甚至不在那里。

这是灰色的:

#header > #nav-container > ul.careers > li > a {
color: white;
background: #9C9C9C url(/Content/Img/header-nav-bg.png) repeat-x;
border-right: 1px solid #939393;
border-left: 1px solid #939393;
padding: 3px 10px;
}

转换为列表下的列表项下的链接,类名为“careers”,位于id“nav-container”的元素下,该元素位于id为“header”的元素下

答案 2 :(得分:2)

没有

根据chrome,规则来自

#header > #nav-container > ul.careers > li > a {
 color: #fff;
 background: #9c9c9c url(/Content/Img/header-nav-bg.png) repeat-x;
 border-right: 1px solid #939393;
 border-left: 1px solid #939393;
 padding: 3px 10px;
}

答案 3 :(得分:1)

它可能没有做任何事情并且可以安全地删除,除非JavaScript依赖于className属性一直具有非空值,我怀疑。

答案 4 :(得分:1)

它没有做任何事情。没有定义类。如果删除它将没有区别,除非存在依赖于存在的类属性的javascript。如果是这样,javascript可能会在null对象上中断。

它存在的另一个可能原因是它是由webapp,cms或其他任何东西生成的。

答案 5 :(得分:1)

将类设置为空字符串不会对元素应用任何类。

如果要为按钮设置样式,则需要以下内容:

.stripes {
   display: block;
   padding: 2px;
   background: url(/path/to/stripy/background.gif) repeat-x 0 0;
   width: 30px;
   height: 10px;
}

然后你将条带类应用于锚元素。

<a class="stripes" href="/">linky</a>

答案 6 :(得分:1)

它什么都不做。可能是CMS的残余。

以下是Chrome在该灰色按钮上查看样式的方式。

  background-attachment: scroll;
  background-clip: border-box;
  background-color: #9C9C9C;
  background-image: url(http://careers.stackoverflow.com/Content/Img/header-nav-bg.png);
  background-origin: padding-box;
  border-bottom-width: 0px;
  border-left-color: #939393;
  border-left-style: solid;
  border-left-width: 1px;
  border-right-color: #939393;
  border-right-style: solid;
  border-right-width: 1px;
  border-top-width: 0px;
  clear: none;
  color: white;
  cursor: pointer;
  display: inline;
  float: none;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 13px;
  height: 0px;
  line-height: 18px;
  list-style-image: none;
  list-style-position: outside;
  list-style-type: none;
  margin-bottom: 0px;
  margin-left: 0px;
  margin-right: 0px;
  margin-top: 0px;
  padding-bottom: 3px;
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 3px;
  text-align: left;
  text-decoration: none;
  vertical-align: baseline;
  white-space: nowrap;
  width: 0px;
  zoom: 1;

答案 7 :(得分:1)

没什么!如果你输入一个空值并不重要。 在这种情况下(按钮'我的个人资料')有一个css表达式可以产生这种效果:

#header > #nav-container > ul.careers > li > a {
  /*properties like color, size, background, etc...*/
}

这些'&gt;'用于遵循层次结构。例如:

#div > a {
  color:blue;
  /*put your background*/    
}

导致:

<a>Nothing happens</a>
<div>
 <a>I'm blue</a>
</div>

答案 8 :(得分:0)

确保“class”为空;)

答案 9 :(得分:0)

它绝对没有:)他们通过选择元素本身来添加样式,例如:

#header > #nav-container > ul.careers > li > a {background:grey};

答案 10 :(得分:0)

它没有做任何事情,但所有先前分配的样式都保持不变。

相关问题