html - 无法更改 HTML 中特定部分的背景图像

标签 html css twitter-bootstrap background-image

我对 HTML 和 CSS 还很陌生。我最近从 bootstrap 下载了一个主题,我正在尝试更改一个部分/div 的背景图像。我不仅尝试向 CSS 添加代码,而且还在我的 html 代码中包含了背景图像引用。但是我仍然无法更改背景。图像是 .jpg。

这是特定部分的 HTML 代码:

<!-- About Section -->
<section class="success" id="about" style="background-image:parallax.jpg;">
    <div class="container">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h1>About</h1>
               <!-- <img class="img-responsive" src="new.gif" alt="" align="middle" align ="center" style="margin-left:auto; margin-right:auto"> -->
                <br>
            </div>
        </div>
        <div>
            <div>
                <p align="left" style="font-family: 'Abel', sans-serif;" > Hello.</p>
            </div>
            <div class="col-lg-8 col-lg-offset-2 text-center">
                <a href="Website Resume.pdf" class="btn  btn-outline" style="font-family:'Shadows Into Light', cursive;">
                    <i style="font-family:'Shadows Into Light', cursive; text-align: center;"></i> Check Out My Resume!
                </a>
            </div>
        </div>
    </div>
</section>

这是 CSS 代码:

section.success {
    color: #000000;
    background: #ffffff;
}

#about{
    background-image: url("parallax.jpg") no-repeat center center fixed;
    background-size: cover;
    height: 300%;
    width: 100%;
}

最佳答案

请注意,您在 HTML 中编写的内联 CSS 无效,它应该是:

背景图片:url("parallax.jpg");

此外,您在样式表中编写的 CSS 无效,它应该是:

background-image: url("parallax.jpg") !important;
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;
background-size: cover;

或者

background: transparent url("parallax.jpg") no-repeat fixed center center !important;
background-size: cover;

引用:https://developer.mozilla.org/en-US/docs/Web/CSS/background-image

关于html - 无法更改 HTML 中特定部分的背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29590689/

相关文章:

html - 编写一个带有图标的搜索栏

jquery - 在 bootstrap 幻灯片中抓取 Twitter 提要

javascript - HTML:将表单字段复制到另一个表单,包括 FILE 输入字段?

javascript - JQuery:当单击图像 map 上的不同区域时关闭切换框?

html - 为什么我的背景图片不显示?

javascript - 多模态叠加

html - bootstrap-responsive 覆盖了我的 .container 宽度

javascript - 如何使用 jQuery 方法从数据 URL 上传图像?

jQuery 展开折叠定义列表 (DL) 中的所有 DT 标签

css - 如何针对 FUOC 自动测试我的 webpack 捆绑网站?