I have a container with several rows. And in each row I have several columns.
I would like to increase the space between each column
<div class="main" style="margin-bottom:0px">
<div class="container">
<div class="row">
<div class="col-md-4 card ">
Colonne 1
</div>
<div class="col-md-4 card">
Colonne 2
</div>
<div class="col-md-4 card">
Colonne 3
</div>
</div>
</div>
<div>
instead usind col-x while you want the same width, you may only use col and they will span the row with an equal width and let you add horizontal margins .
example
.card {
border: solid;/* to show where they are*/
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="main" style="margin-bottom:0px">
<div class="container">
<div class="row">
<div class="col card mx-1 ">
Colonne 1
</div>
<div class="col card mx-1">
Colonne 2
</div>
<div class="col card mx-1">
Colonne 3
</div>
</div>
</div>
<div>
ressources :
https://getbootstrap.com/docs/4.0/utilities/spacing/
t - for classes that set margin-top or padding-top
b - for classes that set margin-bottom or padding-bottom
l - for classes that set margin-left or padding-left
r - for classes that set margin-right or padding-right
x - for classes that set both *-left and *-right
y - for classes that set both *-top and *-bottom
blank - for classes that set a margin or padding on all 4 sides of the element
which is the reason of the mx-1 class added
https://getbootstrap.com/docs/4.0/layout/grid/
where you can find col class which is used to auto-size the columns , if all box receive the col class, they should be of equal width.
<div class="container">
<div class="card-deck text-center mb-5">
<div class="card">
<div class="card-body">
<h5 class="card-title">test</h5>
<hr class="w-50">
<p class="text-left ml-3 mt-3"></p>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">test</h5>
<hr class="w-50">
<p class="text-left ml-3 mt-3"></p>
</div>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">test</h5>
<hr class="w-50">
<p class="text-left ml-3 mt-3"></p>
</div>
</div>
</div>
</div>
I used this with cards, I think this what you're looking for.
Keep me updated! ;)
Use CSS margin property.
.card {
margin: 0px 10px;
}
Working example
.card {
margin: 0px 10px;
}
<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="main" style="margin-bottom:0px">
<div class="container">
<div class="row">
<div class="col col-md-4 card ">
Colonne 1
</div>
<div class="col col-md-4 card">
Colonne 2
</div>
<div class="col col-md-4 card">
Colonne 3
</div>
</div>
</div>
<div>
Bootstrap columns have no space between.
Make another div inside by default column 4 has 15px padding which means if you make div inside it will leave space on both left and right side.
<div class="col-sm-4">
<div class="inner">
Your Content Here
</div>
</div>
Related
I have 6 items to display...
On a cell phone (xs) I want two rows of three items to display and on bigger than cell phone size, I'd like to see all six on the same row.
I tried...
<div class='row'>
<div class='col-xs-4 col-sm-2'>1</div>
<div class='col-xs-4 col-sm-2'>2</div>
<div class='col-xs-4 col-sm-2'>3</div>
<div class='col-xs-4 col-sm-2'>4</div>
<div class='col-xs-4 col-sm-2'>5</div>
<div class='col-xs-4 col-sm-2'>6</div>
</div>
This displays fine on a large screen with all 6 items but when viewing in the xs screen (phone) it just shows 6 separate rows.
I want to see
1 2 3 4 5 6
on large screen and
1 2 3
4 5 6
on xs screens.
Any ideas? Thanks
col-xs- was for Bootstrap-3. For Bootstrap-4, for the smallest screen, use col-4, so your code would look like:
<div class='row'>
<div class='col-4 col-sm-2'>1</div>
<div class='col-4 col-sm-2'>2</div>
<div class='col-4 col-sm-2'>3</div>
<div class='col-4 col-sm-2'>4</div>
<div class='col-4 col-sm-2'>5</div>
<div class='col-4 col-sm-2'>6</div>
</div>
That should give you three columns on a smartphone and six columns on anything else.
Update for space between the elements:
If you want some spacing between your elements, you could put another column inside your first column, and then put your information in that column. The normal gutter is 15px wide, and with two gutters, the space between columns would be 30px. If that’s too wide, you can customize it as explained in this answer: https://stackoverflow.com/a/27005684/1011984
As an example, I revised my first solution to include a 5px gutter (so 10px total). I also put some spacing between the elements on a smartphone, and a block below the elements to illustrate that you can get right next to them, if you want. If you don’t, just delete the mb-n3 margin on the row.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<style>
.row.gutter {
margin-left: -5px;
margin-right: -5px
}
[class*="col-"].gutter {
padding-left: 5px;
padding-right: 5px;
}
</style>
<div class="container mt-5">
<div class='row mb-n3 gutter'>
<div class='col-4 col-sm-2 mb-3 gutter text-center text-light '>
<div class="col bg-primary">1</div>
</div>
<div class='col-4 col-sm-2 mb-3 gutter text-center text-light '>
<div class="col bg-secondary">2</div>
</div>
<div class='col-4 col-sm-2 mb-3 gutter text-center text-light '>
<div class="col bg-success">3</div>
</div>
<div class='col-4 col-sm-2 mb-3 gutter text-center text-light '>
<div class="col bg-danger">4</div>
</div>
<div class='col-4 col-sm-2 mb-3 gutter text-center text-light '>
<div class="col bg-warning">5</div>
</div>
<div class='col-4 col-sm-2 mb-3 gutter text-center text-light '>
<div class="col bg-info">6</div>
</div>
</div>
</div>
<div class="container-fluid bg-dark text-light" style="height: 200px;">
<p>A filler div to show that there can be a space between the rows of elements on a small screen, but no space below the row, if you don’t want one.</p>
</div>
use col-x instead of col-xs-x. It was depreciated on bootstrap 4.
<div class="row">
<div class="col-4 col-sm-2">1</div>
<div class="col-4 col-sm-2">2</div>
<div class="col-4 col-sm-2">3</div>
<div class="col-4 col-sm-2">4</div>
<div class="col-4 col-sm-2">5</div>
<div class="col-4 col-sm-2">6</div>
</div>
I am using bootstrap for my layout.
<div class="container-fluid footer">
<div class="row p-4">
<div class="col-lg-3 d-flex flex-column justify-content-center align-items-md-center">
<h3>Company</h3>
<div class="mt-3 text-left">
<div class="box">
<p class="link-router" routerLink="/careers">Careers</p>
</div>
<div class="box">
<p class="link-router" routerLink="/about-us"><a>About</a></p>
</div>
<div class="box">
<p class="link-router" routerLink="/contact-us">Contract us</p>
</div>
</div>
</div>
</div>
</div>
Here is for example one column in my row.The content of that column should be on the left ( default )
and centered vertically so for that i used
d-flex flex-column justify-content-center
but now on smaller devices i want the content to be in the center, not in on the left.
So tried with the class
align-items-md-center
to tell that the content should be in the middle on > 768px devices.But then the whole time the content is in the middle not only on md devices.
How shoould i do that ?
Youn need to use align-items-center align-items-md-start. You have centring by default and you reset the center on md (> 768px)
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" >
<div class="container-fluid footer">
<div class="row p-4">
<div class="col-lg-3 d-flex flex-column justify-content-center align-items-center align-items-md-start">
<h3>Company</h3>
<div class="mt-3 text-left">
<div class="box">
<p class="link-router" routerLink="/careers">Careers</p>
</div>
<div class="box">
<p class="link-router" routerLink="/about-us"><a>About</a></p>
</div>
<div class="box">
<p class="link-router" routerLink="/contact-us">Contract us</p>
</div>
</div>
</div>
</div>
</div>
I added a new advertising block to the header visible here: https://musebycl.io/test_page. This made the navigation block move to the far right. I can't figure out why that is happening, even though these elements are supposedly in separate divs.
How do I modify the header ad or the navigation HTML/CSS to bring the navigation back to its normal position as visible on the home page (https://musebycl.io/)?
Your framework applies flex rules on the .row element that push your navigation block to the right, as it has no defined width.
Try to move your add .block-content one level up in your rows into div.container.py-2.row
with this html it works:
<div class="container py-2">
<div class="row justify-content-between align-items-center">
<div class="block-content">
<div
class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item">
...
</div>
</div>
<div class="col-auto">
<div class="row justify-content-between align-items-center">
<div class="col-auto">
<div class="region region-logo">
<div id="block-headerad"
class="block block-block-content block-block-content98569f6a-2644-4a93-a22a-d735717c7cda">
</div>
<div id="block-muse-sitebranding-3" class="block block-system block-system-branding-block">
<a href="/" rel="home" class="site-logo">
<img src="https://cdn.musebycl.io/compact-muse-logo.png" alt="Home">
</a>
</div>
</div>
</div>
<div class="col-auto d-none d-lg-block">
<div class="region region-header-primary-menu">
...
</div>
</div>
</div>
</div>
<div class="col-auto">
<div class="row justify-content-between align-items-center no-gutters">
<div class="col-auto d-none d-lg-block">
<div class="social-menu d-flex align-items-center">
...
</div>
<div class="col-auto">
<div id="user-action-menu" class="user-action-menu d-flex align-items-center">
...
</div>
</div>
<div class="d-lg-none">
...
</div>
</div>
</div>
</div>
</div>
You can create external CSS like
#advertising-nav-bar {
position: fixed;
top: 0px;
}
HTML :
<div id="advertising-nav-bar">
<!--content -->
</div>
You have to give your block-content a width.
Like:
.block-content{
width: 500px;
}
I need to implement a cartesian plane with Bootstrap 4 and Flex. The desired output is something like the following image:
The plane is composed by a 10x10 matrix. Moreover I need a row containing the x labels and a column showing the y labels.
Here you are my code:
<div class="d-flex p-2" style="border: 1px solid black; width: 40%; margin-bottom: 50px;">
<div class="d-flex flex-row">
<div class="p-2 align-items-stretch">1</div>
</div>
<div class="d-flex flex-column">
<div class="p-2">1</div>
<div class="p-2">2</div>
<div class="p-2">3</div>
<div class="p-2">4</div>
<div class="p-2">5</div>
<div class="p-2">6</div>
<div class="p-2">7</div>
<div class="p-2">8</div>
<div class="p-2">9</div>
<div class="p-2">10</div>
<div class="p-2 align-items-stretch">11</div>
</div>
<div class="d-flex flex-column">
<div class="p-2">1</div>
<div class="p-2">2</div>
<div class="p-2">3</div>
<div class="p-2">4</div>
<div class="p-2">5</div>
<div class="p-2">6</div>
<div class="p-2">7</div>
<div class="p-2">8</div>
<div class="p-2">9</div>
<div class="p-2">10</div>
</div>
<!-- the same for the other 8 rows -->
</div>
And the associated css:
.p-2 {
border: 1px solid lightgray;
}
.p-2:before {
content:'';
float:left;
padding-top:100%;
}
The actual result is:
I have two problems:
the row number 11 should be stretched until the last column;
the grid items should adapt their size according to the available space
of the container.
How I can reach these goals? Thank you
You can use the Bootstrap grid like this...
Demo: https://www.codeply.com/go/sQA6tvHiZh
<div class="container text-center">
<div class="row">
<div class="col-md-8 mx-auto">
<div class="row">
<div class="col-1">y</div>
<div class="col-11">
<div class="row">
<div class="col">1
</div>
<div class="col">2
</div>
<div class="col">3
</div>
<div class="col">4
</div>
<div class="col">5
</div>
<div class="col">6
</div>
<div class="col">7
</div>
<div class="col">8
</div>
<div class="col">9
</div>
<div class="col">10
</div>
</div>
<!--/row-->
9 more row ...
<div class="row">
<div class="col">x
</div>
</div>
</div>
</div>
</div>
</div>
<!--container-->
</div>
My CSS isn't picking up my different columns. They are stacked on top of each other. I want each of them each to span 4 columns of the same row.
<div class="container">
<div class="row">
<div class="col-md-4" id="directionsPanel1">
<h3 class="directions-discription" id="directions-info1"></h3>
</div>
<div class="col-md-4" id="directionsPanel2">
<h3 class="directions-discription" id="directions-info2"></h3>
</div>
<div class="col-md-4" id="directionsPanel3">
<h3 class="directions-discription" id="directions-info3"></h3>
</div>
How about this using floats. You can apply the float which is the pull-left helper class to the div.col-md-4 and then they won't stack upon each other.
Updated JS fiddle but you shouldn't need to float left in the CSS, couldn't get JS fiddle to pull bootstrap stuff. http://jsfiddle.net/4xEPr/7/
<div class="container">
<div class="row">
<div class="col-md-4 pull-left" id="directionsPanel1">
<h3 class="directions-discription" id="directions-info1"></h3>
</div>
<div class="col-md-4 pull-left" id="directionsPanel2">
<h3 class="directions-discription" id="directions-info2"></h3>
</div>
<div class="col-md-4 pull-left" id="directionsPanel3">
<h3 class="directions-discription" id="directions-info3"></h3>
</div>
AND CSS
div.col-md-4 {
border: 1px solid #333;
width: 200px;
background-color: red;;
}