如何将 HTML div 的背景设为黑色?

B. *_*non 0 html css jquery visual-studio webmatrix-3

我将存储在磁盘上的一些 HTML 动态加载到 div 中,如下所示:

$('#FictionContent').load('Content/HuckFinn.html');
Run Code Online (Sandbox Code Playgroud)

给出一些背景:

    $(document).ready(function () {
            $('#tabs').tabs({
                beforeActivate: function(event, ui) {
                    if (ui.newTab.index() == 0) { // index 0 is fiction
                        $('#body').removeClass('bronzeBackground silverBackground goldBackground').addClass
('bronzeBackground');
                        $('#FictionContent').load('Content/HuckFinn.html');
Run Code Online (Sandbox Code Playgroud)

FictionContent 定义如下:

<div id="FictionContent" class="clearfix">Content in Fiction tab</div>
Run Code Online (Sandbox Code Playgroud)

这是有一些背景的:

<div id="tabs" class="content-wrapper">
<ul>
    <li><a href="#tab-Fiction">Fiction</a></li>
    <li><a href="#tab-Nonfiction">Nonfiction</a></li>
    <li><a href="#tab-MiscTwain">Miscellaneous</a></li>
</ul>
<div id="tab-Fiction">
    <select id="fictionDropDown">
        <option value="HuckFinn">Huck Finn</option>
        <option value="TomSawyer">Tom Sawyer</option>
        <option value="tPatP">Prince and the Pauper</option>
        <option value="ConnYank">Connecticut Yankee</option>
        <option value="Gilded">The Gilded Age</option>
        <option value="Puddnhead">Pudd'nhead Wilson</option>
        <option value="ShortStories">Short Stories</option>
    </select>
    <div id="FictionContent" class="clearfix">Content in Fiction tab</div>
</div>
Run Code Online (Sandbox Code Playgroud)

FictionContent 使用的clearfix CSS 类在 Site.css 中是这样的:

.clearfix:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}
Run Code Online (Sandbox Code Playgroud)

我添加了这个:

background-color: black;
Run Code Online (Sandbox Code Playgroud)

...但无济于事 - 没有改变背景颜色。

我还尝试将其添加到我正在加载的 HTML 文件 (HuckFinn.html) 的顶部:

<style>
    background-color: black;
</style>
<h1>The Adventures of Huckleberry Finn</h1>
Run Code Online (Sandbox Code Playgroud)

结合一些上下文:

<style>
    background-color: black;
</style>
<h1>The Adventures of Huckleberry Finn</h1>

<h3>Scene:  The Mississippi Valley Time:  Forty to fifty years ago</h3>
. . .
Run Code Online (Sandbox Code Playgroud)

这也行不通。

那么我怎样才能使背景变黑,就像我在这里所做的那样:

小智 5

在第一次尝试中,您将 css 添加到了伪元素(请参阅http://www.w3schools.com/css/css_pseudo_elements.asp)。另外 2 次使用 <style> 的尝试并没有什么特别的效果。使用

#FictionContent {
  background: black;
}
Run Code Online (Sandbox Code Playgroud)

附加到您的 CSS 文件,使其看起来像这样:

.clearfix:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0;
}

#FictionContent {
 background: black;
}
Run Code Online (Sandbox Code Playgroud)