Twitter Bootstrap 3 : margins in row - twitter-bootstrap-3

I'm starting with Bootstrap 3 and I have already some problems. Let me explain why.
Below my goal (photoshop draft for 970px container, 30px gutter, 80px columns) :
To code this template with bootstrap 3, I have defined this code :
<div class="row">
<!-- LEFT COLUMN -->
<div class="col-md-6" id="colonne_gauche">
<section class="col-md-12">
<div class="row">
<!-- FAVORIS 1 -->
<article class="col-md-6" id="div-favorite-1">
<h2>Favoris 1</h2>
</article>
<!-- FAVORIS 2 -->
<article class="col-md-6" id="div-favorite-2">
<h2>Favoris 2</h2>
</article>
</div>
</section>
</div>
<!-- RIGHT COLUMN -->
<div class="col-md-6" id="colonne_droite">
<section class="col-md-12">
<div class="row">
<!-- FAVORIS 3 -->
<article id="div-favorite-3">
<h2>Favoris 3</h2>
</article>
</div>
</section>
</div>
</div>
Which gives me this result :
I have defined colors to have a look on blocks :
Green : left column
Gold : right column
AS you can see there is no margin between "Favoris 1" & "Favoris 2". These 2 blocks takes full width without padding and margin.
If you have a look on my draft, you can see that normally it should have a standard margin between these two blocks egual to standard space between two columns, so in my case 30px.
I tried to define for each of them (Favoris 1 : margin-right:15px and Favoris 2 : margin-left:15px) but the width of these blocks are not updated in function of this margin definition.
My goal is to obtain this result, of course without to have defined in the CSS file the width of these blocks :
So I'm looking for your help to find a way to solve this problem.
Thanks a lot for your feedbacks.

Do it like this. See the snippet in full page. Columns should not be child elements of col-*-*. Columns should always be in .row.
<div class="row">
<!-- LEFT COLUMN -->
<div class="col-md-6" id="colonne_gauche">
<div class="row">
<!-- FAVORIS 1 -->
<section class="col-md-6">
<article id="div-favorite-1">
<h2>Favoris 1</h2>
</article>
</section>
<!-- FAVORIS 2 -->
<section class="col-md-6">
<article id="div-favorite-2">
<h2>Favoris 2</h2>
</article>
</section>
</div>
<div class="row">
<!-- ACTUALITE 2 -->
<section class="col-md-12">
<article id="div-actualite-1">
<h2>Actualite 1</h2>
</article>
</section>
</div>
</div>
<!-- RIGHT COLUMN -->
<div class="col-md-6" id="colonne_droite">
<div class="row">
<!-- FAVORIS 3 -->
<section class="col-md-12">
<article id="div-favorite-3">
<h2>Favoris 3</h2>
</article>
</section>
</div>
</div>
</div>
#colonne_gauche {
background-color: green;
}
#colonne_droite {
background-color: yellow;
}
#div-favorite-1,
#div-favorite-2,
#div-favorite-3,
#div-actualite-1 {
color: #fff;
min-height: 200px;
}
#div-favorite-1 {
background-color: blue;
}
#div-favorite-2 {
background-color: orange;
}
#div-favorite-3 {
background-color: red;
}
#div-actualite-1 {
background-color: purple;
}
h2 {
padding: 0;
margin: 0;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<!-- LEFT COLUMN -->
<div class="col-md-6" id="colonne_gauche">
<div class="row">
<!-- FAVORIS 1 -->
<section class="col-md-6">
<article id="div-favorite-1">
<h2>Favoris 1</h2>
</article>
</section>
<!-- FAVORIS 2 -->
<section class="col-md-6">
<article id="div-favorite-2">
<h2>Favoris 2</h2>
</article>
</section>
</div>
<div class="row">
<!-- ACTUALITE 2 -->
<section class="col-md-12">
<article id="div-actualite-1">
<h2>Actualite 1</h2>
</article>
</section>
</div>
</div>
<!-- RIGHT COLUMN -->
<div class="col-md-6" id="colonne_droite">
<div class="row">
<!-- FAVORIS 3 -->
<section class="col-md-12">
<article id="div-favorite-3">
<h2>Favoris 3</h2>
</article>
</section>
</div>
</div>
</div>

Related

Make the space between the columns small inside the card

I have this shape and want to approximate the distance between each column, meaning I want to approximate the distance between each blue piece, how can I do that_?
Card.vue:
<template>
<div>
<div class="card d-inline-flex" style="width: 40rem; height:7rem; ">
<div class="row background">
<div class="col">
<div class="p-5 bg-info rounded-left ">Flex item 1</div>
</div>
<div class="col">
<div class="p-5 bg-info rounded-0 ">Flex item 1</div>
</div>
<div class="col">
<div class="p-5 bg-info rounded-right">Flex item 1</div>
</div>
</div>
</div>
</div>
</template>
<script></script>
<style>
.background {
background-color: #dcdcdc;
}
.d {
margin-left: 4px;
}
</style>
The space is there because bootstrap has a padding-left and padding-right of 15px for the class col pre-defined. So to get the space that you want, just add a custom class to your div and mess around with padding-left and padding-right. But don't forget to use "!important" as you want to override the style defined by Bootstrap. Here is an Example :-
<template>
<div>
<div class="card d-inline-flex" style="width: 40rem; height:7rem; ">
<div class="row background">
<div class="col a">
<div class="p-5 bg-info rounded-left ">Flex item 1</div>
</div>
<div class="col a">
<div class="p-5 bg-info rounded-0 ">Flex item 1</div>
</div>
<div class="col a">
<div class="p-5 bg-info rounded-right">Flex item 1</div>
</div>
</div>
</div>
</div>
</template>
<script></script>
<style>
.background {
background-color: #dcdcdc;
}
.d {
margin-left: 4px;
}
.a {
padding-left:0 !important!;
padding-right:0 !important!;
}
</style>
Here i used a custom class called a, just mess around with padding-left to get the space you need.

Owl Carousel 2 not showing navigation dots

I am trying out owl-carousel 2.3.4 (https://owlcarousel2.github.io/OwlCarousel2/) - all is fine except that the navigation dots are not showing. They aren't images so I don't know why it's not loading. I was wondering what I am doing wrong. I can see that it's working here (https://codepen.io/Ittisafur/pen/ggqzwY) but this uses owl-carousel version 1.3.3.
<style type="text/css">
.owl-carousel div.content
{
box-sizing:border-box;
background-color:#fff;
border:1px solid red;
min-height:150px;
padding:10px;
margin:10px;
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.min.css">
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>
<div class="owl-carousel">
<div class="content">
<p>Text 1</p>
</div>
<div class="content">
<p>Text 2</p>
</div>
<div class="content">
<p>Text 3</p>
</div>
<div class="content">
<p>Text 4</p>
</div>
<div class="content">
<p>Text 5</p>
</div>
<div class="content">
<p>Text 6</p>
</div>
<div class="content">
<p>Text 7</p>
</div>
<div class="content">
<p>Text 8</p>
</div>
<div class="content">
<p>Text 9</p>
</div>
<div class="content">
<p>Text 10</p>
</div>
</div>
<script>
$(document).ready(function()
{
$('.owl-carousel').owlCarousel(
{
center:false,
items:5,
loop:true,
margin:10,
dots: true,
autoplay:true
});
});
</script>
Add the owl-theme class to your container:
<div class="owl-carousel owl-theme">
Add the owl-theme class to your container:
<div class="owl-carousel owl-theme">
<div class="pr-2 pl-2 item"> </div>
<div class="pr-2 pl-2 item"> </div>
</div>

Web page layout with bootstrap-4.1.2

My goal is to get like this.
I use bootstrap-grid.min.css from bootstrap-4.1.2
What do I do wrong? My code
<div class="wrapper d-flex flex-column" style="min-height: 100vh;">
<section class="main d-flex flex-grow-1">
<div class="container-fluid d-flex align-items-stretch">
<div class="row">
<div class="col-md-3">
<div class="menu">
Aside
</div>
</div>
<div class="col-md-9">
<div class="text">
Main
</div>
</div>
</div>
</div>
</section>
<footer class="footer">
Footer
</footer>
</div>
You need to make changes in your structure. I have made some changes for you, please see if it serves the purpose.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet" />
<header class="footer">
Header
</header>
<div class="wrapper d-flex flex-column" style="min-height: calc(100vh - 24px);">
<section class="main d-flex flex-grow-1">
<div class="container-fluid">
<div class="row" style="height:100%;">
<div class="col col-md-3" style="background-color:blue;">
<div class="menu">
Aside
</div>
</div>
<div class="col col-md-9" style="background-color:pink;">
<div class="text">
Main
</div>
</div>
</div>
</div>
</section>
<footer class="footer">
Footer
</footer>
</div>

Bootstrap grid with 8 divs of varying height

I'm trying to use bootstrap grid system to arrange 8 boxes of equal width and simiar but varying heights. I want the layout to do either 2x2x2x2, 3x3x2, 4x4 - responsive to screen size.
I can do the responsive layout but the issue I have is getting them to format properly so it doesn't leave whitespace above some of the boxes in some of the arrangements. I've tried varying combinations of clearfix but can't make it work. Is it possible? I assume so! Here's what it looks like:
<div class="container">
<div class="row">
<div class="col-md-3 col-sm-4 col-xs-6">
<div class="feature-icon">
<img class="img-responsive" src="images/places.png" alt="mockup" />
</div>
<h4>TITLE</h4>
<p>Some text of vaying length .... .... .... ..... ....</p>
</div> <!-- /.block 1 -->
<div class="col-md-3 col-sm-4 col-xs-6">
<div class="feature-icon">
<img class="img-responsive" src="images/places.png" alt="mockup" />
</div>
<h4>TITLE</h4>
<p>Some text of vaying length .... .... .... ..... ....</p>
</div> <!-- /.block 2 -->
<div class="col-md-3 col-sm-4 col-xs-6">
<div class="feature-icon">
<img class="img-responsive" src="images/places.png" alt="mockup" />
</div>
<h4>TITLE</h4>
<p>Some text of vaying length .... .... .... ..... .... .... ..... ......</p>
</div> <!-- /.block 3 -->
<div class="col-md-3 col-sm-4 col-xs-6">
<div class="feature-icon">
<img class="img-responsive" src="images/places.png" alt="mockup" />
</div>
<h4>TITLE</h4>
<p>Some text of vaying length .... .... .... ..... ....</p>
</div> <!-- /.block 4 -->
<div class="clearfix visible-md-block visible-lg-block"></div>
<div class="col-md-3 col-sm-4 col-xs-6">
<div class="feature-icon">
<img class="img-responsive" src="images/places.png" alt="mockup" />
</div>
<h4>TITLE</h4>
<p>Some text of vaying length .... .... </p>
</div> <!-- /.block5 -->
<div class="col-md-3 col-sm-4 col-xs-6">
<div class="feature-icon">
<img class="img-responsive" src="images/places.png" alt="mockup" />
</div>
<h4>TITLE</h4>
<p>Some text of vaying length .... .... .... ..... ....</p>
</div> <!-- /.block 6 -->
<div class="col-md-3 col-sm-4 col-xs-6">
<div class="feature-icon">
<img class="img-responsive" src="images/places.png" alt="mockup" />
</div>
<h4>TITLE</h4>
<p>Some text of vaying length .... .... .... ..... .... .... .... ....</p>
</div> <!-- /.block 7 -->
<div class="col-md-3 col-sm-4 col-xs-6">
<div class="feature-icon">
<img class="img-responsive" src="images/places.png" alt="mockup" />
</div>
<h4>TITLE</h4>
<p>Some text of vaying length .... .... .... ....</p>
</div> <!-- /.block 8 -->
</div><!-- /.row -->
</div><!-- /.container -->
You can use flexbox to get the layout you want. It's not masonry style, but it fixes the blank spaces that you get when an element can't float all the way to the left side of the page. With flexbox you get the first case from your image that you linked in a comment, so elements in the next row will start below the highest element from the previous row.
Just wrap all of the columns inside a div like this (it might work if you just put flexbox on "container" div or "row" but I'm not sure):
html:
<div class="container">
<div class="row">
<div class="flex-wrapper">
<div class="col-md-3 col-sm-4 col-xs-6">
<div class="feature-icon">
<img class="img-responsive" src="images/places.png" alt="mockup" />
</div>
<h4>TITLE</h4>
<p>Some text of vaying length .... .... .... ..... ....</p>
</div> <!-- /.block 1 -->
<div class="col-md-3 col-sm-4 col-xs-6">
<div class="feature-icon">
<img class="img-responsive" src="images/places.png" alt="mockup" />
</div>
<h4>TITLE</h4>
<p>Some text of vaying length .... .... .... ..... ....</p>
</div> <!-- /.block 2 -->
....etc....
</div>
</div>
</div>
css:
.flex-wrapper {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
}
It works in all browsers except for IE10 and below, but there's a polyfill for those browsers as well so you should be good to go.
EDIT:
You could use the solution that was posted in a comment on another answer to get the masonry style (bootsnipp.com/snippets/OeVbl), and if you want to avoid ems you could use column-count to manipulate the number of columns. If you want a different number of columns on different resolutions just put a different column count in a media query.
.row {
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
-moz-column-gap: 15px;
-webkit-column-gap:15px;
}

How to make image in middle in bootstrap

I want to align 5 images in the page, i want to put three images in row in the middle of the page and in the next row i want to put two images below those in the row in the middle but it is not happening,Can anyone help me to sort out
<div class="top container">
<div class="row">
<section class="col-md-4">
<img src="images/1.png">
</section>
<section class="col-md-4">
<img src="images/1.png">
</section>
<section class="col-md-4">
<img src="images/1.png">
</section>
</div>
</div>
<br/>
<br/>
<div class="top1 container">
<div class="row">
<section class="col-md-4">
<img src="images/2.png">
</section>
<section class="col-md-4">
<img src="images/2.png">
</section>
</div>
</div>
use:
<div class="top container">
<div class="row">
<section class="col-md-4 col-md-offset-4">
<img src="images/1.png">
</section>
<section class="col-md-4">
<img src="images/1.png">
</section>
<section class="col-md-4">
<img src="images/1.png">
</section>
</div>
</div>
<br/>
<br/>
<div class="top1 container">
<div class="row">
<section class="col-md-4 col-md-offset-4">
<img src="images/2.png">
</section>
<section class="col-md-4">
<img src="images/2.png">
</section>
</div>
</div>