Hello,
I have two divs in a row, please how can I make the left side div to be sticky or fixed during scrolling?
The left div is like a table of contents in a book, while the right div contains the details of the book. I tried to use the CSS attribute "position: fixed", but the left side div disappears. Then, I also tried using this below
position: -webkit-sticky; /* for Safari */
position: sticky;
margin-top: 0
but it did not work.
From what I have, when the page loads you will see the page bold heading.
Then when you start to scroll, the bold heading scrolls upwards and when it comes to where the two divs (list of contents and details) in a row are, the left side div(list of contents) stops scrolling while the right side div(details) will continue to scroll.
Please how can this be achieved?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, shrink-to-fit=no" />
<link rel="stylesheet" media="all" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" intergrity="sha384-AYmEC3Yw5cVb3ZcuHt0A9w35dYTsvhLPVnYs9eStHfGJv0vKxVfELGroGkvsg+p" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous" />
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" media="all" />
<link href="css/bootstrap.css" rel="stylesheet" media="all" />
<link href="css/control.css" rel="stylesheet" />
<title>Quirver Guide</title>
<style type="text/css">
@media (min-width: 768px) {
.animate {
animation-duration: 0.3s;
-webkit-animation-duration: 0.3s;
animation-fill-mode: both;
-webkit-animation-fill-mode: both;
}
}
@keyframes slideIn {
0% {
transform: translateY(1rem);
opacity: 0;
}
100% {
transform: translateY(0rem);
opacity: 1;
}
0% {
transform: translateY(1rem);
opacity: 0;
}
}
@-webkit-keyframes slideIn {
0% {
-webkit-transform: transform;
-webkit-opacity: 0;
}
100% {
-webkit-transform: translateY(0);
-webkit-opacity: 1;
}
0% {
-webkit-transform: translateY(1rem);
-webkit-opacity: 0;
}
}
.slideIn {
-webkit-animation-name: slideIn;
animation-name: slideIn;
}
.navbar-toggler {
background: none;
border: none;
}
.navbar-toggler:active,
.navbar-toggler:focus {
outline: 0;
}
.navbar-toggler .icon-bar {
display: block;
width: 22px;
height: 2px;
border-radius: 1px;
margin: 4px 0 4px 0;
transition: all 0.2s;
}
.navbar-dark .navbar-toggler .icon-bar {
background: #145c7c;
}
.navbar-toggler .icon-bar:nth-of-type(1) {
transform: rotate(45deg);
transform-origin: 10% 10%;
}
.navbar-toggler .icon-bar:nth-of-type(2) {
opacity: 0;
filter: alpha(opacity=0);
}
.navbar-toggler .icon-bar:nth-of-type(3) {
transform: rotate(-45deg);
transform-origin: 10% 90%;
}
.navbar-toggler.collapsed .icon-bar:nth-of-type(1) {
transform: rotate(0);
}
.navbar-toggler.collapsed .icon-bar:nth-of-type(2) {
opacity: 1;
filter: alpha(opacity=100);
}
.navbar-toggler.collapsed .icon-bar:nth-of-type(3) {
transform: rotate(0);
}
.collapse .navbar-collapse .navbar-nav {
border-top: 1.5px solid #f5f5f5;
border-bottom: none;
}
.side h5 {
font-size: 14pt;
font-weight: 600;
font-family: 'BR Firma', sans-serif;
margin: 0 auto;
margin-top: 10%;
color: #1bb6f4;
}
.side {
margin: 0 auto;
padding: 6px;
line-height: 29px;
color: #0b2436;
line-height: 25.9375px;
vertical-align: baseline; letter-spacing: 0px; word-spacing: 0; text-align: start; font-style: normal; font-variant: normal; text-transform: none; text-indent: 0px;
}
.notes {
color: #505050; margin-top: 8%; font-weight: 500; font-size: 13pt; line-height: 35.9375px; vertical-align: baseline; letter-spacing: 0px; word-spacing: 0; text-align: start; font-style: normal; font-variant: normal; text-transform: none; text-indent: 0px;
}
.cover-notes {
margin-bottom: 8%;
margin-top: 6%;
font-family: 'BR Firma', sans-serif;
box-shadow: 0 15px 45px -20px rgba(206, 191, 191, 0.493);
padding: 10px;
border: 0.2px solid #fefefe;
border-radius: 7px;
margin-left: 4px;
}
.sub-head {
margin-top: 8%;
}
#left-content {
position: fixed;
}
</style>
</head>
<body style="font-weight: 400; font-size: 16.625px; line-height: 25.9375px; vertical-align: baseline; letter-spacing: 0px; word-spacing: 0; text-align: start; font-style: normal; font-variant: normal; text-transform: none; text-indent: 0px;">
<form id="form1" runat="server">
<asp:ScriptManager ID="script" runat="server"></asp:ScriptManager>
<div class="wrapper">
<div class="top" style="background-color: #f2f8fb;">
<nav class="navbar navbar-expand-lg navbar-dark fixed-top" id="header" style="opacity: 0.95;">
<a class="navbar-brand" href="#" style="font-size: 22px; font-weight: 900; margin-top: 0%;">
<img alt="" src="images/logoimage.png" height="33" /></a>
<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation" style="background-color: transparent; border: none; border-color: none; font-size: 12pt; border-width: 0px; color: #145c7c;">
<span class="icon-bar" style="font-size: 14pt; color: #145c7c;"></span>
<span class="icon-bar" style="font-size: 14pt; color: #145c7c;"></span>
<span class="icon-bar" style="font-size: 14pt; color: #145c7c;"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav" style="width: 100%; float: right;">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">About </a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" id="NavbarDrop" href="#" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Learn<b class="caret"></b></a>
<ul class="dropdown-menu dropdown-menu-end animate slideIn" aria-labelledby="NavbarDrop" style="border: none; background-color: #ffffff; font-size: 9pt; border: 0.5px solid #e9ebeb;">
<li><a class="dropdown-item" href="#" style="color: #011b33;"> support<br />
</a></li>
<li><a class="dropdown-item" href="#" style="color: #011b33;"> Contact<br />
</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="#"> Login </a>
</li>
<li class="nav-item">
<asp:Button ID="Button1" runat="server" CssClass="btn btn-primary" Text="Sign up" />
</li>
</ul>
</div>
</nav>
<div class="line" style="color: #fff;"></div>
<br />
<div class="greenbg" id="secondd" style="width: 100%; top: 1%;">
<br />
<div class="row col-sm-11" id="frontheader" style="width: 100%; margin: 0 auto; padding: 4px; margin-top: 8%;">
<div class="col-sm-8" style="margin: 0 auto; padding: 0px; margin-bottom: 8%;">
<div class="container" id="header-write" style="padding: 0px; margin-top: 6%; margin-bottom: 6%;">
<label id="boldhead" style="font-family: 'BR Firma', sans-serif; font-weight: 900; font-size: 8.7vmin; line-height: normal; vertical-align: baseline; word-spacing: 2px; text-align: start; color: #011b33; top: 6%;">
Using technology to increase productivity in organization
</label>
<br />
</div>
</div>
<div class="col-sm-1"></div>
<div class="col-sm-3" style="margin: 0 auto; padding: 6px; margin-top: 6%; margin-bottom: 8%;"></div>
</div>
<br />
<br />
</div>
</div>
<div id="dvMobile" class="visible-lg hidden-xl d-block d-lg-none"></div>
<div style="width: 100%; background-color: #fefefe;">
<div class="col-sm-11" style="max-width: 100%;">
<br />
<div class="row" style="width: 100%; margin: 0 auto;">
<div class="col-md-3 d-sm-inline-block" id="left-content">
<div class="side">
<ul class="list-unstyled components">
<li><h5>Contents</h5></li>
</ul>
</div>
<div class="side" style="color: #0b2436;">
<ul class="list-unstyled components" id="content">
<li class="active">
<a href="#"><b>Introduction</b></a>
</li>
<li style="margin-top: 4%;">
<a href="#">1. The need for technology</a>
</li>
<li style="margin-top: 4%;">
<a href="#">2. Solution to solving many problems</a>
</li>
</ul>
</div>
</div>
<div class="col-md-9 d-sm-inline-block" id="details">
<div class="cover-notes">
<h2 class="sub-head"><b>1. The need technology</b></h2>
<label class="notes">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum
</label>
<h2 class="sub-head"><b>2. Solution to solving many problems</b></h2>
<label class="notes">
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</label>
<br />
<br />
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
$(window).scroll(function () {
if ($(window).scrollTop() >= 30) {
$('.navbar').css('background', '#ffffff');
$('.nav-link').css('color', '#011B33');
$('.navbar-brand').css('color', '#011B33');
} else {
if ($('#dvMobile').is(':hidden')) {
$('.navbar').css('background', 'transparent');
$('.nav-link').css('color', '#011B33');
$('.navbar-brand').css('color', '#011B33');
}
}
});
$(window).resize(function () {
MobileNavColor();
});
$(function () {
MobileNavColor();
});
function MobileNavColor() {
if (!$('#dvMobile').is(':hidden')) {
$('.navbar').css('background', '#ffffff');
$('.nav-link').css('color', '#011B33');
$('.navbar-brand').css('color', '#011B33');
} else {
$('.navbar').css('background', 'transparent');
$('.nav-link').css('color', '#011B33');
$('.navbar-brand').css('color', '#011B33');
}
}
</script>
</body>
</html>