如何将两个背景图像添加到同一标头?

时间:2018-09-15 12:17:03

标签: html css html5 css3 bootstrap-4

我的标头带有背景图像,我希望标头具有相同的背景但两次,效果应该像这样。

为了获得底色,我在一张图像上添加了不透明度,例如0.5,但是这种不透明度会影响标题中的所有内容,我希望文本和徽标不受标题横幅的不透明度影响。

/* Marketing business main header */
.marketing-navbar_items {
    font-family: Helvetica Neue;
    font-size: 30px;
    font-weight: normal;
    color: #FFFFFF;
}

.marketing-main-header_banner {
    background-image: url("https://svgshare.com/i/8KR.svg");
    background-size: auto 1199px;
    background-repeat: no-repeat;
    background-position: center -250px;
    position: relative;
    height: 949px;


}
.sample {
    background-image: url("https://svgshare.com/i/8KR.svg");
    background-size: auto 1199px;
    background-repeat: no-repeat;
    background-position: center -250px;
    position: absolute;
    height: 949px;
    opacity: 0.5;


}
.marketing-main-header_details {

    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    margin-top: 30px;
}

.marketing-main-header_description p {
    font-size: 30px;
    font-family: HeaderFont;
    color: white;
    /* width: 55%; */
    text-align: center;
    margin: 50px 0px;
}

.marketing-main-header_button-primary {
    background-color: white;
    background-size: 150px 100px;
    font-size: 16px;
    border-color: transparent;
    color: #4834D4;
    font-family: Roboto Regular;
    width: 373px;
    height: 92px;

}

.marketing-main-header_button {
    margin-top: 50px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<div class="container-fluid marketing-main-header">
        <div class="marketing-main-header_banner">
        <div class="sample">
            <nav class="navbar navbar-expand-lg navbar-light">
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
                    aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                    <ul class="navbar-nav ml-auto marketing-navbar">
                        <li class="marketing-navbar_items  nav-item">
                            <a class="marketing-nav-link nav-link" href="#">Dla kogo </a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link" href="#">Agenda</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link" href="#">Prowadzacy</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class=" marketing-nav-link nav-link " href="#">Faq</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link " href="#">Kontakt</a>
                        </li>
                        <li class="marketing-navbar_items nav-item">
                            <a class="marketing-nav-link nav-link " href="#">Kompetencje</a>
                        </li>
                    </ul>
                </div>
            </nav>


            <div class="marketing-main-header_details">
                <div class="marketing-main-header_logo">
                    <img src="https://thumb.ibb.co/hPrhZp/logo_mib.png">
                </div>
                <div class="marketing-main-header_title">
                    <h1>SZKOLENIA</h1>
                </div>
                <div class="marketing-main-header_description">
                    <p>Lorem ipsum dolor sit amet, an pro dicta maiorum recusabo.</p>
                </div>
                <div class="marketing-main-header_sub-description">
                    <p>Lorem ipsum dolor sit amet, an pro dicta maiorum recusabo.</p>
                </div>

                <div class="marketing-main-header_button">
                    <button type="button" class="marketing-main-header_button-primary">Poznaj Agende</button>
                </div>
            </div>
            </div>
        </div>
    </div>

我需要做些什么才能获得预期的结果(文本不应该受到不透明度的影响)?

1 个答案:

答案 0 :(得分:2)

像显示的示例一样,在this上创建:before伪。这样,它不会影响其子级不透明度(因为它没有任何不透明度)。

.marketing-navbar_items
/* Marketing business main header */
.marketing-navbar_items {
    font-family: Helvetica Neue;
    font-size: 30px;
    font-weight: normal;
    color: #FFFFFF;
}

.marketing-main-header_banner, .marketing-main-header_banner:before {
    background-image: url("https://svgshare.com/i/8KR.svg");
    background-size: auto 1199px;
    background-repeat: no-repeat;
    background-position: center -250px;
    height: 949px;
}

.marketing-main-header_banner {
    position: relative;
}

.marketing-main-header_banner:before {
    content: "";
    display: block;
    width: 100%;
    position: absolute;
    top: 50px;
    opacity: 0.5;
}

.marketing-main-header_details {

    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    margin-top: 30px;
}

.marketing-main-header_description p {
    font-size: 30px;
    font-family: HeaderFont;
    color: white;
    /* width: 55%; */
    text-align: center;
    margin: 50px 0px;
}

.marketing-main-header_button-primary {
    background-color: white;
    background-size: 150px 100px;
    font-size: 16px;
    border-color: transparent;
    color: #4834D4;
    font-family: Roboto Regular;
    width: 373px;
    height: 92px;

}

.marketing-main-header_button {
    margin-top: 50px;
}