Making the upper part of a site sticky with CSS and HTML - html

I'm trying to make a sidebar and top of the page not move when you scroll (like Twitter, Facebook, etc.).
I'm only using CSS and Html.
I managed to make the side bars stay there, but the "Home" part does not work.
I tried with Position: Sticky, set overflow-x to auto for the parent, tried wrapping it into another div and self-align: flex-start, but nothing seems to be working.
Now that I put it into a smaller screen, it also looks to overlap the Side bar with the Feed, and hide the Widgets.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
--twitter-color: #50b7f5;
--twitter-background: #e6ecf0;
}
/* Sidebar Styling Starts */
.sidebarOption {
display: flex;
align-items: center;
cursor: pointer;
}
.sidebarOption .material-icons,
.fa-twitter {
padding: 20px;
}
.sidebarOption h2 {
font-weight: 800;
font-size: 20px;
margin-right: 20px;
}
.sidebarOption:hover {
background-color: var(--twitter-background);
border-radius: 30px;
color: var(--twitter-color);
transition: color 100ms ease-out;
}
.sidebarOption.active {
color: var(--twitter-color);
}
.sidebar_tweet {
width: 100%;
background-color: var(--twitter-color);
border: none;
color: white;
font-weight: 900;
border-radius: 30px;
height: 50px;
margin-top: 20px;
}
body {
display: flex;
height: 100%;
max-width: 1300px;
margin-left: auto;
margin-right: auto;
padding: 0 10px;
overflow-x: auto;
}
.sidebar {
border-right: 1px solid var(--twitter-background);
flex: 0.2;
min-width: 250px;
margin-top: 20px;
padding-left: 20px;
padding-right: 20px;
left: 0;
align-self: flex-start;
position: sticky;
top: 0;
overflow-x: auto;
}
.fa-twitter {
color: var(--twitter-color);
font-size: 30px;
}
/* Sidebar Styling Ends */
/* Feed Styling Starts */
.feed {
flex: 0.5;
border-right: 1px solid var(--twitter-background);
min-width: fit-content;
overflow-x: auto;
align-self: flex-start;
}
.feed-header {
border: 1px solid var(--twitter-background);
padding: 15px 20px;
/* I DONT KNOW HOW TO MAKE THIS STICK */
}
.feed-header h2 {
font-size: 20px;
font-weight: 800;
}
.feed::-webkit-scrollbar {
display: none;
}
.feed {
-ms-overflow-style: none;
scrollbar-width: none;
}
/* Styling Tweetbox Starts */
.tweetbox__input img {
border-radius: 50%;
height: 40px;
}
.tweetBox {
padding-bottom: 10px;
border-bottom: 8px solid var(--twitter-background);
padding-right: 10px;
}
.tweetBox form {
display: flex;
flex-direction: column;
}
.tweetbox__input {
display: flex;
padding: 20px;
}
.tweetbox__input input {
display: flex;
margin-left: 20px;
font-size: 20px;
border: none;
outline: none;
}
.tweetBox__tweetButton {
background-color: var(--twitter-color);
border: none;
color: white;
font-weight: 900;
border-radius: 30px;
width: 80px;
height: 40px;
margin-top: 20px;
margin-left: auto;
}
/* Styling Tweetbox Ends */
/* Feed Styling Ends */
/* Post Styling Starts */
.post__avatar img {
border-radius: 50%;
height: 40px;
}
.post {
display: flex;
align-items: flex-start;
border-bottom: 1px solid var(--twitter-background);
padding-bottom: 10px;
}
.post__body img {
width: 450px;
object-fit: contain;
border-radius: 20px;
}
.post__footer {
display: flex;
justify-content: space-between;
margin-top: 10px;
}
.post__badge {
font-size: 14px !important;
color: var(--twitter-color);
margin-right: 5px;
}
.post__headerSpecial {
font-weight: 600;
font-size: 12px;
color: gray;
}
.post__headerText {
font-size: 15px;
margin-bottom: 5px;
}
.post__headerDescription {
margin-bottom: 10px;
font-size: 15px;
}
.post__body {
flex: 1;
padding: 10px;
}
.post__avatar {
padding: 20px;
}
/* Post Styling Ends */
/* Widgets Styling Starts */
.widgets {
flex: 0.3;
right: 0;
right: 0;
align-self: flex-start;
position: sticky;
top: 0;
overflow-x: auto;
}
.widgest__input {
display: flex;
align-items: center;
background-color: var(--twitter-background);
padding: 10px;
border-radius: 20px;
margin-top: 10px;
margin-left: 20px;
}
.widgest__input input {
border: none;
background-color: var(--twitter-background);
outline: none;
}
.widgets__searchIcon {
color: gray;
}
.widgets__widgetContainer {
display: flex;
flex-direction: column;
margin-top: 10px;
margin-left: 20px;
padding: 20px;
background-color: #f5f8fa;
border-radius: 20px;
}
.widgets__widgetContainer h2 {
font-size: 18px;
font-weight: 800;
}
.card_container {
display: flex;
flex-direction: column;
align-items: center;
}
.card {
display: flex;
flex-direction: column;
align-items: flex-start;
width: 18rem;
}
.card img {
border-radius: 20px;
width: 18rem;
}
/* Widgets Styling Ends */
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Twiter Clone</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO+tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- Sidebar Start -->
<div class="sidebar">
<i class="fab fa-twitter "></i>
<div class="sidebarOption active ">
<span class="material-icons ">home</span>
<h2>Home</h2>
</div>
<div class="sidebarOption">
<span class="material-icons ">search</span>
<h2>Explore</h2>
</div>
<div class="sidebarOption">
<span class="material-icons ">notifications_none</span>
<h2>Notifications</h2>
</div>
<div class="sidebarOption">
<span class="material-icons ">mail_outline</span>
<h2>Message</h2>
</div>
<div class="sidebarOption">
<span class="material-icons ">bookmark_border</span>
<h2>Bookmarks</h2>
</div>
<div class="sidebarOption">
<span class="material-icons">list_alt</span>
<h2>Lists</h2>
</div>
<div class="sidebarOption">
<span class="material-icons">perm_identity</span>
<h2>Profile</h2>
</div>
<div class="sidebarOption">
<span class="material-icons">more_horiz</span>
<h2>More</h2>
</div>
<button class="sidebar_tweet">Tweet</button>
</div>
<!-- Sidebar End -->
<!-- Feed Starts -->
<div class="feed">
<div class="feed_header">
<h2>Home</h2>
</div>
<!-- Tweetbox Starts -->
<div class="tweetBox">
<form>
<div class="tweetbox__input">
<img src="https://i.pinimg.com/originals/a6/58/32/a65832155622ac173337874f02b218fb.png" alt="">
<input type="text" placeholder="What's happening">
</div>
<button class="tweetBox__tweetButton">Tweet</button>
</form>
</div>
<!-- Tweetbox Ends -->
<!-- Post Starts -->
<div class="post">
<div class="post__avatar">
<img src="https://i.pinimg.com/originals/a6/58/32/a65832155622ac173337874f02b218fb.png" alt="">
</div>
<div class="post__body">
<div class="post__header">
<div class="post__headerText">
<h3>My Name
<span class="post_headerSpecial">
<span class="material-icons post__badge"> verified </span>#myname
</span>
</h3>
</div>
<div class="post_headerDescription">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
</div>
</div>
<img src="https://i.ytimg.com/vi/bepwr1-CNRU/maxresdefault.jpg" alt="">
<div class="post__footer">
<span class="material-icons">repeat</span>
<span class="material-icons">favorite_border</span>
<span class="material-icons">publish</span>
</div>
</div>
</div>
<!-- Post Ends -->
<!-- Post Starts -->
<div class="post">
<div class="post__avatar">
<img src="https://i.pinimg.com/originals/a6/58/32/a65832155622ac173337874f02b218fb.png" alt="">
</div>
<div class="post__body">
<div class="post__header">
<div class="post__headerText">
<h3>My Name
<span class="post_headerSpecial">
<span class="material-icons post__badge"> verified </span>#myname
</span>
</h3>
</div>
<div class="post_headerDescription">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
</div>
</div>
<img src="https://i.ytimg.com/vi/bepwr1-CNRU/maxresdefault.jpg" alt="">
<div class="post__footer">
<span class="material-icons">repeat</span>
<span class="material-icons">favorite_border</span>
<span class="material-icons">publish</span>
</div>
</div>
</div>
<!-- Post Ends -->
<!-- Post Starts -->
<div class="post">
<div class="post__avatar">
<img src="https://i.pinimg.com/originals/a6/58/32/a65832155622ac173337874f02b218fb.png" alt="">
</div>
<div class="post__body">
<div class="post__header">
<div class="post__headerText">
<h3>My Name
<span class="post_headerSpecial">
<span class="material-icons post__badge"> verified </span>#myname
</span>
</h3>
</div>
<div class="post_headerDescription">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
</div>
</div>
<img src="https://i.ytimg.com/vi/bepwr1-CNRU/maxresdefault.jpg" alt="">
<div class="post__footer">
<span class="material-icons">repeat</span>
<span class="material-icons">favorite_border</span>
<span class="material-icons">publish</span>
</div>
</div>
</div>
<!-- Post Ends -->
<!-- Post Starts -->
<div class="post">
<div class="post__avatar">
<img src="https://i.pinimg.com/originals/a6/58/32/a65832155622ac173337874f02b218fb.png" alt="">
</div>
<div class="post__body">
<div class="post__header">
<div class="post__headerText">
<h3>My Name
<span class="post_headerSpecial">
<span class="material-icons post__badge"> verified </span>#myname
</span>
</h3>
</div>
<div class="post_headerDescription">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
</div>
</div>
<img src="https://i.ytimg.com/vi/bepwr1-CNRU/maxresdefault.jpg" alt="">
<div class="post__footer">
<span class="material-icons">repeat</span>
<span class="material-icons">favorite_border</span>
<span class="material-icons">publish</span>
</div>
</div>
</div>
<!-- Post Ends -->
</div>
<!-- Feed Ends -->
<!-- Widget Starts -->
<div class="widgets">
<div class="widgest__input">
<span class="material-icons widgets__searchIcon"> search </span>
<input type="text" placeholder="search Twitter">
</div>
<div class="widgets__widgetContainer">
<h2>What's happening</h2>
<div class="card_container">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="https://neilpatel.com/wp-content/uploads/2021/03/source-code_featured-image.png" alt="Card image cap">
<div class="card-body">
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>
</div>
<div class="widgets__widgetContainer">
<h2>What's happening</h2>
<div class="card_container">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="https://neilpatel.com/wp-content/uploads/2021/03/source-code_featured-image.png" alt="Card image cap">
<div class="card-body">
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>
</div>
</div>
<!-- Widget Ends -->
</body>
</html>

In your code if you remove overflow-x: auto from .feed and add
.feed_header {
position: sticky;
top: 0;
}
the 'Home' heading sticks to the top as you scroll.
Another way is to use
.feed_header {
position: fixed;
top: 0;
}
.feed {
margin-top: 16px;
}
This fixes the feed_header to the top of the screen as you scroll. The feed container then needs a bit of spacing at the top to ensure the feed_header isn't overlapping.

Remove overflow-x: auto; from .feed and add this to your css:
.feed_header, .tweetBox {
position: sticky;
top: 0;
}

Please insert the following code and make changes to your classes as well.
change from .feed-header to .feed_header
.feed_header {
border: 1px solid var(--twitter-background);
padding: 15px 20px;
/* I DONT KNOW HOW TO MAKE THIS STICK */
position: fixed; /*Code to add*/
top: 0; /*Code to add*/
}

Adding on to #John's answer - sometimes you may need to specify z-index:1 to have the element always on top while scrolling. Like this:
position: -webkit-sticky; /* Safari & IE */
position: sticky;
top: 0;
z-index: 1;

Just add position: fixed for sidebar and feed header.
.feed_header, .sidebar {
position: fixed;
top: 0;
}

Related

overflow scroll not adjusting height of div

My issue:
I'm making somewhat of a Zillow clone. I need the page to not expand beyond 100% of the viewport height however, I'm making a section with the intentions of having the overflow property set to scroll. When I do this, the section expands beyond the viewport height and leaves a large whitespace at the bottom of my page. I can adjust the height to fill up to 100vh however, if I adjust the screen vertically the div with the scroll overflow doesn't adjust to the viewport height. Thanks for any and all help!
Here's a screenshot of my issue:
The circled section is the section that I need the overflow to scroll:
This is my HTML for the entire 'popup' portion:
<div class="home__popup--backdrop">
<div class="home__popup--container">
<div class="home__popup--left">
<div class="home__popup--img--container">
<div class="home__popup--img--main--container">
<img src="./src/img/home-0.jpg" alt="home-0" class="home__popup--img--main">
</div>
<div class="home__popup--img--sub--container">
<img src="./src/img/home-1.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-2.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-3.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-4.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-5.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-0.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-1.jpg" alt="home-0" class="home__popup--img--sub">
<img src="./src/img/home-2.jpg" alt="home-0" class="home__popup--img--sub">
</div>
</div>
</div>
<div class="home__popup--right">
<div class="home__popup--header--container">
<div class="home__popup--logo--container">
<div class="logo__container--home">
<img src="./src/img/logo__house.svg" alt="logo-homes" class="logo logo__homes logo__homes--small">
</div>
<div class="logo__container--txt">
<img src="./src/img/logo__txt.svg" alt="logo-homes" class="logo logo__homes logo__txt--small">
</div>
</div>
<div class="home__popup--social--container">
<div class="home__popup--social">
<img src="./src/img/like.svg" alt="logo like" class="popup__logo logo__like">
<p>Save</p>
</div>
<div class="home__popup--share">
<div class="home__popup--social">
<img src="./src/img/next.svg" alt="logo next" class="popup__logo logo__next">
<p>Share</p>
</div>
</div>
<div class="home__popup--more">
<div class="home__popup--social">
<img src="./src/img/more.svg" alt="logo more" class="popup__logo logo__more">
<p>More</p>
</div>
</div>
</div>
</div>
<div class="home__popup--details--container">
<div class="home__popup--details">
<p class="home__popup--price">$500,000</p>
<p class="home__popup--beds home__popup--details--home">3 <span>bds</span></p>
<p class="home__popup--baths home__popup--details--home">2 <span>ba</span></p>
<p class="home__popup--sqft home__popup--details--home">2,245 <span>sqft</span></p>
</div>
<div class="home__popup--address--container">
<p class="home__popup--address">
4210 sharman rd<span>,&nbsp</span>
</p>
<p class="home__popup--city">Madison<span>,&nbsp</span></p>
<p class="home__popup--state">WI</p>
</div>
<div class="home__popup--btn--container">
<button class="btn__agent">Contact Agent</button>
</div>
</div>
<div class="home__popup--overview--container">
<div class="home__popup--overview--container--links">
<img src="./src/img/001-left-arrow.svg" alt="arrow-left" class = 'arrow-small arrow-small--left'>
<div class="home__popup--overview home__popup--overview--active home__popup--overview--container--links--text--container" data-list-section = 0>
<p class="home__popup--overview--text home__popup--overview--container--links--text">Overview</p>
</div>
<div class="home__popup--facts home__popup--overview--container--links--text--container">
<p class="home__popup--facts--text home__popup--overview--container--links--text">Facts and features</p>
</div>
<div class="home__popup--value home__popup--overview--container--links--text--container">
<p class="home__popup--value--text home__popup--overview--container--links--text">Home value</p>
</div>
<div class="home__popup--history home__popup--overview--container--links--text--container" data-list-section = 1>
<p class="home__popup--history--text home__popup--overview--container--links--text">Price and tax history</p>
</div>
<div class="home__popup--monthly home__popup--overview--container--links--text--container">
<p class="home__popup--monthly--text home__popup--overview--container--links--text">Monthly cost</p>
</div>
<div class="home__popup--rental home__popup--overview--container--links--text--container">
<p class="home__popup--rental--text home__popup--overview--container--links--text">Rental Value</p>
</div>
<div class="home__popup--schools home__popup--overview--container--links--text--container" data-list-section = 2>
<p class="home__popup--schools--text home__popup--overview--container--links--text">Nearby schools</p>
</div>
<div class="home__popup--similar home__popup--overview--container--links--text--container">
<p class="home__popup--similar--text home__popup--overview--container--links--text">Similar homes</p>
</div>
<div class="home__popup--neighborhood home__popup--overview--container--links--text--container">
<p class="home__popup--neighborhood--text home__popup--overview--container--links--text">Neighborhood</p>
</div>
<div class="home__popup--homes-for-you home__popup--overview--container--links--text--container">
<p class="home__popup--homes-for-you--text home__popup--overview--container--links--text">Homes for you</p>
</div>
<img src="./src/img/002-right-arrow.svg" alt="arrow-right" class = 'arrow-small arrow-small--right'>
</div>
<div class="home__popup--scroll">
<div class="home__popup--home--detail--container">
<div class="home__popup--map--container">
<div class="test" id = "home__popup--map"></div>
</div>
<div class="home__popup--text--container">
<div class="home__popup--text--stats">
<P class="home__popup--text--header">Overview</P>
<div class="home__popup--text--user-activity">
<p class="home__popup--text--time">Time on Home Finder &nbsp<span> --</span></p>
<p class="home__popup--text--views">Views <span>64</span></p>
<p class="home__popup--text--saves">Saves <span>1</span></p>
</div>
<p class="home__popup--text--description">
No showings until 8/22 OH.....
</p>
<p class="home__popup--text--read-more">Read more</p>
</div>
<p class="home__popup--text--open-house--header">Open House</p>
<p class="home__popup--text--open-house--day">Sun, Aug 22</p>
<p class="home__popup--text--open-house--time">12:00 PM - 2:00 PM</p>
<ul class="home__popup--text--agent--container">
<li class="home__popup--text--agent">Kavita Biyani</li>
<li class="home__popup--text--agent">Nik Tantardini</li>
<li class="home__popup--text--agent">First Weber INC</li>
<li class="home__popup--text--agent">Lena Oberwetter</li>
<li class="home__popup--text--agent">Prince Michael</li>
</ul>
<div class="home__popup--overview--text">
</div>
<div class="home--popup--overview--specs">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Here's the HTML for the overflowed portion:
<div class="home__popup--scroll">
<div class="home__popup--home--detail--container">
<div class="home__popup--map--container">
<div class="test" id = "home__popup--map"></div>
</div>
<div class="home__popup--text--container">
<div class="home__popup--text--stats">
<P class="home__popup--text--header">Overview</P>
<div class="home__popup--text--user-activity">
<p class="home__popup--text--time">Time on Home Finder &nbsp<span> --</span></p>
<p class="home__popup--text--views">Views <span>64</span></p>
<p class="home__popup--text--saves">Saves <span>1</span></p>
</div>
<p class="home__popup--text--description">
No showings until 8/22 OH. Amazing opportunity ...
</p>
<p class="home__popup--text--read-more">Read more</p>
</div>
<p class="home__popup--text--open-house--header">Open House</p>
<p class="home__popup--text--open-house--day">Sun, Aug 22</p>
<p class="home__popup--text--open-house--time">12:00 PM - 2:00 PM</p>
<ul class="home__popup--text--agent--container">
<li class="home__popup--text--agent">Kavita Biyani</li>
<li class="home__popup--text--agent">Nik Tantardini</li>
<li class="home__popup--text--agent">First Weber INC</li>
<li class="home__popup--text--agent">Lena Oberwetter</li>
<li class="home__popup--text--agent">Prince Michael</li>
</ul>
<div class="home__popup--overview--text">
</div>
<div class="home--popup--overview--specs">
</div>
</div>
</div>
Here is the relevant css:
.home__popup {
&--home--detail--container {
}
&--text {
&--description{
font-size: 1.8rem;
font-weight: 300;
color: $color-grey-text;
line-height: 1.3;
}
&--user-activity{
display: flex;
margin-bottom: 2rem;
font-size: 1.4rem;
color: $color-grey-text;
& span{
color: black;
}
}
&--time{
margin-right: 2rem;
border-right: 1px solid $color-grey-medium;
& span{
font-weight: bold;
margin-right: 2rem;
}
}
&--saves{
margin-left: 2rem;
& span{
font-weight: bold;
}
}
&--views{
margin-right: 2rem;
border-right: 1px solid $color-grey-medium;
& span{
font-weight: bold;
margin-right: 2rem;
}
}
&--header {
font-size: 2rem;
font-weight: 700;
letter-spacing: 0.5px;
margin-bottom: 2rem;
}
&--container {
margin-top: 2rem;
display: flex;
flex-direction: column;
margin-left: 1rem;
}
}
&--btn {
&--container {
margin-top: 1rem;
margin-left: 1rem;
display: flex;
justify-content: space-between;
width: 100%;
position: relative;
}
}
&--address {
&--container {
display: flex;
font-weight: 300;
font-size: 1.6rem;
margin-left: 1rem;
margin-top: 1rem;
}
}
&--baths {
margin-left: 0.5rem;
}
&--beds {
margin-left: 2rem;
}
&--price {
margin-top: 3rem;
font-size: 2.5rem;
font-weight: 500;
margin-left: 1rem;
}
&--social {
cursor: pointer;
&--container {
display: flex;
align-items: center;
width: 45%;
justify-content: space-around;
}
}
&--backdrop {
width: 100vw;
height: 100vh;
z-index: 2999;
position: absolute;
top: 0;
left: 0;
backdrop-filter: blur(2px);
background-color: rgba(0, 0, 0, 0.671);
}
&--container {
position: absolute;
top: 0;
left: 50%;
height: 100vh;
width: 65vw;
background-color: white;
transform: translateX(-50%);
z-index: 3000;
backdrop-filter: blur(2px);
display: flex;
flex-direction: row;
}
&--left {
position: relative;
width: 60%;
overflow-y: scroll;
}
&--right {
width: 40%;
position: relative;
}
&--img {
&--main {
height: auto;
object-fit: cover;
width: 100%;
}
&--sub {
height: 25rem;
object-fit: cover;
width: 49.5%;
margin-bottom: 0.4rem;
&--container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
}
}
&--header {
&--container {
display: flex;
justify-content: space-between;
position: relative;
border-bottom: 1px solid #6060607a;
margin-left: 1rem;
margin-right: 1rem;
}
}
&--logo {
&--container {
display: flex;
transform: translateY(1rem);
}
&__homes {
&--small {
height: 6rem;
width: 7rem;
}
}
}
&--details {
display: flex;
align-items: flex-end;
&--container {
display: flex;
flex-direction: column;
position: relative;
}
&--home {
font-size: 1.6rem;
font-weight: 400;
& span {
border-right: 1px solid $color-grey-text;
padding-right: 0.5rem;
font-weight: 300;
}
}
}
&--sqft {
margin-left: 0.5rem;
& span {
border-right: none;
}
}
&--overview {
color: $color-primary;
border-bottom: 2px solid $color-primary;
&--container {
display: flex;
flex-direction: column;
position: relative;
&--links {
display: flex;
overflow-x: scroll;
font-size: 14px;
font-weight: 300;
height: 5rem;
align-items: center;
margin-top: 2rem;
border-top: 1px solid $color-grey-medium;
border-bottom: 1px solid $color-grey-medium;
margin-left: 0.5rem;
margin-right: 0.5rem;
&::-webkit-scrollbar {
display: none;
}
&--text {
margin-left: 1rem;
margin-right: 1rem;
width: max-content;
&--container {
cursor: pointer;
height: 100%;
display: flex;
align-items: center;
transition: .2s all;
&:hover {
color: $color-primary-light;
}
}
}
}
}
}
}
I was having way too many issues out of pure stubbornness of not wanting to change my css however, I finally gave in and refactored the section as a grid. I'm now able to get it to function properly. Here's what it looks like:
And here's the css for the grid-layout:
&--right {
width: 40%;
position: relative;
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: 5rem 20rem 5rem auto;
}
here's the CSS for the updated div containing the scroll bar:
&--scroll{
grid-column: 1/-1;
grid-row: 4/5;
overflow-y: scroll;
overflow-x: hidden;
}

How to center cards and remove scroll bar?

I have added 9 cards to the website I'm making and I'm having two issues.
(1) How do I center the 9 cards? As it is more to the left and not centered to the screen.
(2) How do I remove the scroll bar? It seems like the spacing between the top and bottom cards and also below the bottom cards is a lot therefore its moving down and has a scroll bar.
Website Image
<!DOCTYPE html>
<html>
<head>
<title>Discover | Sweeties</title>
<header>
<div class="header">
<nav class="navigation">
Sweeties | Popular Destinations
<div class="navbar-right">
Home
Discover
About Us
Contact
About Developer
</div>
</nav>
<style>
.navigation{
padding-top:30px;
padding-bottom:30px;
position:absolute;
top:0;
width:100%;
z-index:1001;
}
.navbar-right{
float:right;
padding-right:10%;
}
.navbar-right a{
text-decoration:none;
padding:10px;
color: #FFFFFF;
font-family:Calibri;
font-weight:900;
font-size: 25px;
}
.navbar-right a:hover{
text-decoration:underline;
}
.navbar-logo{
padding-left:10%;
font-family:Calibri;
font-size:30px;
font-weight:bold;
text-decoration:none;
color:#FFFFFF;
}
.video-container {
z-index: -100;
width:100%;
height:75%;
overflow:hidden;
position:absolute;
top:0;
left:0;
}
#video-bg{
width:100%;
}
.portfolio-section{
margin-top:50%;
}
.tagline-left{
float:left;
width:50%;
text-align:center;
}
.tagline-right{
float:right;
width:50%;
text-align:center;
}
.tagline-video{
width:75%;
}
.tagline-right-text{
position:absolute;
margin-top:9%;
text-align:center;
margin-left:17%;
font-family:Calibri;
color:#FFFFFF;
width:290px;
font-size:40px;
}
.tagline-left-text{
position:absolute;
margin-top:9%;
text-align:center;
margin-left:11%;
font-family:Calibri;
color:#fff;
width:375px;
font-size:40px;
}
</style>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
font-family: Calibri, sans-serif;
}
.background-wrap {
position: fixed;
z-index: -1001;
width: 100%;
height: 100%;
overflow: hidden;
top: 0;
left: 0;
}
#video-bg-elem {
position: absolute;
top: 0;
left: 0;
min-height: 100%;
min-width: 100%;
}
.content {
position: absolute;
width: 100%;
min-height: 100%;
z-index: 1000;
background-color: rgba(0,0,0,0.7);
}
.content h1 {
text-align: center;
font-size: 100px;
text-transform: uppercase;
font-weight: 300;
color: #fff;
padding-top: 15%;
margin-bottom: 10px;
}
.content p {
text-align: center;
font-size: 50px;
letter-spacing: 3px;
color: #aaa;
}
</style>
</head>
<body>
<div class="background-wrap">
<video id="video-bg-elem" preload="auto" autoplay="true" loop="loop" muted="muted">
<source src="Videos/beach1.mp4" type="video/mp4">
</video>
</div>
</body>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
body{
font-family: Calibri;
}
.main{
margin: 3%;
}
.card{
width: 20%;
background-color: white;
display: inline-block;
box-shadow: 2px 2px 20px black;
border-radius: 25px;
margin: 2%;
}
.image img{
width: 100%;
border-top-right-radius: 25px;
border-top-left-radius: 25px;
}
.title{
text-align: center;
padding: 20px;
}
h1{
font-size: 40px;
}
h2{
font-size: 22px;
}
.des{
padding: 3px;
text-align: center;
padding-top: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
}
button{
margin-top: 40px;
margin-bottom: 10px;
background-color: white;
border: 1px solid black;
border-radius: 100px;
padding:10px;
}
button:hover{
background-color: black;
color: white;
transition: .5s;
cursor: pointer;
}
{
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.card {
position: relative;
overflow: hidden;
}
.card img {
max-width: 100%;
transition: all 0.3s;
display: block;
width: 100%;
height: auto;
transform: scale(1.20);
}
.card:hover img {
transform: scale(1);
}
</style>
<body>
<div class="main">
<div class="card">
<div class="image">
<img src="Images/rakiraki.jpg">
</div>
<div class="title">
<h1>
Rakiraki</h1>
</div>
<div class="des">
<h2>Dive Wananavu</h2>
<button onclick="document.location='https://www.tripadvisor.com/Attraction_Review-g297568-d3850463-Reviews-Dive_Wananavu-Rakiraki_Viti_Levu.html'">Read More...</button>
</div>
</div>
<div class="card">
<div class="image">
<img src="Images/Lautoka.jpg">
</div>
<div class="title">
<h1>
Lautoka</h1>
</div>
<div class="des">
<h2>Koroyanitu National Heritage Park</h2>
<button onclick="document.location='default.asp'">Read More...</button>
</div>
</div>
<div class="card">
<div class="image">
<img src="Images/nadi.jpg">
</div>
<div class="title">
<h1>
Nadi </h1>
</div>
<div class="des">
<h2>Denarau Island</h2>
<button onclick="document.location='default.asp'">Read More...</button>
</div>
</div>
<div class="card">
<div class="image">
<img src="Images/sigatoka.jpg">
</div>
<div class="title">
<h1>
Sigatoka</h1>
</div>
<div class="des">
<h2>Sand Dunes</h2 >
<button onclick="document.location='default.asp'">Read More...</button>
</div>
</div>
<div class="card">
<div class="image">
<img src="Images/ph.jpg">
</div>
<div class="title">
<h1>
Pacific Harbour</h1>
</div>
<div class="des">
<h2>Arts Village</h2>
<button onclick="document.location='default.asp'">Read More...</button>
</div>
</div>
<div class="card">
<div class="image">
<img src="Images/suva.jpg">
</div>
<div class="title">
<h1>
Suva</h1>
</div>
<div class="des">
<h2>Museum</h2>
<button onclick="document.location='default.asp'">Read More...</button>
</div>
</div>
<div class="card">
<div class="image">
<img src="Images/Labasa.jpg">
</div>
<div class="title">
<h1>
Labasa</h1>
</div>
<div class="des">
<h2> KokoMana Vuadomo Waterfall</h2>
<button onclick="document.location='default.asp'">Read More...</button>
</div>
</div>
<div class="card">
<div class="image">
<img src="Images/savusavu.jpg">
</div>
<div class="title">
<h1>
Savusavu</h1>
</div>
<div class="des">
<h2>KokoMana Coco Farm</h2>
<button onclick="document.location='default.asp'">Read More...</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
The best approach that I would suggest is flex.
I have added some custom style to yoy existing code just to make it fine in flex.
Here is my additional css added.
.main {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
.card {
display: flex;
flex-direction: column;
}
.des {
flex-grow: 1;
justify-content: space-between;
display: flex;
flex-direction: column;
}
Your working fiddle.
.navigation {
padding-top: 30px;
padding-bottom: 30px;
/* position: absolute;
top: 0; */
width: 100%;
z-index: 1001;
}
.navbar-right {
float: right;
padding-right: 10%;
}
.navbar-right a {
text-decoration: none;
padding: 10px;
color: #ffffff;
font-family: Calibri;
font-weight: 900;
font-size: 25px;
}
.navbar-right a:hover {
text-decoration: underline;
}
.navbar-logo {
padding-left: 10%;
font-family: Calibri;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #ffffff;
}
#video-bg {
width: 100%;
}
.portfolio-section {
margin-top: 50%;
}
.tagline-left {
float: left;
width: 50%;
text-align: center;
}
.tagline-right {
float: right;
width: 50%;
text-align: center;
}
.tagline-video {
width: 75%;
}
* {
margin: 0;
padding: 0;
}
body {
font-family: Calibri, sans-serif;
}
.background-wrap {
position: fixed;
z-index: -1001;
width: 100%;
height: 100%;
overflow: hidden;
top: 0;
left: 0;
}
#video-bg-elem {
position: absolute;
top: 0;
left: 0;
min-height: 100%;
min-width: 100%;
}
.content {
position: absolute;
width: 100%;
min-height: 100%;
z-index: 1000;
background-color: rgba(0, 0, 0, 0.7);
}
.content h1 {
text-align: center;
font-size: 100px;
text-transform: uppercase;
font-weight: 300;
color: #fff;
padding-top: 15%;
margin-bottom: 10px;
}
.content p {
text-align: center;
font-size: 50px;
letter-spacing: 3px;
color: #aaa;
}
* {
margin: 0px;
padding: 0px;
}
body {
font-family: Calibri;
}
.main {
/* Commented */
/* margin: 3%; */
}
.card {
width: 20%;
background-color: white;
display: inline-block;
box-shadow: 2px 2px 20px black;
border-radius: 25px;
margin: 2%;
}
.image img {
width: 100%;
border-top-right-radius: 25px;
border-top-left-radius: 25px;
}
.title {
text-align: center;
padding: 20px;
}
h1 {
font-size: 40px;
}
h2 {
font-size: 22px;
}
.des {
padding: 3px;
text-align: center;
padding-top: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
}
button {
margin-top: 40px;
margin-bottom: 10px;
background-color: white;
border: 1px solid black;
border-radius: 100px;
padding: 10px;
}
button:hover {
background-color: black;
color: white;
transition: 0.5s;
cursor: pointer;
}
.card {
position: relative;
overflow: hidden;
}
.card img {
max-width: 100%;
transition: all 0.3s;
display: block;
width: 100%;
height: auto;
transform: scale(1.2);
}
.card:hover img {
transform: scale(1);
}
/* Custom styles */
.main {
display: flex;
flex-wrap: wrap;
justify-content: center;
width: 100%;
}
.card {
display: flex;
flex-direction: column;
}
.des {
flex-grow: 1;
justify-content: space-between;
display: flex;
flex-direction: column;
}
body {
background: cadetblue;
}
<header>
<div class="header">
<nav class="navigation">
Sweeties | Popular Destinations
<div class="navbar-right">
Home
Discover
About Us
Contact
About Developer
</div>
</nav>
</div>
</header>
<div class="background-wrap">
<video
id="video-bg-elem"
preload="auto"
autoplay="true"
loop="loop"
muted="muted"
>
<source src="https://youtu.be/ujKVJcwbpRo" type="video/mp4" />
</video>
</div>
<div class="main">
<div class="card">
<div class="image">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/RakiRaki_ramens_-_1.jpg/800px-RakiRaki_ramens_-_1.jpg"
/>
</div>
<div class="title">
<h1>
Rakiraki
</h1>
</div>
<div class="des">
<h2>Dive Wananavu</h2>
<button
onclick="document.location='https://www.tripadvisor.com/Attraction_Review-g297568-d3850463-Reviews-Dive_Wananavu-Rakiraki_Viti_Levu.html'"
>
Read More...
</button>
</div>
</div>
<div class="card">
<div class="image">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/RakiRaki_ramens_-_1.jpg/800px-RakiRaki_ramens_-_1.jpg"
/>
</div>
<div class="title">
<h1>
Lautoka
</h1>
</div>
<div class="des">
<h2>Koroyanitu National Heritage Park</h2>
<button onclick="document.location='default.asp'">
Read More...
</button>
</div>
</div>
<div class="card">
<div class="image">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/RakiRaki_ramens_-_1.jpg/800px-RakiRaki_ramens_-_1.jpg"
/>
</div>
<div class="title">
<h1>
Nadi
</h1>
</div>
<div class="des">
<h2>Denarau Island</h2>
<button onclick="document.location='default.asp'">
Read More...
</button>
</div>
</div>
<div class="card">
<div class="image">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/RakiRaki_ramens_-_1.jpg/800px-RakiRaki_ramens_-_1.jpg"
/>
</div>
<div class="title">
<h1>
Sigatoka
</h1>
</div>
<div class="des">
<h2>Sand Dunes</h2>
<button onclick="document.location='default.asp'">
Read More...
</button>
</div>
</div>
<div class="card">
<div class="image">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/RakiRaki_ramens_-_1.jpg/800px-RakiRaki_ramens_-_1.jpg"
/>
</div>
<div class="title">
<h1>
Pacific Harbour
</h1>
</div>
<div class="des">
<h2>Arts Village</h2>
<button onclick="document.location='default.asp'">
Read More...
</button>
</div>
</div>
<div class="card">
<div class="image">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/RakiRaki_ramens_-_1.jpg/800px-RakiRaki_ramens_-_1.jpg"
/>
</div>
<div class="title">
<h1>
Suva
</h1>
</div>
<div class="des">
<h2>Museum</h2>
<button onclick="document.location='default.asp'">
Read More...
</button>
</div>
</div>
<div class="card">
<div class="image">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/RakiRaki_ramens_-_1.jpg/800px-RakiRaki_ramens_-_1.jpg"
/>
</div>
<div class="title">
<h1>
Labasa
</h1>
</div>
<div class="des">
<h2>KokoMana Vuadomo Waterfall</h2>
<button onclick="document.location='default.asp'">
Read More...
</button>
</div>
</div>
<div class="card">
<div class="image">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/RakiRaki_ramens_-_1.jpg/800px-RakiRaki_ramens_-_1.jpg"
/>
</div>
<div class="title">
<h1>
Savusavu
</h1>
</div>
<div class="des">
<h2>KokoMana Coco Farm</h2>
<button onclick="document.location='default.asp'">
Read More...
</button>
</div>
</div>
</div>

How to position cards

My question is how to position these cards on my website?
https://imgur.com/a/Ompfh
It would be easy if there isn't this half circles above them.
I have tried to create parent class="cards" and class="card" for each of 3 cards.
In css:
.cards { display: flex }
.card { width: 33.33% }
And set relative position to my background and absolute position to my half-circles but I want to do it without absolute and relative positions if it's possible.
.cards {
display: flex;
}
.card {
width: 33.33%;
color: #fff;
text-align: center;
}
.card p {
min-height: 80px;
padding: 0 39px 0 39px;
}
.strategy--logo {
position: absolute;
top: 383px;
left: 607px;
width: 96px;
height: 48px;
background-color: #5a471b;
border-top-right-radius: 48px;
border-top-left-radius: 48px;
}
.strategy {
margin-top: 135px;
background-color: #5a471b;
}
.crop--marketing {
margin-top: 135px;
background-color: #9fa374;
}
.risk--mgmt {
margin-top: 135px;
background-color: #666;
}
<div class="cards">
<div class="card">
<div class="strategy">
<div class="strategy--logo">
<img src="css/images/strategy-logo.png" alt="" />
</div>
<!-- /.strategy-/-logo -->
<h2>
</h2>
<p>
</p>
</div>
<!-- /.crop-/-marketing -->
</div>
<!-- /.card -->
<div class="card">
<div class="crop--marketing">
<img src="css/images/crop-logo.png" alt="" />
<h2>
</h2>
<p>
</p>
</div>
<!-- /.crop-/-marketing -->
</div>
<!-- /.card -->
<div class="card">
<div class="risk--mgmt">
<img src="css/images/arrow-logo.png" alt="" />
<h2>
</h2>
<p>
</p>
</div>
<!-- /.risk-/-mgmt -->
</div>
<!-- /.card -->
</div>
<!-- /.cards -->
Now I'm using absolute and relative but is there another way? Because when I resize my web browser the circles go away random ...
Are you trying to achieve this?
.card {
displaY: block;
float: left;
width: 33.33%;
text-align: center;
color: white;
font-family: 'Calibri';
}
.icon {
width: 50px;
height: 25px;
/*half of width*/
margin: auto;
display: block;
border-radius: 50px 50px 0 0;
}
.fa {
margin-top: 10px;
}
.text {
padding: 25px;
}
.strategy .text,
.strategy .icon {
background-color: #5c471c;
}
.crop .text,
.crop .icon {
background-color: #a0a175;
}
.risk .text,
.risk .icon {
background-color: #666666;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet" />
<div class="card strategy">
<div class="icon">
<i class="fa fa-area-chart" aria-hidden="true"></i>
</div>
<div class="text">
Our Strategy
</div>
</div>
<div class="card crop">
<div class="icon">
<i class="fa fa-pagelines" aria-hidden="true"></i>
</div>
<div class="text">
Crop Marketing
</div>
</div>
<div class="card risk">
<div class="icon">
<i class="fa fa-arrow-down" aria-hidden="true"></i>
<i class="fa fa-arrow-up" aria-hidden="true"></i>
</div>
<div class="text">
Commodity Risk Management
</div>
</div>
Is the main problem that when you use position your layout changes its position elsewhere?
If so, to use position property is ok if you make a few changes:
CSS
.strategy--logo {
position: absolute;
/* Remove this top parameter, use transform instead */
/* top:383px; */
/* Instead your value of a left use value of 50% and transform left
and right properties like it is changed below */
/* left: 607px; */
left: 50%;
transform: translate(-50%, -100%);
width: 96px; height: 48px;
background-color: #5a471b;
border-top-right-radius: 48px;
border-top-left-radius: 48px;
}
.strategy {
/* add position relative to a parent of strategy-logo */
position: relative;
margin-top: 135px;
background-color: #5a471b;
}
Then your code will stay in the same position even if you resize the screen.

Center text on bottom of the div container

Could someone explain me how do I center my text on bottom of the div container?
<div class="container-fluid">
<header id="welcome-header" class="row">
<div id="welcome-div">
<img src="img/logo.png" alt="logo">
<h1 class="welcome-text">
<span>Hi, I'm Robert. I design & build</span>
<br>
<span class="welcome-text-animation"></span>
</h1>
<div class="hire-button">
Yes, I'm available for hire
</div>
<div class="page-scroll ">
<a href="#welcome-div">
Learn more about what i do
<br>
<i class="fa fa-chevron-down"></i>
</a>
</div>
</div>
</header>
Im trying to get "Learn more about what i do" at the bottom of "welcome-header" row.
CSS :
#welcome-div {
min-height: 100%;
position: relative;
}
.page-scroll {
}
.page-scroll a {
font-family: Sansita;
text-decoration: none;
font-size: 20px;
color: aliceblue;
}
Sorry guys u get me wrong. I want the string to stick to bottom like bottom: 0px;
http://codepen.io/anon/pen/jBLaBX
Add position: relative to #welcome-header then position: absolute; bottom: 0; left: 0; right: 0 to .page-scroll to position the element at the bottom of #welcome-header, and your text-align: center rule will center the text horizontally.
#import url('https://fonts.googleapis.com/css?family=Sansita');
#welcome-header {
width: 100%;
height: 100vh;
background-image: url(img/background.jpg);
position: relative;
}
.welcome-text,
.welcome-text-animation {
font-family: Sansita;
text-align: center;
color: aliceblue;
font-size: 50px;
padding-top: 90px;
}
.home-logo {
display: block;
text-align: center;
}
.home-logo img {
display: inline-block;
padding: 2.5%;
width: 120px;
height: 120px;
margin-left: auto;
margin-right: auto;
display: block;
}
.hire-button {
text-align: center;
padding-top: 90px;
}
.hire-button a {
font-family: Sansita;
text-decoration: none;
color: aliceblue;
font-size: 25px;
border: 2px solid #FDCD3B;
border-radius: 50px;
padding: 1.2%;
transition: all 0.2s linear;
}
.hire-button a:hover {
background-color: #FDCD3B;
color: #2A3A3F;
padding-left: 3%;
padding-right: 3%;
}
#welcome-div {}
.page-scroll {
text-align: center;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
.page-scroll a {
font-family: Sansita;
text-decoration: none;
font-size: 20px;
color: black;
}
<body>
<div class="container-fluid">
<header id="welcome-header" class="row">
<div id="welcome-div">
<img src="img/logo.png" alt="logo">
<h1 class="welcome-text">
<span>Hi, I'm Robert. I design & build</span>
<br>
<span class="welcome-text-animation"></span>
</h1>
<div class="hire-button">
Yes, I'm available for hire
</div>
<div class="page-scroll ">
<a href="#welcome-div">
Learn more about what i do
<br>
<i class="fa fa-chevron-down"></i>
</a>
</div>
</div>
</header>
<section id="about" class="row">
ABOUT CONTENT
</section>
<section id="skills" class="row">
SKILLS CONTENT
</section>
<section id="portfolio" class="row">
PORTFOLIO CONTENT
</section>
<section id="contact" class="row">
CONTACT CONTENT HERE
</section>
</div>
</body>
.page-scroll {
text-align:center;
}

How do I vertically align floated element?

What I need to achieve is to align .btn p vertically to the middle of .btn img height. Is that possible to make if the .btn p element is floated to the right? I need them to be on the same line, but when changed their displays to display: inline block; they are stacked vertically (and I don't know why).
I know that I could do it with flexbox really easily, but I need it to be supported by IE 9+ browsers, and flexbox is only partially-supported by IE 11.
html, body {
margin: 0;
padding: 0;
}
.slide1 {
background-color: lightblue;
height: 100vh;
position: relative;
text-align: center;
}
.slide1 h1 {
display: block;
width: 100%;
padding: 0;
margin: 0 auto;
position: absolute;
top: 4.75em;
}
.slider-btn {
position: absolute;
width: 100%;
bottom: 120px;
left: 50%;
transform: translateX(-50%);
text-align: center;
}
.slider-btn a {
display: inline-block;
}
.slider-btn p {
background-color: blue;
color: white;
margin: 0;
padding: 0.5em;
float: right;
}
.btn {
display: inline-block;
}
/*# sourceMappingURL=main.css.map */
<!DOCTYPE html>
<html>
<head>
<title> test </title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<section class="heading">
<div class="slide1">
<h1> Lorem Ipsum sit dolor amet </h1>
</div>
<div class="slider-btn">
<div class="btn">
<a href="http://google.com">
<img src="http://placehold.it/81x81" />
<p> Slide no. 1 </p>
</a>
</div>
<div class="btn">
<a href="http://google.com">
<img src="http://placehold.it/81x81" />
<p> Slide no. 2 </p>
</a>
</div>
<div class="btn">
<a href="http://google.com">
<img src="http://placehold.it/81x81" />
<p> Slide no. 3 </p>
</a>
</div>
</div>
</section>
</body>
</html>
You could do this:
Changes: position, vertical-align, display and HTML
CSS
html,
body {
margin: 0;
padding: 0;
}
.slide1 {
background-color: lightblue;
height: 100vh;
position: relative;
text-align: center;
}
.slide1 h1 {
display: block;
width: 100%;
padding: 0;
margin: 0 auto;
position: relative;
padding: 40px 0px;
}
.slider-btn {
position: relative;
width: 100%;
text-align: center;
}
.slider-btn a {
display: inline-block;
}
.slider-btn p {
background-color: blue;
color: white;
margin: 0;
padding: 0.5em;
display: inline-block;
vertical-align: middle;
}
.btn {
display: inline-block;
}
.btn a img{
display: inline-block;
vertical-align: middle;
}
HTML
<section class="heading">
<div class="slide1">
<h1>Lorem Ipsum sit dolor amet</h1>
<div class="slider-btn">
<div class="btn">
<a href="http://google.com">
<img src="http://placehold.it/81x81" /><p>Slide no. 1</p>
</a>
</div>
<div class="btn">
<a href="http://google.com">
<img src="http://placehold.it/81x81" /><p>Slide no. 2</p>
</a>
</div>
<div class="btn">
<a href="http://google.com">
<img src="http://placehold.it/81x81" /><p>Slide no. 3</p>
</a>
</div>
</div>
</div>
</section>
DEMO HERE