I have problem with position on CSS.
I create 3 elements: a menu navbar, a category bar (to filter content), and content.
It looks like this:
*Menu `navbar`*
Home About US
*Category bar*
Category 1 Category 2
*Content*
Lorem ipsum dolor sit amet consectetur adipisicing elit
When scrolling down, the menu show is hidden, and category bar will be fixed on top.
Screenshot:
When I add CSS code to fix category bar at top:
ul#filters {
overflow: hidden;
background-color: #333;
position: fixed;
width: 100%;
}
ul#filters li {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
It looks like:
I expected output is:
When loading page success, like the first image in my answer. When the user scrolls down, menu hidden, category bar fix top, content at below category bar.
Like this:
Note: change menu bar to category bar
Here is my code:
ul#filters {
overflow: hidden;
background-color: #333;
position: fixed;
width: 100%;
}
ul#filters li {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-fixed green child-nav">
<div class="container-fluid">
<div class="container">
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse ">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>About US</li>
</ul>
</div><!-- /.navbar-collapse -->
</div>
</div>
</nav>
<div class="container">
<ul id="filters" class="loaiduan clearfix">
<li class="li-selected">
Category 1
</li>
<li class="li-selected">
Category 2
</li>
</ul>
<div id="container" class="list">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores at numquam dolorem adipisci?</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores at numquam dolorem adipisci?</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores at numquam dolorem adipisci?</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores at numquam dolorem adipisci?</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores at numquam dolorem adipisci?</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores at numquam dolorem adipisci?</p>
</div>
</div>
Just use bootstrap class (navbar-fixed-top)
Example:
<nav class="navbar navbar-fixed-top green child-nav">
Hope to help!
I'd use Bootstrap's navbar.
You can make stick it on top with just one parameter, plus it's responsive.
Let me know if it works for you.
Related
Info in advance:
I've been looking for a solution for almost a week now and have already searched half of StackOverflow.
I know that there are many questions with the same title, but these have not brought me any further.
So please before commenting that this is a duplicate, first try the respective solution on my code.
The goal:
I want to add my footer at the very end of the page after the content.
The problem:
The ideas I have tried so far do not work properly. Either the content is permanently displayed at the edge of the screen, no matter where you are (so to speak a sticky footer), or the footer is in the middle of the content.
The Code (HTML & SCSS):
<html>
<head>
<link id="theme" rel="stylesheet" href="style.css" type="text/css" />
<title>Some page with footer</title>
</head>
<body>
<!-- Navigation - Don't worry, the navigation stylesheet isn't included-->
<div class="navigation">
<input id="burger" type="checkbox" />
<label for="burger">
<span></span>
<span></span>
</label>
<nav>
<div class="logo">
</div>
<ul>
<li>Some navigation</li>
<li>Some content</li>
</ul>
</nav>
<div class="icons">
</div>
</div>
<!-- Content -->
<main>
<div class="content">
<h2 id="faq">FAQ</h2>
<p>Some content here:
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Consectetur repellendus quia ab, voluptates tempore ipsam nemo?
<br>Ipsum mollitia odio maiores nisi dignissimos, temporibus magnam impedit est optio voluptate sit laboriosam?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Illum suscipit nobis, explicabo ducimus voluptates laudantium pariatur eius delectus repudiandae?
<br>Iure eaque sit quisquam itaque ducimus nam voluptates debitis nihil eligendi?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Consectetur repellendus quia ab, voluptates tempore ipsam nemo?
<br>Ipsum mollitia odio maiores nisi dignissimos, temporibus magnam impedit est optio voluptate sit laboriosam?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Illum suscipit nobis, explicabo ducimus voluptates laudantium pariatur eius delectus repudiandae?
<br>Iure eaque sit quisquam itaque ducimus nam voluptates debitis nihil eligendi?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Consectetur repellendus quia ab, voluptates tempore ipsam nemo?
<br>Ipsum mollitia odio maiores nisi dignissimos, temporibus magnam impedit est optio voluptate sit laboriosam?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Illum suscipit nobis, explicabo ducimus voluptates laudantium pariatur eius delectus repudiandae?
<br>Iure eaque sit quisquam itaque ducimus nam voluptates debitis nihil eligendi?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Consectetur repellendus quia ab, voluptates tempore ipsam nemo?
<br>Ipsum mollitia odio maiores nisi dignissimos, temporibus magnam impedit est optio voluptate sit laboriosam?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Illum suscipit nobis, explicabo ducimus voluptates laudantium pariatur eius delectus repudiandae?
<br>Iure eaque sit quisquam itaque ducimus nam voluptates debitis nihil eligendi?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Consectetur repellendus quia ab, voluptates tempore ipsam nemo?
<br>Ipsum mollitia odio maiores nisi dignissimos, temporibus magnam impedit est optio voluptate sit laboriosam?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Illum suscipit nobis, explicabo ducimus voluptates laudantium pariatur eius delectus repudiandae?
<br>Iure eaque sit quisquam itaque ducimus nam voluptates debitis nihil eligendi?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
</p>
<br>
</div>
</main>
<!-- Footer -->
<footer>
<ul>
<li># Copyright 2021 by some guy</li>
<li>This is not the final website.</li>
<li>Contact</li>
<li>AGB/TERMS</li>
<li>LEGAL</li>
</ul>
</footer>
</body>
</html>
body {
main {
position: absolute;
top: 15vh;
bottom: 0;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
line-height: 40px;
text-align: center;
width: 90%;
h2 {
position: relative;
font-family: 'Times New Roman', Times, serif ;
font-size: 2.7vh;
text-align: center;
}
p {
position: relative;
font-family: 'Gill Sans', 'Gill Sans MT', sans-serif;
font-size: 1.5vh;
text-align: center;
}
}
footer {
position: absolute; // Footer is inside the content
left: 0;
top: 100vh;
bottom: 0;
width: 100%;
height: 60px;
text-align: center;
background-color: red;
ul li {
display: inline;
}
}
}
I think this might help you
body {
margin: 0;
padding: 0;
}
.content {
top: 15vh;
bottom: 0;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
line-height: 40px;
text-align: center;
width: 90%;
}
h2 {
position: relative;
font-family: 'Times New Roman', Times, serif;
font-size: 2.7vh;
text-align: center;
}
p {
position: relative;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
font-size: 1.5vh;
text-align: center;
}
footer {
left: 0;
margin: 0;
padding: 0;
height: 60px;
text-align: center;
background-color: red;
padding: 0;
}
ul, li {
display: inline;
}
<html lang="en">
<head>
<link id="theme" rel="stylesheet" href="style.css" type="text/css" />
<title>Some page with footer</title>
</head>
<body>
<!-- Navigation - Don't worry, the navigation stylesheet isn't included-->
<div class="navigation">
<input id="burger" type="checkbox" />
<label for="burger">
<span></span>
<span></span>
</label>
<nav>
<div class="logo">
</div>
<ul>
<li>Some navigation</li>
<li>Some content</li>
</ul>
</nav>
<div class="icons">
</div>
</div>
<!-- Content -->
<main>
<div class="content">
<h2 id="faq">FAQ</h2>
<p>Some content here:
<br>Ipsum mollitia odio maiores nisi dignissimos, temporibus magnam impedit est optio voluptate sit laboriosam?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Illum suscipit nobis, explicabo ducimus voluptates laudantium pariatur eius delectus repudiandae?
<br>Iure eaque sit quisquam itaque ducimus nam voluptates debitis nihil eligendi?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Consectetur repellendus quia ab, voluptates tempore ipsam nemo?
<br>Ipsum mollitia odio maiores nisi dignissimos, temporibus magnam impedit est optio voluptate sit laboriosam?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Illum suscipit nobis, explicabo ducimus voluptates laudantium pariatur eius delectus repudiandae?
<br>Iure eaque sit quisquam itaque ducimus nam voluptates debitis nihil eligendi?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Consectetur repellendus quia ab, voluptates tempore ipsam nemo?
<br>Ipsum mollitia odio maiores nisi dignissimos, temporibus magnam impedit est optio voluptate sit laboriosam?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Illum suscipit nobis, explicabo ducimus voluptates laudantium pariatur eius delectus repudiandae?
<br>Iure eaque sit quisquam itaque ducimus nam voluptates debitis nihil eligendi?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Consectetur repellendus quia ab, voluptates tempore ipsam nemo?
<br>Ipsum mollitia odio maiores nisi dignissimos, temporibus magnam impedit est optio voluptate sit laboriosam?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
<br>Illum suscipit nobis, explicabo ducimus voluptates laudantium pariatur eius delectus repudiandae?
<br>Iure eaque sit quisquam itaque ducimus nam voluptates debitis nihil eligendi?
<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.
</p>
<br>
</div>
</main>
<!-- Footer -->
<footer>
<ul>
<li># Copyright 2021 by some guy</li>
<li>This is not the final website.</li>
<li>Contact</li>
<li>AGB/TERMS</li>
<li>LEGAL</li>
</ul>
</footer>
</body>
</html>
WordPress theme developers are always faced with this problem. One way to go about is to give your "main" element a style of
height:100vh;
This way it pushes the footer to the bottom of the page without you going through the stress of
position:absolute;
Sorry if its a dumb question but im making a ui thingy that I want to not get bigger when an item is added to it but also dont want change max-height
If you click on the button, a new element will be added. This does not change the size ("not make a div get bigger") of the div.
<div style="width:40px; max-height: 40px; overflow: auto; background: lightgreen">123 456 789 0 abc def xyz 123 456 789 0</div>
function myfunc(){
document.getElementById('mydiv').innerHTML += '<br>new_Item';
}
#mydiv {
width:100px;
max-height: 56px;
overflow: auto; /* or: hidden */
background: lightgreen
}
<div id="mydiv">123 456 789 0 abc def xyz 123 456 789 0</div>
<button onclick="myfunc()">Add item to div</button>
Maybe you need to use overflow on the div?
div {
overflow: scroll;
}
You can make use of overflow-y: scroll; with some extra CSS to the child. It will add child items only horizontally instead of breaking into a new line.
.container{
border: 1px solid red;
height: 100px;
overflow-y: scroll;
width: max-content;
}
.child{
max-width: 200px;
height: 100%;
display: inline-block;
border: 1px solid black;
vertical-align: top;
}
<div class="container">
<div class="child">I am first child</div>
<div class="child">I am second</div>
<div class="child">3rd</div>
<div class="child">Lorem ipsum dolor sit amet consectetur adipisicing elit. Porro itaque ad ipsum fugit assumenda sit sapiente soluta modi! Veniam, </div>
<div class="child">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quod iste hic nam odit cupiditate similique quia facilis, corporis fugit sit, reiciendis, explicabo sapiente. Minima aliquam dolore velit, eius non beatae?</div>
<div class="child">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quod iste hic nam odit cupiditate similique quia facilis, corporis fugit sit, reiciendis, explicabo sapiente. Minima aliquam dolore velit, eius non beatae?</div>
<div class="child">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quod iste hic nam odit cupiditate similique quia facilis, corporis fugit sit, reiciendis, explicabo sapiente. Minima aliquam dolore velit, eius non beatae?</div>
<div class="child">Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quod iste hic nam odit cupiditate similique quia facilis, corporis fugit sit, reiciendis, explicabo sapiente. Minima aliquam dolore velit, eius non beatae?</div>
<div class="child">I am not nth</div>
<div class="child">nth+1</div>
</div>
I am using Bootstrap 4 and I am making use of the CSS class called fixed-top to leave my sidebar landline while I go down with the scroll, this works perfect, but it happens that what I have inside container-fluid which is a table, is below sidebar, as I show it in The following example:
Keep in mind that I also use one sidebar Toggle to contract or not the sidebar, likewise the table is below the
I leave the class fixed-top and class code container-fluid
.fixed-top {
position: fixed;
top: 0;
right: 0;
left: 0;
z-index: 1030;
}
.container-fluid {
width: 100%;
padding-right: 0.75rem;
padding-left: 0.75rem;
margin-right: auto;
margin-left: auto;
}
UPDATE:
Add HTML code
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<link rel="shortcut icon" href="/Content/favicon.png">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
</head>
<body id="page-top">
<!-- Page Wrapper -->
<div id="wrapper">
<!-- Sidebar -->
<ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion toggled fixed-top" id="accordionSidebar">
<!-- Sidebar - Brand -->
<a class="sidebar-brand d-flex align-items-center justify-content-center">
<div class="sidebar-brand-icon rotate-n-15">
</div>
</a>
<!-- Divider -->
<hr class="sidebar-divider">
<!-- Nav Item - Dashboard -->
<li class="nav-item">
<a class="nav-link" href="#Url.Action("Index", "TicketForm")">
<i class="fa fa-paper-plane"></i>
<span>Abrir un ticket</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#Url.Action("Index", "Tickets")">
<i class="fa fa-bars"></i>
<span>Listado de Tickets</span>
</a>
</li>
<!-- Nav Item ties Collapse Menu -->
<li class="nav-item">
<a class="nav-link" href="#Url.Action("Index", "Service")">
<i class="fa fa-cogs"></i>
<span>Gestionar servicios</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#Url.Action("Index", "Report")">
<i class="fa fa-table"></i>
<span>Reportes</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#Url.Action("Index", "Dashboard")">
<i class="fa fa-line-chart"></i>
<span>Dashboard</span>
</a>
</li>
<!-- Sidebar Toggler (Sidebar) -->
<div class="text-center d-none d-md-inline">
<button class="rounded-circle border-0" id="sidebarToggle"></button>
</div>
</ul>
</body>
</html>
$(document).ready(function() {
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("menuDisplayed");
});
});
/* Sidebar */
#sidebar-wrapper {
z-index: 1;
position: fixed;
width: 150px;
height: 100%;
overflow-y: hidden;
background: #5b4282;
opacity: 0.9;
transition: all 0.5s;
}
/* Main Content */
#page-content-wrapper {
width: 100%;
position: absolute;
padding: 15px;
padding-left: 150px;
transition: all 0.5s;
}
#menu-toggle {
transition: all 0.3s;
font-size: 2em;
display: block;
text-align: center;
}
/* Change the width of the sidebar to display it*/
#wrapper.menuDisplayed #sidebar-wrapper {
width: 250px;
}
#wrapper.menuDisplayed #page-content-wrapper {
padding-left: 250px;
}
/* Sidebar styling */
.sidebar-nav {
padding: 0;
list-style: none;
transition: all 0.5s;
width: 100%;
text-align: center;
}
.sidebar-nav li {
line-height: 40px;
width: 100%;
transition: all 0.3s;
padding: 10px;
}
.sidebar-nav li a {
display: block;
text-decoration: none;
color: #ddd;
}
.sidebar-nav li:hover {
background: #846bab;
}
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div id="wrapper">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
<span class="fa fa-bars"></span>
</div>
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 class="text-center">Sidebar</h1>
<h2 class="small text-center">Second Header</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusantium perferendis maiores velit ad id delectus nisi eligendi doloremque officia necessitatibus, repellendus alias omnis, natus nam voluptates dolor vel minus ab?</p>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<!DOCTYPE html>
</body>
</html>
You need to divide the page in two sections first. Then distribute them as content section and sidebar section. That should solve your overlapping issue. like below snippet
<body>
<div id="wrapper">
<div id="sidebar">
dashboard menu (that nav tag and its childs)...
make this div fixed and sticky
</div>
<div id="content">
Contents
</div>
</div>
</body
This is just div distribution without css.
Footer is on right place but the columns in section are overlapping the footer
.columns {
float:left;
width: 22%;
height: 30%;
margin-left:8%;
}
Instead of float:left; I have used display:inline-block; but issue
not resolved this problem is occurring when website displayed on
mobile. When viewed on desktop it's working fine.
Try adding this to your CSS
box-sizing: border-box;
.container {
background: #f4f4f4;
padding: 5%;
margin: 5%;
}
.column1 {
background: #b40404;
padding: 5%;
color: #fff;
}
.column2 {
background: #000;
padding: 5%;
color: #fff;
}
.column3 {
background: #b40404;
padding: 5%;
color: #fff;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="column1">
This is column 1<br><br> Lorem ipsum, dolor sit amet consectetur adipisicing elit. Doloribus vero labore obcaecati illum reprehenderit incidunt consequatur quidem, id repellendus impedit, quaerat, mollitia ea culpa sint? Totam sunt omnis quis
eaque.
</div>
</div>
<div class="col-md-4">
<div class="column2">
This is column 2<br><br> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Laudantium mollitia, incidunt accusantium iure eius suscipit fugit tempore veniam deleniti, nulla dolore repudiandae voluptas, eaque architecto ratione recusandae
consectetur officia. Saepe.
</div>
</div>
<div class="col-md-4">
<div class="column3">
This is column 3<br><br> Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quis vitae nulla, beatae tenetur ea eaque obcaecati perspiciatis, architecto nemo culpa id non facilis distinctio aliquam. Accusamus voluptatum mollitia perferendis
libero.
</div>
</div>
</div>
</div>
you can use Bootstrap. Use the class container then row and define columns inside it. Like this:
I'm trying to make a sidebar on the left hand side of the page with the content to the right of it. the problem I'm running into is that when I try to make the div 100% height, I have to set it to position: absolute; which causes the content to overlap the sidebar.
Here is my HTML
<div class="row">
<div class="sidebar col-sm-3">
<ul>
<li class="active">
<h3>Link</h3>
</li>
<li class="">
<h3>Link</h3>
</li>
<li class="">
<h3>Link</h3>
</li>
<li class="active">
<h3>Link</h3>
</li>
</ul>
</div>
<!-- sidebar -->
<div class="sidebar-content col-sm-9">
<ul>
<li class="active">
<h2 class="underline">Link</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
</li>
<li class="">
<h2 class="underline">Link</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
</li>
<li class="">
<h2 class="underline">Link</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
</li>
<li class="">
<h2 class="underline">Link</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
</li>
</ul>
</div>
<!-- sidebar-content -->
</div>
<!-- row -->
And my CSS
.sidebar {
background: #eee;
height: 100%;
padding-top: 100px !important;
}
.sidebar-content ul li {
display: none;
}
.sidebar-content ul li.active {
display: block;
}
.sidebar-content {
position: relative;
right: 0;
padding: 100px;
}
Can anybody tell me how to make the div relative and 100% height or a better way to go about creating a sidebar?
Fiddle: https://jsfiddle.net/3Lapzoyf/3/
Solution:
Add a height of 100vh (which is a length unit representing 1% of the viewport height). This will result in a sidebar that has a height of 100% of the viewport height. Also make sure you have your row(s) inside a .container or .container-fluid when you are using Twitter Bootstrap (if you didn't do that already).
HTML:
<div class="container-fluid">
<div class="row">
<div class="sidebar col-sm-3">
<ul>
<li class="active">
<h3>Link</h3>
</li>
<li class="">
<h3>Link</h3>
</li>
<li class="">
<h3>Link</h3>
</li>
<li class="active">
<h3>Link</h3>
</li>
</ul>
</div><!-- sidebar -->
<div class="sidebar-content col-sm-9">
<ul>
<li class="active">
<h2 class="underline">Link</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
</li>
<li class="">
<h2 class="underline">Link</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
</li>
<li class="">
<h2 class="underline">Link</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
</li>
<li class="">
<h2 class="underline">Link</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum nostrum assumenda sequi praesentium aperiam. Accusamus omnis velit quos sint quas corporis inventore, facilis laborum pariatur explicabo maxime voluptas at aliquid!</p>
</li>
</ul>
</div><!-- sidebar-content -->
</div><!-- row -->
</div>
CSS:
.sidebar {
background: #eee;
height: 100vh;
padding-top: 100px;
}
.sidebar-content ul li {
display: none;
}
.sidebar-content ul li.active {
display: block;
}
.sidebar-content {
padding: 100px;
position: relative;
right: 0;
}
Fiddle: https://jsfiddle.net/3Lapzoyf/4/