How to setup a master-detail page with Bootstrap? - html

I'm having trouble setting up a "master-detail" view using Bootstrap 3. I'm attaching a picture of the specific layout I'm trying to get:
I've created a div with .row spanning the 12 columns for the header, and then another div.row with a div.col-md-4 and div.col-md-8 for the two columns. But obviously this doesn't achieve what I'm looking for. I've tried playing with the position attribute, but it seems to conflict with the Bootstrap CSS and I always just get jumbled text.
Thank you very much in advance and let me know if you'd like me to provide more details on what I'm looking for. Hopefully the pic is clear.

You are looking for
position: fixed;
This ensures that the element is always static relative to the viewport. You will then use the relative positioning properties to place it where you want it to go.
For the top element (say, your navbar), you can set:
top: 0;
For the bottom element, you can set:
bottom: 0;
So, something like this:
.row, .col-md-4, .col-md-8 {
border: 2px solid pink; /* For showing the div borders */
}
.row.main-content {
background-color: blue;
height: 300px;
margin-top: 20px; /* Needs to match the height of .row.top */
}
.row.top {
position: fixed;
top: 0;
height: 20px;
width: 100%;
background-color: red;
z-index: 9999;
}
.row.bottom {
position: fixed;
bottom: 0;
height: 20px;
width: 100%;
background-color: green;
z-index: 9999;
}
.scrollable {
overflow-y: scroll;
height: 300px; /* May need to be set somehow */
}
<div class="container-fluid"><!-- To get it to take up the whole width -->
<div class="row top">
</div><!-- row -->
<div class="row main-content">
<div class="col-md-4">
<div class="sub-header">
</div>
<div class="scrollable">
<!-- menu items here -->
</div>
<div class="sub-footer">
</div>
</div>
<div class="col-md-8 scrollable">
<!-- Product detail goes here -->
</div>
</div><!-- row -->
<div class="row bottom">
</div><!-- row bottom -->
</div><!-- container-fluid -->
Hope that helps.

Related

Unable to make left sidebar fixed [duplicate]

This question already has answers here:
How to create a fixed sidebar layout with Bootstrap 4?
(5 answers)
Closed 3 years ago.
I have a left div with id sideNav and a right main div like this
#sideNav {
background-color: #012d20;
position: fixed;
z-index: 1;
top: 0;
left: 0;
overflow: hidden;
border-right-style: groove;
height: 100vh;
}
<div class="row">
<!-- navigation sidebar -->
<div class="col-2 pt-5" id="sideNav">
...
</div>
<!-- main content area -->
<main class="col-10">
...
</main>
</div>
The code works but the left part of main is now inside behind the sideNav. When I remove the position property of the sideNav css, my divs are displayed correctly again but sideNav is no longer fixed and scrolls with the page.
How do I keep sideNav fixed and my divs properly displayed?
The reason this isn't working for you, is because row has display type flex, so that all the cols below fit into that row.
Your cols are then blocks spaced via their given value e.g. col-3 col-4 etc
By changing the column display type (to fixed in your example) your removing it from the flex spacing, and so your main nav will move left because you haven't offset it.
To fix this, don't add padding as others have suggested, BootStrap has classes that handle this. Instead, add offset-2 to your main nav, and leave everything else as is.
Example Snippet
#sideNav {
background-color: #012d20;
position: fixed;
z-index: 1;
top: 0;
left: 0;
overflow: hidden;
border-right-style: groove;
height: 100vh;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="row">
<!-- navigation sidebar -->
<div class="col-2 pt-5" id="sideNav">
...
</div>
<!-- main content area -->
<main class="col-10 offset-2">
...
</main>
</div>
Thats because fixed gets "ignored" by other containers. It is handelt as if it was absolute. You can give your sidebar a fixed width and your main a padding.
#sideNav {
background-color: #012d20;
position: fixed;
z-index: 1;
top: 0;
left: 0;
overflow: hidden;
border-right-style: groove;
height: 100vh;
width: 350px;
}
main {
padding-left: 350px;
}
Codepen
Lets try this,
iam adding width for sideNav about 40px;the same padding-left iam put #main-content.
html
<div class="row">
<!-- navigation sidebar -->
<div class="col-2 pt-5" id="sideNav">
<p>paragraph...</p>
</div>
<!-- main content area -->
<main class="col-10" id="main-content">
<p>paragraph...</p>
<p>paragraph...</p>
</main>
</div>
css
#sideNav {
background-color: #012d20;
position: fixed;
z-index: 1;
top: 0;
left: 0;
overflow: hidden;
border-right-style: groove;
height: 100%;
width:40px;
}
#main-content{
width:100%;
float:left;
padding:0 0 0 40px;
background:yellow;
}
I saw you are using bootstrap grid, so to keep the grid working I recommend putting your fixed container in the .col-2 div
#sideNav {
background-color: #012d20;
position: fixed;
z-index: 1;
top: 0;
left: 0;
overflow: hidden;
border-right-style: groove;
height: 100vh;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<!-- navigation sidebar -->
<div class="col-2 pt-5">
<div id="sideNav">
...
</div>
</div>
<!-- main content area -->
<main class="col-10">
...
</main>
</div>

absolute child same width as column container

I'm creating my own dropdown search bar that displays results when a user types some text.
The problem is that the result list div has to be position: absolute. This leads it to ignoring the parent col container width. How do I get results list to fit within the width of the col?
.player-search-list {
z-index: 2;
background-color: white;
position: absolute;
width: 100%;
}
<div class="row">
<div class="col-6">
<!-- some other content -->
</div>
<div class="col-6">
<div class="top-buffer">
<!-- Relative search bar that expands to bootstrap col -->
<div class="player-search-bar input-group rounded-bottom-0">
<!-- search functionality-->
</div>
</div>
<!-- ***ABSOLUTE drop down*** that doesnt fit inside bootstrap col -->
<div class="list-group player-search-list" id="playerSearch">
<div *ngFor="let result of results | slice:0:9">
<!-- drop down results list functionality -->
</div>
</div>
</div>
</div>
I used:
.player-search-list{
z-index: 2;
background-color: white;
position: absolute;
width: 100%;
left: 0;
padding-left: 15px;
padding-right: 15px;
}
The left is to center the div inside the container. The padding-left and padding-right is the same amount of the col container. This keeps the divs in the same position and size of the search bar.
In Case somebody stumbles on this question and is still looking for the result:
Your Parent DIV (in this case .col-6) must be position:relative.
The width of the search results must be set to 100%!
parent_container {
position: relative;
}
search_results {
position: absolute;
width: 100%
}

CSS: Sidebar won't appear inside parent element

I'm trying to add two sidebars to both edges of the middle element. The left one works without an issue, however, the right one won't. Instead, it appears below its parent element (as seen in the picture) unless I position it as absolute, then however, it goes over the navbar.
Relevant css:
/* The parent element */
main {
margin: 0;
position: relative;
left: 22%;
right: 22%;
width: 56%;
height: 50vh;
background-color: #c5c5c5;
}
/* The correctly shown sidebar */
.sidenav {
margin: 0;
height: 100%;
width: 160px;
top: 7%;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 7%;
}
/* The wrongly shown sidebar */
.bar-right{
float: right;
margin: 0;
width: 200px;
height: 100%;
background-color: #111;
overflow-x: hidden;
padding-top: 7%;
}
HTML:
<main>
<div class="topbar">
[top bar stuff]
</div>
<div class="sidenav">
[usernamestuff]
Link1
Link2
Link3
</div>
<div class="bar-right">
<p>text for test</p>
</div>
</main>
Both sidebars are effectively identical so I don't understand why they behave so differently. How do I get them both to their appropriate edges of the main element?
I would recommend you to use Bootstrap. This will help you to achieve what you looking for so easy, by this code:
<div class="container">
<div class="row">
<div class="col-sm-3">
// First sidebar
</div>
<div class="col-offset-6 col-sm-3">
// Second sidebar
</div>
</div>
</div>

Can't make zurb foundation columns stretch to bottom of page

I'm trying to make a three column layout that stretches to the bottom of the screen which uses the Zurb Foundation grid.
The basic structure involves three columns, each with a title in the center and a distinctive background image, and a footer.
This is what I'm trying to achieve (where the three colours would be background images):
The issue is that since there isn't enough content to fill the screen my columns don't stretch to the bottom. I've been able to fix the footer to the bottom of the page using this technique https://css-tricks.com/snippets/css/sticky-footer/.
But the result looks like this:
Here is my html:
<div id="content-wrapper">
<div class="row collapse">
<div class="small-centered large-uncentered large-4 columns episode">
<div class="episode-titles">
<h1>Column01</h1>
</div><!-- ends episode titles-->
</div><!-- ends episode-->
<div class="small-centered large-uncentered large-4 columns episode" >
<div class="episode-titles">
<h1>Column02</h1>
</div><!-- ends episode titles-->
</div><!-- ends columns-->
<div class="small-centered large-uncentered large-4 columns episode" style="background-image:url('{{ featured_image }}');">
<div class="episode-titles">
<h1>Column03</h1>
</div><!-- ends episode titles-->
</div><!-- ends columns-->
</div><!-- ends row collapse-->
</div>
and here is my css:
body, html {
height: 100%;
}
#content-wrapper {
min-height: 100%;
margin-bottom: -90px;
}
#footer, #content-wrapper:after {
height: 90px;
}
#content-wrapper:after {
content: "";
display: block;
}
#footer {
background-color: #161616;
border: none;
}
.episode {
max-width: 100%;
background-size: cover;
background-position: center center;
text-align: center;
height: 100%;
}
.episode-titles {
text-align: center;
display: inline-block;
vertical-align: middle;
}
Here is a fiddle for my approach:
JSFiddle
For the footer though, I just used position: fixed instead. The key thing is that you also need to specify height on the parent elements too, the content-wrapper, the row, etc.
The only caveat with the way I did it though, is that the row-footer div is position fixed and has a z-index of 1. So it is essentially hovering over the 3 columns. So that means if there does happen to be any content contained within these columns that nears the very bottom, there is a potential it can be covered.

Position footer at the bottom of the page

I have a fairly complex layout that I am building, it relies on a is affected by height, and min-height's so the usual tricks to position the footer at the bottom aren't working.
Given my JSFiddle how can I position the footer at the bottom when the content is a lot or minimal?
Here is some of the css I am currently using:
body, html, #wrapper {
height: 100%;
min-height: 100%;
}
.header {
height: 30%;
background-color: aliceblue;
}
.main {
background-color: antiquewhite;
}
.main .content {
height: 2000px;
background-color: aquamarine;
padding-bottom:80px;
}
.footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 80px;
background-color: beige;
}
If I understand your requirement correctly, you want the footer to sit at the bottom of the content box.
One solution is to make the content box position:relative and move the footer inside it, so that its position:absolute will bind it to the content box, and the bottom:0 will achieve the desired effect of having it sit against the bottom of said content box.
See http://jsfiddle.net/wn6uvske/5/.
HTML:
<div id="wrapper">
<div id="sidebar"></div>
<div id="body-content">
<div class="header">
<div class="navbar navbar-default" role="navigation">
<div class="container">
<ul class="nav navbar-nav navbar-right">
<li>Toggle Menu
</li>
</ul>
</div>
</div>
</div>
<div class="main">
<div class="content container">
<p>Content</p>
<div class="footer"> <!-- moved up into content container -->
<p>Footer</p>
</div>
</div>
</div>
</div>
</div>
(relevant) CSS:
.main .content {
height: 2000px;
background-color: aquamarine;
padding-bottom:80px;
position:relative;
}
.footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 80px;
background-color: beige;
}
you can use the sticky footer trick. Wrap all of your content in a wrapper excluding the footer, set min-height:100% and margin: -(footer height) on said wrapper to keep it at the bottom:
FIDDLE
UPDATE
You can take the header section out and use CSS calc() to adjust the height:
NEW FIDDLE