I'm trying to improve my css and html skills as a new frontend developer by mimicking canva. Here is my code:
.content {
height: calc(100vh - 7.2rem);
overflow: scroll;
flex: 0 1 80%;
align-self: stretch;
background-color: #00DBDE;
background-image: linear-gradient(90deg, #00DBDE 0%, #FC00FF 100%);
display: flex;
flex-direction: column;
}
.search-field {
position: relative;
z-index: 1;
width: 99%;
// width: 99rem;
height: 34.4rem;
border-radius: .8rem;
margin: 3rem auto;
overflow: hidden;
&__bg {
width: 100%;
height: calc(100% + 30vh);
position: absolute;
top: 0;
left: 0;
z-index: 0;
background-image: url(https://banner-static.canva.com/images/c4878dcc-0e7e-453f-adee-4c60971feb3d_20200523-DeskSpaceMint-Global-Desktop-2x.jpg);
background-size: cover;
background-position: 50%;
}
&__front {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
//test
position: absolute;
top: 0;
left: 0;
z-index: 2;
}
&__heading {
font-size: 4.8rem;
font-weight: 700;
}
&__input {}
&__link {
display: block;
}
}
<section class="content">
<div class="search-field">
<div class="search-field__bg"></div>
<div class="search-field__front">
<h2 class="search-field__heading">Design anything.</h2>
<input type="search" class="search-field__input" placeholder='Try "Card"'>
<svg class="navbar__icon-size-small">
<use href="/img/svg/sprites.svg#icon-down-arrow"></use>
</svg>
</div>
</div>
<div class="test">
list of items...
</div>
</section>
The question is why does my div.search-field
disappears even though I have manually set it's height to 34.4rem
and width to 99%
. I have checked the google chrome developer tools by finding that its computed height somehow becomes 0
.
If you want a complete copy of my project, please see Codepen. You might note that there are some imgs and svgs missing because I don't know how to uploaded local imgs to Codepen. The website is hosted on Netlify. Much appreciated if you would spend some time on spotting these bugs.