html - Two divs, one scrolls, other static -
i'm creating blog website top part displaying recent posts, , below part displays blog posts. have recent posts along side div show popular posts, social icons, etc. want happen have sidebar stay static alongside recent posts, , have recent posts scrollable. code have causes sidebar disappear. when take section out debug along css, works perfectly. when put together, sidebar disappears again.
here relevant code works itself:
/* relevant css */ .wrapper { position: relative; width: 100%; height: 100%; margin: auto; padding: 0; } .maincontent { top: 0; left: 0; width: 80%; height: 100%; } .sidebar { position: fixed; float: right; /*top: 200px;*/ left: 80%; width: 20%; height: 100%; z-index: 999; padding: 5px; } /* ============================================================================= index > recent posts ============================================================================= */ .description { text-align: justify; } .items .item .category2 { position: relative; margin-top: -10px; z-index: 2; margin-bottom: 20px; font: bold 18px/21px 'proxima_novasemibold'; } .items .item .category2 { display: inline-block; background: #b9b9c8; text-transform: uppercase; letter-spacing: 1px; padding: 0 10px; text-decoration: none; } .items .item .category2 a:hover { color: #ffff00; text-decoration: none; } .social li a:hover { color: #ffff00; } .social { text-align: center; padding-left: 0; margin-left: -5px; list-style: none; } .socialheading { font-weight: bold; display: inline-block; letter-spacing: -2px; padding-right: 15px; } .social>li { display: inline-block; padding-right: 1px; padding-left: 1px; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" /> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <!-- relevant html --> <div class="wrapper"> <div class="w3-row-padding w3-container"> <div class="w3-content w3-col l9 maincontent"> <div class="w3-row-padding w3-panel" onclick="javascript:window.location.href=''"> <div class="items"> <div class="w3-col l5"> <div class="item"> <div class="image"> <a href="post.php?id=3&title=fightlikeagirl"><img src="http://via.placeholder.com/350x150" class="w3-image"></a> </div> <div class="category2"> <a href="#">wellness</a> </div> </div> </div> <div class="w3-col l7"> <h3>title</h3> <p class="description">lorem ipsum dolor sit amet, consectetur adipiscing elit. phasellus condimentum sed arcu vel dignissim. cras fermentum ullamcorper libero, non finibus ante rhoncus id. nullam condimentum ornare neque, vitae vestibulum libero dignissim ut. donec aliquam justo pretium, tempor libero vulputate, ultrices arcu</p> <p><a href="">read more</a></p> </div> </div> </div> <hr> <div class="w3-row-padding w3-panel" onclick="javascript:window.location.href=''"> <div class="items"> <div class="w3-col l5"> <div class="item"> <div class="image"> <a href="post.php?id=3&title=fightlikeagirl"><img src="http://via.placeholder.com/350x150" class="w3-image"></a> </div> <div class="category2"> <a href="#">wellness</a> </div> </div> </div> <div class="w3-col l7"> <h3>title</h3> <p class="description">lorem ipsum dolor sit amet, consectetur adipiscing elit. phasellus condimentum sed arcu vel dignissim. cras fermentum ullamcorper libero, non finibus ante rhoncus id. nullam condimentum ornare neque, vitae vestibulum libero dignissim ut. donec aliquam justo pretium, tempor libero vulputate, ultrices arcu</p> <p><a href="">read more</a></p> </div> </div> </div> <hr> </div> <div class="w3-col l3 sidebar"> <ul class="social"> <p class="socialheading">keep in touch </p> <li><a href="" target="_blank"><span class="fa fa-facebook" aria-hidden="true"></span></a></li> <li><a href="" target="_blank"><span class="fa fa-instagram" aria-hidden="true"></span></a> </li> <li><a href="" target="_blank"><span class="fa fa-twitter" aria-hidden="true"></span></a></li> <li><a href="" target="_blank"><span class="fa fa-pinterest-p" aria-hidden="true"></span></a></li> <li><a href="" target="_blank"><span class="fa fa-linkedin" aria-hidden="true"></span></a></li> <li><a href="" target="_blank"><span class="fa fa-youtube-play" aria-hidden="true"></i></a></li> </ul> <hr> <p class="socialheading">most popular posts</p> </div> </div> </div>
here codepen of put , not working.
try css sidebar
when positioned fixed make use of right:0
property instead of left:80%
, use bottom:0
css
.sidebar { position: sticky; float: right; right: 0%; width: 20%; bottom: 0; height: 50%; z-index: 999; padding: 5px; top: 0; }
style accordingly.
hope helps..
Comments
Post a Comment