How to add margin between elements in side container without pushing to next row
How to add margin between elements in side container without pushing to next row
I have 3 items which are wrapped inside a container. I have added back ground color and padding to them.
Now When I want add some margin between them , it is shifting to next row.
.div-category{
background-color: #2274A5;
padding-left: 50px;
padding-right: 50px;
padding-top: 50px;
padding-bottom: 100px;
border-radius: 3px;
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.14);
color: whitesmoke;
//margin-right: 10px; Shifts line to next row.
}
JsFiddle
@import url('https://fonts.googleapis.com/css?family=Baloo+Bhaina');
/* GLOBAL STYLES
-------------------------------------------------- */
/* Padding below the footer and lighter body text */
body {
padding-top: 3rem;
padding-bottom: 3rem;
color: #231123;
background-color: #F4E04D;
}
/* MARKETING CONTENT
-------------------------------------------------- */
/* Center align the text within the three columns below the carousel */
.marketing .col-lg-4 {
margin-bottom: 1.5rem;
text-align: center;
}
.marketing h2 {
font-weight: 400;
}
.marketing .col-lg-4 p {
margin-right: .75rem;
margin-left: .75rem;
}
.div-category{
background-color: #2274A5;
padding-left: 50px;
padding-right: 50px;
padding-top: 50px;
padding-bottom: 100px;
border-radius: 3px;
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.14);
color: whitesmoke;
}
You need to change your structure a bit, here is updated fiddle and little margin like it should work then add one more div inside and apply margin to that .inside-margin class it is because you have utilised 12 columns of grid and then you are trying to apply margin and because entire space of screen has been utilised by 12 columns it lacks space and wraps to new row. you can change col-lg-4 to col-lg-3 and then try to give margin.<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<!-- /.col-lg-4 -->
<!-- /.col-lg-4 -->
<!-- /.col-lg-4 -->
</div><!-- /.row -->
</div>
Yes @charankumar, Need them in same row after adding margin
– Simsons
Jul 3 at 8:51
@Simsons do you want margin in right or bottom??
– לבני מלכה
Jul 3 at 8:56
I want the margin to the right..
– Simsons
Jul 3 at 8:57
Have you looked into this (Bootstrap built-in spacing) or this (adding margin to a column in Bootstrap)?
– James Whiteley
Jul 3 at 9:08
3 Answers
3
---
</div>
---
</div>
---
</div> .col-lg-4 .div-category{
margin: 0 20px;
}@import url('http://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css');
/* GLOBAL STYLES
-------------------------------------------------- */
/* Padding below the footer and lighter body text */
body {
padding-top: 3rem;
padding-bottom: 3rem;
color: #231123;
background-color: #F4E04D;
}
/* MARKETING CONTENT
-------------------------------------------------- */
/* Center align the text within the three columns below the carousel */
.marketing .col-lg-4 {
margin-bottom: 1.5rem;
text-align: center;
}
.marketing h2 {
font-weight: 400;
}
.marketing .col-lg-4 p {
margin-right: .75rem;
margin-left: .75rem;
}
.div-category{
background-color: #2274A5;
padding-left: 50px;
padding-right: 50px;
padding-top: 50px;
padding-bottom: 100px;
border-radius: 3px;
box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.14);
color: whitesmoke;
}
.col-lg-4 .div-category{
margin: 0 20px;
}
</div><!-- /.col-lg-4 -->
</div><!-- /.col-lg-4 -->
</div><!-- /.col-lg-4 -->
</div><!-- /.row -->
</div>
</div>
.inside-margin{ margin:0 5px; }
That still shifts it to next row. Please have a look at the jsFiddle or snipper.
– Simsons
Jul 3 at 9:00
you are viewing in medium device, you need to add extra col-md-4 and col-sm-4 along with col-lg-4, i have edited my code
– charan kumar
Jul 3 at 9:01
Thats not the solution . It will squeeze the container too narrow.
– Simsons
Jul 3 at 9:01
@Simsons you can do one thing. wrap the content of each block in another div and apply padding to that div. it will add space between each block items. and also apply background color to that div only
– Umang Patel
Jul 3 at 9:07
@Simsons have a look at this fiddle jsfiddle.net/to5pzqLg and let me know if it serves your purpose.
– Umang Patel
Jul 3 at 9:17
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
you want 3 divs in same row?
– charan kumar
Jul 3 at 8:50