Multiple container next to each other in Bootstrap4 - html

I have a bootstrap layout which I am trying to develop as a dashboard.
I have a container-fluid like this
<div class="row">
<div class="col-10 col-md-3 col-lg-3 col-sm-6">
</div>
It;s height is 100vh and width 250px. I have applied a margin-left:-240px so that it hides and when the user hovers over the 10px div the whole div shows up using transitions.
My problem is to place a main div next to it,like so
How can I achieve this? Should I add another container or row?

You can you the new auto-layout col class..
<div class="container-fluid">
<div class="row">
<div class="sidebar bg-faded">Sidebar</div>
<div class="col bg-inverse text-white">
Content
</div>
</div>
</div>
Demo: http://www.codeply.com/go/pDFygIAy9G

Not sure if you want the sidebar to push the content to its right over when it opens or if you want the sidebar to overlay the content when it opens.
Here is a solution for an overlaid sidebar.
$( '.sidebar' ).on( 'click', function ( e ) {
$( this ).toggleClass( 'closed' );
} );
#import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
.sidebar {
position: absolute;
left: 0;
top: 0;
width: 250px;
height: 100vh;
color: white;
background-color: black;
transition: left 500ms ease-in-out;
z-index: 5;
}
.sidebar.closed {
left: -240px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<aside class="sidebar closed">
<p>
Sidebar
</p>
</aside>
<div class="container-fluid">
<div class="row">
<div class="col-xs-6">
.col-md-6
</div>
<div class="col-xs-6">
.col-md-6
</div>
</div>
</div>

Related

My footer doesn't stay at the bottom of my webpage

I am a HTML / CSS beginner and I can't fix a problem. My problem is that when I zoom in my footer follows me.
By the way, I am using bootstrap 4
html{
position: relative;
min-height: 100%;
}
.Footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px; /* Set the fixed height of the footer here */
line-height: 60px;
background-color: #f5f5f5;
}
<footer class="Footer">
<div class="container-fluid">
<div class="col">
<!-- Les lanngues (Footer) -->
<div class="col-lg-3 col-xs-2">
EN
GER
FR
</div>
</div>
<div class="col">
<!-- L'adresse E-mail (Footer) -->
<div class="col-lg-5 col-xs-5" id="EmailFooter">
<span class="">E-mail : asdpawd#bluewin.ch</span>
</div>
<div class="col">
<!-- Telephone (Footer) -->
<div class="col-lg-3 col-xs-6">
<span id="Tel-Footer" >Tél : xxxxx</span>
</div>
</div>
</div>
</footer>
Not zoomed in : https://prntscr.com/pi19m7
Zoomed in : https://prntscr.com/pi19v3
When I zoom in, it just stop into the button
Welcome to our community. It is better to use a felx-box than absolute.
html,
body {
height: 100%;
}
#page-content {
flex: 1 0 auto;
}
#sticky-footer {
flex-shrink: none;
}
/* Other Classes for Page Styling */
body {
background: #000;
}
<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">
<body class="d-flex flex-column">
<div id="page-content">
<div class="container text-center">
<div class="row justify-content-center">
<div class="col-md-7">
<h1 class="font-weight-light mt-4 text-black">Sticky Footer using Flexbox</h1>
</div>
</div>
</div>
</div>
<footer id="sticky-footer" class="py-4 bg-dark text-white-50">
<div class="container text-center">
<small>Copyright ©</small>
</div>
</footer>
</body>
Setting the position to absolute may be the issue. This property will not be responsive to zoom ins and will remain in the same position regardless of the movement of other elements. Attempt removing the "position: absolute;" and instead giving the footer a margin-top if you want it to be spaced away from the content above.
I think that position: absolute is the issue here. Try to remove it and then run it. Sometimes working with position can be little tricky as well so try to get over with it and then apply your footer and see the results.

setting responsive width of the child element inside a flex div

In my application, there's a login page having a bootstrap customized well containing login form. Looks like this
Code was like
<div class="row">
<div class="col-lg-4"></div>
<div class="col-lg-4">
<div class="animated fadeInDown">
<div class="well no-padding">
<!-- Content Of Login Form -->
</div>
</div>
</div>
<div class="col-lg-4"></div>
</div>
Now, I have to put this on the center of the page. horizontally and vertically. So I removed the and all the bootstrap column grids. Put the well inside the custom container having display flex property.
<div class="login-container">
<div class="animated fadeInDown">
<div class="well no-padding">
<!-- Content Of Login Form -->
</div>
</div>
</div>
CSS of .login-container
.login-container {
position: fixed;
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
Now, the login form looks like this
How to get the same responsive width as I have previously inside the bootstrap col-lg-4 grid of the well. I tried to give the grids inside the container but that didn't work for me. I want the login form something like this without hardcoding width, something like this.
This I have done just for the question purpose by hardcoding width of the well.
The property position: fixed does not respect the width of the parent box if you want it to take up the full width, so one solution would be to calculate the width of the parent box using jQuery code and apply it to the child box. Here is an example:
let parentWidth = parseInt($('.col-sm-4.login-container').css('width'));
let parentPadding = parseInt($('.col-sm-4.login-container').css('padding').split(' ')[1]) * 2;
let childWidth = parentWidth - parentPadding;
$('.login').css('width', childWidth);
.container {
background: black;
}
.col-sm-4 {
background: #eee;
height: 100vh;
}
.login-container {
display: flex;
align-items: center;
}
.login {
width: 100%;
height: 100px;
background: red;
position: fixed;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-4 login-container">
<div class="login"></div>
</div>
<div class="col-sm-4"></div>
</div>
</div>
I hope it helps you.

Overflow-y and position: absolute cause the offset when scroll bar is not at the top

Here is an example: https://jsfiddle.net/sunvom3a/
I have a list of items.
Basically a container with some text and a dropdown. The idea is when you hover over the text the dropdown should be directly below (kina like a tooltip).
.container {
overflow-y: scroll;
height: 100px;
border: solid 2px green;
}
.popup {
width: 100px;
height: 100px;
background-color: yellow;
position: absolute;
display: none;
}
.item:hover .popup {
display: block;
}
<div class="container">
<div class="item"><span> Text1</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text2</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text3</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text4</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text5</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text6</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text7</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text8</span>
<div class="popup"></div>
</div>
<div class="item"><span> Text9</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text10</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text11</span>
<div class="popup"></div>
</div>
</div>
The first few elements that fit below the scrollbar of overflow-y (with my resolution these are first 5 items) work great:
but the rest are broken - when the scroll bar is moved this offset is added as a distance between the popup and the text:
Is there any way to get the consistent behavior for all items in the list?
This is exhibited in Chrome and Edge (Firefox works as expected). It is calculating the relative position based on the initial, out-of-view position.
You need to add this...
.item{
position: relative;
}
...to make the absolutely positioned element positioned relative to the hovered item.
Fiddle: https://jsfiddle.net/sunvom3a/1/
The downside to the above solution is that it moves the tooltip inside the container, making a portion of it likely to be out of view. On a side note, I'm not sure this is a great UI anyway since you are covering other options with your tooltip. I would recommend attaching it to the parent of your container (then you don't have to worry about the tooltip being out of view either.
Adding to your snippet...
body{
position: relative;
}
...will always put the tooltip in the top right corner of the body. This would be better done by adding a container for your scrolling container, but this is a mere example.
Fiddle: https://jsfiddle.net/sunvom3a/2/
just change position absolute to relative in popup class
jsfiddle: demo
.container {
overflow-y: scroll;
height: 100px;
border: solid 2px green;
}
.popup {
width: 100px;
height: 100px;
background-color: yellow;
position: relative;
display: none;
}
.item:hover .popup {
display: block;
}
<div class="container">
<div class="item"><span>Text1</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text2</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text3</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text4</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text5</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text6</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text7</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text8</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text9</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text10</span>
<div class="popup"></div>
</div>
<div class="item"><span>Text11</span>
<div class="popup"></div>
</div>
</div>

Bootstrap full width sections with graphical backgrounds

I am trying to implement a design from my graphic designer, which whilst looks cool is giving me some headaches as i don't know how to implement in bootstrap.
We have a call to action section, which aligns with the 12 column grid system on its left and right extremes.
It also stretches to the view-port edges:
On the left we have red background stretching all the way to the view-port edge.
On the right we have a grey background image stretching all the way to the view-port edge.
I haven't been able to find a search term for what I am looking to achieve let alone where to start (other than have the cta use the background for the entire width, then overlay a left element over the top).
Any idea on how to code the below graphical layout in bootstrap please?
<section class="cta" style="background: grey; position: relative">
<div class="red" style="position: absolute; left: 0; width: 10%; background: red"></div>
<div class="text-outer">
<div class="container">
<div class="row">
<div class="col-xs-6">left</div>
<div class="col-xs-6">right</div>
</div>
</div>
</div>
</section>
Using <div class="container-fluid"> as a starting point; I am guessing at your page's layout. Let's try this:
See below:
.cntn {
border: 1px red solid; /* you can remove this (not needed) */
}
.red {
background-color: red;
text-align: right;
margin: 0; /* optional */
width: 100px; /* adjust to suit your needs */
float: left;
}
.cta {
margin: 0; /* optional */
float: right;
border: 1px solid green; /* you can remove this (not needed) */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- make container fluid -->
<div class="container-fluid">
<div class="row">
<!-- heading area: hexagon -->
<div class="red">
<img src="http://placehold.it/100/100" />
</div>
<!-- heading area: call-to-action -->
<section class="cta">
Action
</section>
</div>
<div class="row cntn">
<div class="col-xs-6">left</div>
<div class="col-xs-6">right</div>
</div>
</div>
Simply change 'div class="container"' to 'div class="container-fluid"'
Something like this? Where black should be the grey gradient and max-width:400px could be anything.
.cta {
overflow-x: hidden;
position: relative
}
.text-outer .container {
width: 100%;
max-width: 400px;
background: grey;
z-index: 2;
position: relative;
}
.text-outer:before,
.text-outer:after {
content: "";
position: absolute;
width: 50%;
height: 100%;
top: 0;
}
.text-outer:before {
background-color: red;
left: 0;
}
.text-outer:after {
background-color: black;
right: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<section class="cta">
<div class="text-outer">
<div class="container">
<div class="row">
<div class="col-xs-6">left</div>
<div class="col-xs-6">right</div>
</div>
</div>
</div>
</section>
jsFiddleLink
I created with 3 divs as Left Center and Right but if you want to use Left and center then create your own class. Probably following will work
.custom {
width:calc(100% - (50% - 768px/2));
}
.custom {
width:calc(100% - leftCellWidth);
}
You can set height of left as per height of hex image.
Use jumbotron class outside the class container for full-width, as explained here.
HTML:
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="red col-xs-4">
</div>
<div class="grey col-xs-8">
</div>
</div
</div>
</div>
CSS:
.red {
background: url('awesomeredimage.png');
background-size: cover;
}
.grey {
background: url('awesomegreyimage.png');
background-size: cover;
}
All your divs should be wrapped in the container div. And as some others have also suggested: container-fluid helps.
Within container fluid you can add a regular container for the rest of your content. My code below explains this.
You could take the easy route and just use the entire cta image you've posted as a clickable image with .img-responsive in a col-xs-12. In that case my fix takes you about 2 minutes:
<section style="background: grey; position: relative">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<img src="/img/cta.jpg" class="img-responsive">
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="container">
<!-- All you other content here-->
</div>
</div>
</div>
</div>
</section>
But you could also hack the design into cols, as I try to show in the code snippet below. Of course you need to tweak and decide on the exact sizes yourself.
<section style="background: grey; position: relative">
<div class="container-fluid">
<div class="row">
<div class="col-xs-3 red">
<img src="/img/hexagon.png" class="img-responsive pull-right">
<!--and give this img a negative margin to flow over to the grey area-->
</div>
<div class="col-xs-1 grey-image"></div>
<div class="col-xs-3 grey-image">
<h3 class="text-center">Call to action</h3>
<p class="text-center">Discount etcetera</p>
</div>
<div class="col-xs-5 grey-image">
<button class="btn center-block">Request quote</button>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="container">
<!-- All you other content here-->
</div>
</div>
</div>
</div>
</section>
Use class="container-fluid" instead of class="container" and than do this style:
.container-fluid {
margin-right: auto;
margin-left: auto;
padding-left: 0px;
padding-right: 0px;
}

How to get vertical spacing using a bootstrap grid?

I'm having a tough time wrapping my mind around how to achieve vertical spacing with the bootstrap grid system. I want one box to be 1/3 from the top and left and another to take up 1/3 from the bottom, but be full-width. I have three rows right now spanning 12, 6, and 12 columns respectively:
An example layout using draw.io:
Within the body tag of index.html:
<body>
<br>
<br>
<br>
<!-- Content -->
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-0 col-sm-8 col-sm-offset-0 col-xs-12 col-xs-offset-0">
<div class="col-md-12 col-sm-12 col-xs-12 text-left">
<h1><strong>I am strong<strong><span class="lead">i am less strong</span></h1>
</div>
</div>
</div>
</div>
<!-- JavaScript -->
<script src="assets/third-party/js/jquery.min.js"></script>
<script src="assets/third-party/js/bootstrap.min.js"></script>
</body>
One trick is to force the height of your container to fill the whole page with a line of jQuery. You don't need jQuery for this, but I noticed that you already include it on your page.
The markup:
<div class="container full-page-height">
<div class="row offset-top-third">
<div class="col-md-6 col-md-offset-3 white">
<h1>Hey you!</h1>
</div>
</div>
<div class="row offset-bottom-third">
<div class="bgimg">Background image here</div>
</div>
</div>
The CSS:
.bgimg {
background: #333;
color: #eee;
}
.white {
background: #fff;
}
.offset-top-third {
position:relative;
top: 33.333%;
height: 33.333%;
background: #888;
}
.offset-bottom-third {
position:relative;
top: 66.667%;
height: 33.333%;
background: #888;
}
The Javascript:
$(function() {
var h = window.innerHeight;
$(".full-page-height").css({height: h});
});
The bootply.
If your vertical columns are div's, then give each one a margin value in pixels to space them away from each other. Then set the width of each column to a percent value so they fit the whole window.