html - CSS 内部区域

标签 html css twitter-bootstrap

我有一个关于 Bootstrap 的问题。我想知道您是否可以让 style HTML 代码在指定区域工作。我有这段代码,我希望下面的 CSS 代码只在这个 div 中工作。

HTML 代码:

<div style="position:relative;width:280px;">
    <a class="pull-left" style="position:relative; margin: 4px 5px 0 0;">
        <img class="avatar" src="https://minotar.net/avatar/mcname/32.png" player="mcname" size="32" width="32" height="32" style="width: 32px; height: 32px; vertical-align: bottom;" />
    </a>
    <a href="#" style="color: red"><b>Marcus</b></a>
    <span class="label" style="background-color: green; color: white"><a href="#" class="nounderline">Owner</a></span>
    <span class="label" style="background-color: purple; color: white"><a href="#" class="nounderline">Developer</a></span>
    <span class="label" style="background-color: #FA0; color: white"><a href="#" class="nounderline">Staff</a></span>
    <p><i>Posted Nov. 16'th, 2013</i></p>
</div>

CSS 代码:(我把它放在 style 的 HTML 代码中)

a {
    color: inherit;
}
a:hover { 
    color: white
}
a:link { 
    color: #ffffff; 
    text-decoration: none
}

EDIT:

I've tried all the answers, but strange enough, they aren't working. In my head they looked like they were right, and they must have. I can't just get it to work. When I try the answers the links all around the page fade from white to it's normal color. I just want the div with the label span's to show links as white (also with hover), and everything else on the page as normal Bootstrap links. - Even thought it doesn't work for me, thanks to you guys for trying to help me!

最佳答案

你可以给父 div 一个 id,然后引用它的子 div。一个例子:

<div id="Parent">
  <span>I should be given unique style!<span>
</div>

CSS:

#Parent span {
    /* my style goes here */
}

关于html - CSS 内部区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20105053/

相关文章:

javascript - 父级的 JQuery 比较 ('tr) and find(' tr :first') not working

javascript - 过滤器下拉 jquery 不适用于 IE,但适用于 Chrome/FF

android - 聚焦时无法设置 android 4.x 上的输入元素的样式

css - 是否可以水平居中对齐一行加起来不等于 12 的 Bootstrap 跨度?

javascript - 更改事件类以及导航丸中的内容

html - Bootstrap 列不起作用

javascript - 用于触摸屏的 HTML Canvas 帮助

html - 样式选择选项

javascript - JS在 Accordion 中隐藏嵌套列表

CSS 嵌套的第 nth-child() 行为很奇怪