Bootstrap Layout center container - html

I am new to bootstrap and am trying to create the following layout without success.
<div class="container-fluid">
<!-- Logo row -->
<div class="row">
<div class="col-sm-12">
<div class="header">
<img id="logoImage" src="#" height="67px">
</div>
</div>
</div>
<!-- QRCODE row-->
<div class="row gradient qrCodeRow ">
<div class="row" style="height: 100px;"></div>
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="qrCode"><img src="#" height="300px" width="300px"></div>
</div>
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="text qrText ">
<p class="bigText"><strong>text</strong> text</p>
<p>text</p>
<p>text</p>
</div>
</div>
</div>
</div>
and css:
.container-fluid {
padding: 0;
margin: 0;
}
.v-center {
position: relative;
transform: translateY(50%);
}
.gradient {
background: #1a5062; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(#1a5062, #0d2933); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(#1a5062, #0d2933); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(#1a5062, #0d2933); /* For Firefox 3.6 to 15 */
background: linear-gradient(#1a5062, #0d2933); /* Standard syntax */
}
.text {
color: #ffffff;
font-family: sans-serif;
}
/* header */
.header {
height: 121px;
padding: 0px 36px 0px 36px;
display: flex;
align-items: center;
}
/* qrcode */
.qrCodeRow {
min-height:502px;
}
.qrCode {
float: right;
}
.qrCode img {
height: 300px;
width: 300px;;
}
.qrText {
height: 300px;
padding-left: 45px;
font-size: 24pt;
font-family: "DIN Neuzeit Grotesk Std Light";
}
I can not figure out how to make the middle part stay 1200px all the time until it has to resize. And I haven't even started thinking of how to make M1 go on top of M2.

I believe this is what you are looking for. First I created a header that is empty and fullwidth. Next I created the main element with the container (of 1200px) in it. The container has a negative margin-top to pull it up. Inside this container you can find the 2 columns. Adding col-xs-12 will make the column 100% width on xs-devices (extra small devices eq phones) and col-md-4 will make this column only 4/12th width of the container on medium devices (desktop) adding these 2 classes together with some offset for the columns makes it responsive. Below you can see the code created in this bootply: http://www.bootply.com/04pBMcDCSu
<div class="wrapper" style="background-color: red;">
<header style="height: 300px; background-color: white;">
</header>
<main>
<!-- (1) -->
<div class="container" style="margin-top: -100px; background-color: yellow;">
<div class="row">
<div class="col-xs-12 col-md-4 col-md-offset-1" style="background-color: blue; height: 300px;">
<h1>M1</h2>
</div>
<div class="col-xs-12 col-md-4 col-md-offset-2" style="background-color: green; height: 300px;">
<h1>M2</h2>
</div>
</div>
</div>
<!-- (2) -->
</main>
</div>

Related

CSS uneven div positioning

I want to position a div according to the picture:
I'm successful so far by using Bootstrap's row class and using z-index in my CSS. But when I resize the browser, it's not responsive, it just floats off the right side of the page. By the way, I'm using position: absolute (I read online that I have to use this in order to make use of z-index). Is there any other more elegant way to do this? I want it to be responsive but can't seem to find any other workaround than the wonky one I implemented.
Code:
#div2 {
float: inherit;
position: absolute;
top: inherit;
left: 60%;
width: 320px;
height: 1290px;
z-index: 5;
}
<div class="container">
<div class="div-container">
<div class="row">
<div id="div1">
<p>Div 1</p>
</div>
<div id="div2" align='center'>
<p>Div 2</p>
</div>
</div>
<div class="row">
<div id="div3">
<p>Div 3</p>
</div>
</div>
</div>
</div>
You need to make use of the nested rows inside a column. See here - Bootstrap Nesting. Ignore the CSS here as it is for snippet styling and height is used for ignoring the content.
.B {
min-height: 130px;
background: #393276;
margin-bottom: 20px;
}
.A {
min-height: 100px;
margin-bottom: 20px;
background: #393276;
}
.C {
min-height: 250px;
background: #393276;
}
div {
text-align: center;
color: #fff;
font-size: 32px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container mt-4">
<div class="row">
<!-- First Column -->
<div class="col-sm-6">
<!--Rows nested inside a column-->
<div class="row">
<div class="col-12">
<div class="A">A</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="B">B</div>
</div>
</div>
</div>
<!-- Second Column -->
<div class="col-sm-6">
<div class="C">C</div>
</div>
</div>
</div>
I have used flexbox to keep responsive design and some margin positioning to keep the formation together.
.container{
display: flex;
flex-wrap: wrap;
width: 150px;
}
.div1, .div3{
margin-right: 5px;
width: 50px;
height: 50px;
}
.div2{
margin-right: 5px;
width: 50px;
height: 110px;
}
<div class="container">
<div class="div1"> div1 </div>
<div class="div2"> div2 </div>
<br/>
<div class="div3" style="margin-top: -55px;"> div 3 </div>
</div>

How to make div have 100% height of parent, independent of children's size? Complex layout

I have the following layout on my webpage:
The left side, represented here by D, is perfect. There's a lot of content in there and it scrolls as it should. Even when the content grows, the height remains 100% of the webpage's height while the scroll increases.
The right side has some content on B. Everything fine as well. Using Bootstrap 4, B and A are row inside a col and, as such, have 50% share of the parent container.
The problem is that I would A to fill all of the remaining space while being scrollable independent of the number of Cs inside it. This means that with 1 C, it should have its height as half of the page's height (as depicted in the picture) and by having 20 Cs, it should occupy the same height (while being scrollable such that the user can see the 20th C by scrolling to the bottom of A).
So, I am being able to achieve vertical scrollability on A if I set a hardcoded height as height=350px but this is far from ideal since desktops have varying heights. On the other hand, if I don't set a height, A's height become the height necessary to wrap all elements inside it, so with 4 Cs the right-bg layout already surpass the left part of the webpage, causing a break on the overall layout.
<div class="right-bg">
<div class="container col" style="height:100%">
<div class="row"> <!-- THIS IS B -->
<div class="col">
<div class="row" id="chart-div">
<canvas id="myChart"></canvas>
</div>
<div class="row horizontal-menu-wrapper">
</div>
</div>
</div>
<div class="container row ranking-container"> <!-- THIS IS A -->
<div class="container rounded-card"> <!-- THIS IS C -->
<div class="row">
<div class="col-lg-1 col-md-1 col-sm-1">
<div id="ranking-trophy-header" class="row card-header">
<i title="General" class="fas fa-trophy header-icon"></i>
</div>
</div>
<div class="col-lg-11 col-md-11 col-sm-11">
<div class="row row-card">
<div class="col-lg-5 col-md-5 col-sm-5">
<p class="ranking-percentage-value"> Top 1%</p>
</div>
<div class="col ranking-field">
<p class="form-field">Position</p>
<p class="form-ranking-value"><span class="absolute-ranking">#<span class="absolute-ranking-value">83</span></span></p>
</div>
<div class="col ranking-field">
<p class="form-field">Pool</p>
<p class="form-pool-value">9470</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
html {
height: 100%;
}
body {
height: 100%;
}
.left-bg {
flex-flow: column;
display: flex;
width: 54%;
height: 100%;
overflow: scroll;
padding-bottom: 10px;
}
.right-bg {
flex-flow: column;
display: flex;
width: 46%;
height: 100%;
padding-top: 12px;
}
.ranking-container {
vertical-align: center;
margin: 5px;
margin-top: 15px;
margin-bottom: 5px;
padding: 15px;
overflow: scroll;
border-radius: 10px;
margin-bottom: -9999px;
padding-bottom: 9999px;
}
Use d-flex, flex-column, and h-100 for its parent. And flex-grow-1 for the row that you want that it occupies all of the available space.
html,
body {
height: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<div class="container d-flex flex-column h-100 bg-light">
<div class="row">
<div class="col p-5 bg-danger"></div>
</div>
<div class="row bg-info flex-grow-1">
<div class="col"></div>
</div>
</div>
It works as expected irrespective of how many row you have.
https://codepen.io/anon/pen/RJVaKw
You need to use bootstrap-4.1 because flex-grow-1 does not exist in the earlier version of it.
Most of your style is unnecessary. You can achieve this with pure Bootstrap classes.
Update
It does not work in Chrome. To fix the issue, use flex-grow-1 for the column inside flex-grow-1 row. And set its overflow-y to scroll. You may hide the scrollbars too.
html,
body {
height: 100%;
}
.overflow-y-scroll {
overflow-y: scroll;
}
/*hide scrollbar in webkit-browsers */
::-webkit-scrollbar {
width: 0px;
background: transparent;
}
::-webkit-scrollbar-thumb {
background: #FF0000;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
<div class="container d-flex flex-column h-100 bg-light">
<div class="row">
<div class="col p-5 bg-danger"></div>
</div>
<div class="row bg-info flex-grow-1">
<div class="col flex-grow-1 bg-primary overflow-y-scroll">
<!-- content -->
</div>
</div>
</div>
https://codepen.io/anon/pen/jKmYdq
Try it:
<div class="container col" style="position: absolute; top: 0px; bottom: 0px; ">
</div>
You can give any block level element an explicit height and then add:
overflow: auto;
which will add a scrollbar to that element if the content of the element is taller than the element's own explicitly declared height.
Here is a layout similar to the one you have described above, using CSS Grid.
Note that vertical scrollbars automatically display in the areas D and A because the content within those elements is taller than the height of the parent elements themselves.
Working Example:
main {
display: grid;
grid-template-rows: 50% 50%;
grid-template-columns: 50% 50%;
width: 80vw;
height: 80vh;
border: 6px solid rgb(191, 191, 191);
border-radius: 15px;
}
.a-area {
background-color: rgb(255, 63, 63);
}
.b-area {
background-color: rgb(255, 127, 0);
}
.c-area {
border: none;
background-color: rgb(63, 63, 63);
}
.d-area {
grid-area: 1 / 1 / 3 / 2;
color: rgb(127, 127, 127);
}
main div {
color: rgb(255, 255, 255);
border: 4px solid rgb(191, 191, 191);
overflow-x: hidden;
overflow-y: auto;
}
main div h2 {
margin: 0;
padding-right: 6px;
font-size: 24px;
line-height: 36px;
text-align: right;
}
main div p,
.c-area {
margin: 6px 12px;
}
<main>
<div class="d-area">
<h2>D</h2>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
<p>Paragraph</p>
</div>
<div class="b-area">
<h2>B</h2>
</div>
<div class="a-area">
<h2>A</h2>
<div class="c-area">
<h2>C</h2>
</div>
<div class="c-area">
<h2>C</h2>
</div>
<div class="c-area">
<h2>C</h2>
</div>
<div class="c-area">
<h2>C</h2>
</div>
<div class="c-area">
<h2>C</h2>
</div>
<div class="c-area">
<h2>C</h2>
</div>
</div>
</main>

Div align to center

Hello i spent hours doing this but still can't align the social media icons to the center of text "Connect with us" when it's in desktop size. It's only aligned when it's in mobile size i want them to align to center either its desktop size or mobile. I want the content of the footer to be responsive. I already used media queries but i encounter a problem so i repeat my footer again from the start because its not responsive when in desktop size. Please give me some ideas how to do it or suggestions. Im new to html and css.
here is the desktop size. I want the social media icons to align to the center of text "Connect with us".
here is the mobile size. Its well aligned here.
UPDATE:
This is what i want to do in the first picture. But i repeat my footer because when i minimized it as a desktop its not responsive the alignments, the text, the height it's a disaster so i decided to do it again from the start. I already used media queries before but as a desktop its not working when i minimized it it's not responsive but in mobile size its working.
here is my html code for the footer.
<div class="content">
</div>
<footer class="footer">
<div class="container">
<div class="row">
<div class="footer-col col-sm-4">
<h4 class="connect">Connect With Us</h4>
<div class="twitter-hover social-slide"></div>
<div class="facebook-hover social-slide"></div>
<div class="linkedin-hover social-slide"></div>
</div>
</div>
</div>
</div>
</footer>
here is my css code.
* {
margin: 0;
}
html, body {
height: 100%;
overflow: auto;
}
.content {
min-height: 100%;
/* equal to footer height */
margin-bottom: auto;
}
.content:after {
content: "";
display: block;
}
.footer, .content:after {
height: auto;
}
.footer {
display: block;
background-color: #a92419;
color:#fff;
font-family: Century Gothic;
width: 100%;
height: auto;
}
h4{
text-align: center;
padding-top: 20px;
}
.twitter-hover {
background-image: url('images/twitter-hover.png');
margin-left: 65px;
}
.facebook-hover {
background-image: url('images/facebook-hover.png');
margin-left: 15px;
}
.linkedin-hover {
background-image: url('images/linkedin-hover.png');
margin-left: 15px;
}
.social-slide:hover {
background-position: 0px -48px;
box-shadow: 0px 0px 4px 1px rgba(0,0,0,0.8);
}
.social-slide{
height: 35px;
width: 38px;
float:left;
-webkit-transition: all ease 0.3s;
-moz-transition: all ease 0.3s;
-o-transition: all ease 0.3s;
-ms-transition: all ease 0.3s;
transition: all ease 0.3s;
}
Update: rewritten my answer completely.
You shouldn't use float:left when you want your content to be centered.
<div class="footer-col col-sm-4">
<h4 class="connect">Connect With Us</h4>
<ul>
<li><span class="twitter-hover social-slide"></span></li>
<li><span class="facebook-hover social-slide"></span></li>
<li><span class="linkedin-hover social-slide"></span></li>
</ul>
</div>
css:
.footer-col h4 {
text-align: center;
}
.footer-col ul {
list-style: none;
text-align: center;
}
.footer-col li {
display: inline;
}
.social-slide {
display: inline-block;
height: 35px;
width: 38px;
line-height: 35px;
margin-left: 15px;
/* don't use float: left! */
}
.social-slide:first-child {
margin-left: 0;
}
.twitter-hover { background-image: url('images/twitter-hover.png'); }
.facebook-hover { background-image: url('images/facebook-hover.png'); }
.linkedin-hover { background-image: url('images/linkedin-hover.png'); }
if you also use bootstrap latest then you use this class
col-sm-offset-......12
you don't know what size of your device you adjust self` col-sm-offset........12345 up to12
for more detail read out
https://getbootstrap.com/examples/grid/
Here is the fiddle
https://jsfiddle.net/brunocoder/ozgntcm2/1/
First of all there is one extra closing div in your footer tag.
You need to use bootstrap offset property to centralize your column. Here is the link http://getbootstrap.com/css/#grid
So your code should be something like this.
Modified HTML
<div class="content">
</div>
<footer class="footer">
<div class="container">
<div class="row">
<div class="footer-col col-sm-4 col-md-4 col-lg-4 col-md-offset-4">
<h4 class="connect">Connect With Us</h4>
<div class="twitter-hover social-slide"></div>
<div class="facebook-hover social-slide"></div>
<div class="linkedin-hover social-slide"></div>
</div>
</div>
</div>
</footer>
Use bootstrap in every section of your code, like if you have used div inside the div , use bootstrap to align them also as if you not then it will not align themselves according to the screen size.
<footer class="footer">
<div class="container">
<div class="row">
<div class="footer-col col-sm-4 col-md-4 col-lg-4 col-md-offset-4">
<h4 class="connect">Connect With Us</h4>
<a href="https://twitter.com/official_gapc" target="_blank" title="Follow us on Twitter">
<div class="twitter-hover social-slide col-sm-4">
</div>
</a>
<a href="https://www.facebook.com/pages/Governor-Andres-Pascual-CollegeNavotas-City/344134628983014?fref=ts" target="_blank" title="Like us on Facebook">
<div class="facebook-hover social-slide col-sm-4">
</div>
</a>
<a href="https://www.linkedin.com/edu/governor-andres-pascual-college-in-navotas-city-39345" target="_blank" title="Join us on Linkedin">
<div class="linkedin-hover social-slide col-sm-4">
</div>
</a>
</div>
<div class="footer-col col-sm-4 col-md-4 col-lg-4 col-md-offset-4"></div>
<div class="footer-col col-sm-4 col-md-4 col-lg-4 col-md-offset-4"></div>
</div>
</div>
</footer>
place anything you want to place in two div below or remain as it is, might it will help you to make responsive footer.

bootstrap: slim vertical element with full height

I would like to have a collapsible sidebar in bootstrap.
For this I' d like to have a slim element between the content and the sidebar toggles the visibility of the sidebar (display property). See the example below:
https://jsfiddle.net/zaao8Lqb/1/
Instead of the border (as in the fiddle), I' d like to have an element. How would I do that?
The solution is a simple div with full height. The total solution of a collapsible sidebar:
https://jsfiddle.net/c2bgkbzL/1/
html,
body {
height: 100%;
}
.fill {
height: 100%;
min-height: 100%;
}
#content {
background-color: AliceBlue;
height: 100%;
padding-left: 0;
}
#sidebar {
background-color: DarkGray;
height: 100%;
padding: 3px;
}
#collapseme{
background-color: black;
width: 10px;
height: 100%;
float: left;
}
Here is the code to do it. Can find fiddle at https://jsfiddle.net/qaisarnadeem/zzs94oc1/
<body>
<div class="container-fluid fill">
<div class="row fill">
<div class="col-lg-2 col-md-4 col-xs-4" id="sidebar">
<h4>
Sidebar
</h4>
</div>
<div class="pull-left vertical-elem"></div>
<div class="col-lg-10 col-md-6 col-xs-6 text-center" id="content">
<h3>
Content
</h3>
</div>
</div>
</div>
</body>
here is css for class vertical-elem
.vertical-elem{
height:100%;
width:6px;
background-color:blue;
}

Bootstrap: two column centered

I'm trying to have a two-column centered layout with Bootstrap 3.1.
I've read this: How do I center a Bootstrap div with a 'spanX' class?, but the content is stil aligned to the left. Here is my HTML:
<div class="row">
<div class="center">
<div class="col-lg-3 gauche">
Left div
</div>
<div class="col-lg-5 corps">
Right div
</div>
</div>
</div>
And my CSS:
body
{
padding: 0;
margin: 0;
}
.corps
{
background-color: white;
}
.contenu
{
margin-top: 5em;
margin-bottom: 1em;
background-color: white;
padding: 1.2em;
padding-left: 1.5em;
}
.center
{
float: none;
margin-left: auto;
margin-right: auto;
}
.gauche
{
background-color: #e6e6e6;
min-height: 200px;
}
Result is here: http://i.imgur.com/5nhZ2WS.png
You would want to use a column offset class. If you are using a stock build of Bootstrap all of the column classes need to add up to 12. Your col-lg-3 and col-lg-5 only add up to 8 so adding a col-lg-offset-2 should fix you up to center. Also, bootstrap has a built in centering class container i personally would use that. See below code:
<div class="container">
<div class="row">
<div class="col-lg-3 col-lg-offset-2 gauche">
Left div
</div>
<div class="col-lg-5 corps">
Right div
</div>
</div>
</div>
Add a container, remove the center div and add two blank col-lg-2 on either side so it adds up to 12 columns:
<div class="container">
<div class="row">
<div class="col-lg-2">
</div>
<div class="col-lg-3 gauche">
Left div
</div>
<div class="col-lg-5 corps">
Right div
</div>
<div class="col-lg-2">
</div>
</div>
</div>
For a scalable solution I recommend:
HTML:
<div class="row">
<div class="center">
<div class="col-lg-3 gauche">Left div</div>
<div class="col-lg-5 corps">Right div</div>
</div>
</div>
SCSS:
.center {
display: flex;
flex-direction: row;
justify-content: center;
.col-* {
display: inline-block;
margin-left: -2px; /* Adjust the value of marging work best with your context */
float: none;
}
}
Now it won't matter how many columns (or types of columns) you put in <div class="center"></div>
Try
.row {
margin:0px auto;
}