/    Sign up×
Community /Pin to ProfileBookmark

Why am I getting about 5px whitespace

As my subject says, I’m getting a scroll bar and about 5px of white space.

hero.jpg is a large file. 1500×900

“`
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Document</title>
<link rel=”stylesheet” type=”text/css” href=”<?php echo $baseURL; ?>/CSS/main.css”>
</head>
<body>

<div class=”container”>
<img src=”Images/logo.png” class=”logo”>
<div class=”banner”>
<ul>
<li>Join</li>
</ul>
</div>

<div class=”subMenu”>
<ul>
<li> <a href=”#”>Home</a> </li>
<li> <a href=”#”>Link2</a> </li>
<li> <a href=”#”>Link3</a> </li>
<li> <a href=”#”>Link4</a> </li>
<li> <a href=”#”>Link5</a> </li>
</ul>
</div>

<div class=”heroImage”>
<img src=”Images/Hero.jpg” alt=””>

</div>

</div>

</body>
</html>
“`

“`
@import url(‘https://fonts.googleapis.com/css2?family=Montserrat&display=swap’);

*{
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: ‘Montserrat’, sans-serif;
}

.container{
display: grid;
grid-gap: 0;
grid-template-rows: 42px 82px auto 100px;
grid-template-columns: 100px 300px auto 100px 100px;
min-height: 100vh;
}

.banner{
grid-row: 1 / 2;
grid-column: 1 / 6;
background: rgb(0, 0, 0);
display: grid;
grid-template-columns: 400px auto 300px;
}

.banner ul{
grid-column: 2 /3;
}

.banner ul li{
list-style: none;
color: #FFF;
line-height: 42px;
margin-left: 2em;
font-size: 0.8em;
}

.logo{
grid-row: 1;
grid-column: 2;
z-index: 9;
overflow: hidden;

}

.heroImage{
grid-row: 2/5;
grid-column: 1 / 6;
position: relative;
z-index: -1;
}

.heroImage img{
width: 100%;
height: calc(100vh – 42px);
object-fit: cover;
}

.heroImage::after{
position: absolute;
content: ”;
top:0;
left:0;
width: 100%;
height: 100%;
background: rgba(138, 138, 138, 0.35);
}

.subMenu{
grid-row: 2/3;
grid-column: 3/4;
display: flex;
justify-content: center;
}

.subMenu ul li{
list-style: none;
line-height: 82px;
display: inline-block;
margin: 0 20px;
}
.subMenu ul li a{
text-decoration: none;
text-transform: uppercase;
list-style: none;
text-align: center;
font-weight: 400;
color: rgb(255, 255, 255);
letter-spacing: 2px;
}
“`

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumDec 13.2020 — The reason is that the default value for `vertical-align</C> is <C>baseline</C>, this makes the small gap at the bottom. Set it to <C>top` and the gap will disappear:
.heroImage img {
width: 100%;
height: calc(100vh - 42px);
object-fit: cover;
vertical-align: top;
}
Copy linkTweet thisAlerts:
@SempervivumDec 13.2020 — PS: Another way to fix this is letting grid layout do the job of calculation the height of the image: Set height to 100%:
.heroImage img {
width: 100%;
height: 100%;
object-fit: cover;
}
Copy linkTweet thisAlerts:
@siddhi_patelDec 21.2020 — Hello...

This way is easy to solve your question
``<i>
</i>.hero img{
width:100%;
height: 100%;
object-fit:cover;
}<i>
</i>
``
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...