作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有带背景图片的页眉,我希望页眉有相同的背景但是两次,效果应该是这样的。
为了获得底部颜色,我向一张图片添加了不透明度,例如 0.5
,但不透明度会影响标题中的所有内容,我希望文本和 Logo 不受标题横幅的不透明度影响。
/* 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>
我需要做什么才能获得预期的结果(文本不应受到不透明度的影响)?
最佳答案
在 .marketing-navbar_items
上制作一个 :before
伪代码,如所示示例。这样,它就不会影响其子级的不透明度(因为它没有任何透明度)。
/* 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;
}
<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>
关于html - 如何将两个背景图像添加到同一个标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52344610/
我是一名优秀的程序员,十分优秀!