我正在尝试放置submenu div和由背景制成的横幅。
问题是它们没有填充屏幕宽度。左右两侧都有小的空白。 同样在我的真实应用中,单击按钮后会出现submenu div,因此必须将其向下推。我的意思是,如果我将submenu设为绝对位置,则可以达到100%的宽度,但是横幅div的下方不被按下。 >
HTML:
<div>
<div class="subMenu"></div>
<div class="mainBanner">
<a class="mainBannerLink" href="/products/category/all" data-auto-id="true" id="gift_guide-category-minimalist-591-0">
<span class="mainBannerLinkContent">
<h1>
<span class="mainBannerTitle">Considered carry goods to<br></br>enhance your everyday</span>
</h1>
<button class="mainBannerLinkContentShopNow">
SHOP NOW
</button>
</span>
</a>
</div>
</div>
CSS:
.mainBanner{
position: relative;
padding-top: 59vh;
background-image: url(https://bellroy.imgix.net/cms_images/1912/homepage-banner-test-1-1800x660.jpg?auto=format&fit=max);
background-size: cover;
width:100%;
background-position: center center;
background-repeat: no-repeat;
cursor: pointer;
}
.mainBannerLink{
position: absolute;
display: block;
top: 0;
right: 0;
bottom: 0;
left: 0;
text-decoration: none;
z-index: 3;
}
.mainBannerLinkContent{
position: relative;
display: block;
top: 50%;
transform: translateY(-50%);
text-align: center;
}
.mainBannerLinkContentShopNow{
font-family: 'Lato', sans-serif;
-webkit-font-smoothing: antialiased;
color: #626161;
font-weight: bold;
letter-spacing: 2.5px;
font-size: 12px;
text-transform: uppercase;
padding: 0 15px;
line-height: 35px;
border: 0;
background-color: #fff;
cursor: pointer !important;
}
.mainBannerTitle{
font-family: 'Lato', sans-serif;
font-size: 55px;
font-weight: bold;
line-height: 1.3;
-webkit-font-smoothing: antialiased;
color: #7c7c7c;
margin: 0 0 30px 0;
padding: 0;
letter-spacing: 1px;
}
.subMenu{
display: flex;
position:relative;
left: 0;
width: 100%;
background: rgb(33, 49, 94);
height: 100px;
overflow: hidden;
border-top: 5px solid #eee;
opacity: 1;
z-index: 1;
}
以下是最小化问题的codepen:
https://codepen.io/anon/pen/roEQqo
Gif以获得更好的解释: https://i.imgur.com/TvPDHyE.gifv