I am using Bootstrap and trying to center 3 div blocks using the bootstrap 12 columns style. So each div takes up 4 columns. I want some spacing between these columns thus I added 10px margin to the right. This pushes down the 3rd div to the next row. How do I get my spacing and still keep all 3 columns on the same row?
HTML
<div class="container">
<div class="form-group col-sm-4 col-lg-4 cust_box">
<h3>Something</h3>
</div>
<div class="form-group col-sm-4 col-lg-4 cust_box">
<h3>Something</h3>
</div>
<div class="form-group col-sm-4 col-lg-4 cust_box">
<h3>Something</h3>
</div>
</div>
CSS
.cust_box{
margin-top: 15px;
margin-bottom:15px;
padding-left: 10px;
padding-right:10px;
background-color: #1A284B;
color: #fff;
height: 290px;
max-width:100%;
border: 1px solid #162444;
margin-right: 10px; /*Line that causes issue*/
}
Problem recreated in CodePen
Place your class cust_box inside the the column. The h3 has margin so that may also be interfering with your layout. You may also want to just use the row class instead of form-group.
See working Example Snippet. (colors added so you can see what's actually happening)
.cust_box {
margin: 15px 2.5px;
padding: 25px;
height: 290px;
max-width: 100%;
background-color: #1A284B;
color: #fff;
border: 1px solid #162444;
}
.cust_box h3 {
margin: 0;
}
.red {
border: 2px solid red;
}
.yellow {
background: yellow;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row yellow">
<div class="col-sm-4 red">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
<div class="col-sm-4 red">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
<div class="col-sm-4 red">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
</div>
</div>
Example without Color
.cust_box {
margin: 15px 2.5px;
padding: 25px;
height: 290px;
max-width: 100%;
background-color: #1A284B;
color: #fff;
border: 1px solid #162444;
}
.cust_box h3 {
margin: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
<div class="col-sm-4">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
<div class="col-sm-4">
<div class="cust_box">
<h3>Something</h3>
</div>
</div>
</div>
</div>
with the additional margin you are destroying the bootstrap grid system.
have you tried using padding instead of margin?
apart from this you can customize bootrap a lot!
have a look on this:
http://getbootstrap.com/customize/#grid-system
EDIT:
i looked at your code and saw your struggle:
use a inner div like this:
<div class="form-group col-sm-4 col-lg-4 cust_box">
<div class="inner">
<h3>Something</h3>
</div>
</div>
and use your style on the inner div:
.cust_box .inner{
margin-top: 15px;
margin-bottom:15px;
padding-left: 10px;
padding-right:10px;
background-color: #1A284B;
color: #fff;
height: 290px;
max-width:100%;
border: 1px solid #162444;
margin-right: 10px; /*should not be an issue anymore*/
}
Related
movie class has two column class.
But the two columns div do not fit in the movie div well.
there is a space on left and right
How to fit the two column div in the movie div well?
Image:
Try adding padding instead of margin. This is only solution. Thanks
.movie{
border: 1px solid lightgray;
border-radius: 20px;
overflow: hidden;
width: 33%;
/*margin: 2px 10px; */
padding: 2px 10px;
overflow: hidden;
}
You should create a new div to be a container for your movie card because your styles override the bootstrap structure for the columns.
HTML
<div class="col-12 col-md-6 col-lg-4">
<div class="movie">
<div class="column">
<div class="title"><?= $movie["title"] ?></div>
<div class="year">(<?= $movie["year"] ?>)</div>
<div class="box-office">
Box Office:
<?= $movie["box-office"] ?>
</div>
</div>
<div class="column">
<img width = "80%" src= "posters/<?= $movie["poster"]?>"
alt=“Poster” >
</div>
</div>
</div>
CSS
.movie {
border: 1px solid lightgray;
border-radius: 20px;
overflow: hidden;
margin: 1rem;
}
.column {
float: left;
width: 50%;
}
Please try this code:
<style>
.movie{
}
.inner-col {
border: 1px solid lightgray;
border-radius: 20px;
overflow: hidden;
/*margin: 2px 10px; */
overflow: hidden;
}
.column {
float: left;
width: 50%;
}
</style>
<body>
<div class="container">
<div class="row">
<?php foreach ($movies as $movie) { ?>
<div class="movie col-12 col-md-6 col-lg-4 ">
<div class="inner-col">
<div class="column">
<div class = "title"><?= $movie["title"] ?></div>
<div class = "year">(<?= $movie["year"] ?>)</div>
<div class = "box-office">Box Office: <?= $movie["box-office"] ?></div>
</div>
<div class = "column">
<img width = "80%" src= "posters/<?= $movie["poster"]?>" alt=“Poster” >
</div>
</div>
</div>
<?php } ?>
</div>
</div></body>
I'm try to do a footer with bootstrap and I need move a span element, this one is whitin of a column set up it with col-sm-4 class, How do I can move this one for instance 20px whitout affecting responsive design. Below I put a image about footer and the html structure and css. I appreciate any help.
<footer class="footer">
<div class="container-fluid">
<div class="row">
<div id="location" class="col-sm-4 col-xs-3">
<span>Location</span>
</div>
<div id="info" class="col-sm-4 col-xs-3">
<span>Info about me</span>
</div>
<div id="created" class="col-sm-4 col-xs-3">
<p>texto</p>
</div>
</div>
</div>
</footer>
css:
.footer{
position: fixed;
bottom:0%;
height: 100px;
width: 100%;
background-color: #2c3e50;
}
#location{
background-color: white;
height: 50px;
}
#info{
background-color: gray;
height: 50px;
}
#created{
background-color: blue;
height: 50px;
}
You can use <span style="padding-left:20px;">move space 20px</span>
It will not affect responsiveness
How to put banners side by side using HTML/CSS? Ideally with different sizes as shown below?
One simple way would be to display the banners inline-block, and assign them the required width.
.banner {
display: inline-block;
}
.banner-sm {
width: 32%;
}
.banner-lg {
width: 65%;
}
.banner {
height: 100px;
background: #DDD;
padding: 0; margin: 0;
}
<div class="row">
<div class="banner banner-lg"> </div>
<div class="banner banner-sm"> </div>
</div>
<div class="row">
<div class="banner banner-sm"> </div>
<div class="banner banner-sm"> </div>
<div class="banner banner-sm"> </div>
</div>
<div class="row">
<div class="banner banner-sm"> </div>
<div class="banner banner-lg"> </div>
</div>
Either use some grid system, or the bare CSS float property, pseudo example shown below:
.banner1 {
float: left;
width: 100px;
height: 20px;
margin: 4px;
border: 1px solid #777;
}
.banner2 {
float: left;
width: 200px;
height: 20px;
margin: 4px;
border: 1px solid #777;
}
.banner3 {
float: left;
width: 50px;
height: 20px;
margin: 4px;
border: 1px solid #777;
}
.clearfix {
clear: both;
}
<div class="banner1">banner</div>
<div class="banner1">banner</div>
<div class="clearfix"></div>
<div class="banner2">banner</div>
<div class="clearfix"></div>
<div class="banner3">banner</div>
<div class="banner3">banner</div>
<div class="banner3">banner</div>
<div class="banner3">banner</div>
<div class="clearfix"></div>
Good luck
You can use Twitter Bootstrap to get grid system and other useful layout functionality:
.row div {
height: 30px;
background: #aaa;
border: 1px solid #ddd;
}
* {
box-sizing: border-box;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='row'>
<div class='col-xs-8'></div>
<div class='col-xs-4'></div>
</div>
<div class='row'>
<div class='col-xs-4'></div>
<div class='col-xs-4'></div>
<div class='col-xs-4'></div>
</div>
<div class='row'>
<div class='col-xs-4'></div>
<div class='col-xs-8'></div>
</div>
<div class='row'>
<div class='col-xs-4'></div>
<div class='col-xs-8'></div>
<div class='col-xs-8'></div>
<div class='col-xs-4'></div>
</div>
If you are familiar with twitter-bootstrap then use its Grid system otherwise using inline-block will help you.
div {
border: 1px solid #ddd;
height: 200px;
margin: 5px;
display: inline-block;
box-sizing:border-box;
}
<section style="width:650px">
<div style="width:415px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:200px;"></div>
<div style="width:415px;"></div>
</section>
you can use CSS3 flex-box concept
.flex-container {
display: -webkit-flex;
display: flex;
width: 400px;
height: 250px;
background-color: lightgrey;
flex-direction:column;
}
.flex-item {
background-color: cornflowerblue;
width: calc(100% - 20px);
height: 100px;
margin: 10px;
display:flex;
justify-content:space-between;
}
.sub{
height:100%;
background:white;
box-sizing:border-box;
}
.one{
width:75%;
border:1px solid green;
}
.two{
width:25%;
border:1px solid red;
}
.subb{
width:33%;
background:white;
height:100%;
}
<div class="flex-container">
<div class="flex-item">
<div class="sub one">sub 1 </div>
<div class="sub two">sub 2 </div>
</div>
<div class="flex-item">
<div class="subb s3">sub 3 </div>
<div class="subb s4">sub 4 </div>
<div class="subb s5">sub 5 </div>
</div>
</div>
You can use Bootstrap to do this.
Bootstarp is a Powerful css framework which enables web developer's
to do stuff like these(dividing screens etc).
Bootstrap is very easy to learn and implement.
You can start Learning Bootstrap here
I know this was asked many times in SO but I can't find the answer for my question. I used bootstrap with this one and tried to have a two six columns in a row. It works as expected but what I want to achieve is that I wanted to out a gap between them. To see what I mean you can check it here.
I don't want to override the bootstrap cols here. I wanted to use only the added class which is survey-extra.
HTML
<div class="container">
<div class="row visit-redeem text-center">
<h5>Visit Site To Redeem</h5>
</div>
<div class="row">
<div class="col-xs-6 survey-extra">
<h5>FROM OUR SPONSORS</h5>
<span class="money-extra">$0.00</span>
</div>
<div class="col-xs-6 survey-extra">
<h5>FREEBIES</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
</div>
CSS
.survey-extra {
background: #1e90ff;
color: #fff;
padding: 5px;
border-radius: 10px;
text-transform: uppercase;
}
.visit-redeem {
background: #56a4da;
margin-top: 5px;
margin-bottom: 6px;
color: #fff;
padding: 5px;
border-radius: 20px 20px 0 0;
text-transform: uppercase;
}
I also tried the CSS3 :nth-of-type() Selector but no luck!
I wanted to do this using css only.
Try putting survey-extra within col-xs-6 instead. Hope that help
.survey-extra {
background: #1e90ff;
color: #fff;
padding: 10px;
border-radius: 10px;
text-transform: uppercase;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="survey-extra">
<h5>FROM OUR SPONSORS</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
<div class="col-xs-6">
<div class="survey-extra">
<h5>FREEBIES</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
</div>
</div>
I was able to put a visual space between the two divs by using CSS to set the width of .survey-extra to a percentage and then giving either one of the divs (using the :nth-of-type() Selector) or both of them margins, like this:
.survey-extra {
width: 45%;
margin-right: 5px;
background: #1e90ff;
color: #fff;
padding: 5px;
border-radius: 10px;
text-transform: uppercase;
}
Check it out on JSFiddle.
Of course you'd have to play around with the width percentage and margins to get exactly what you want.
If you don't want to use margins, you could also keep the width set to a percentage and then use floating, like this:
.survey-extra {
background: #1e90ff;
color: #fff;
width: 45%;
padding: 5px;
border-radius: 10px;
text-transform: uppercase;
}
.survey-extra:nth-of-type(0) {
float: left;
}
.survey-extra:nth-of-type(1) {
float: right;
}
Check it out using floating on fiddle
I found a solution for my problem and I would like to share it to you for future references. What I did is add nth-of-type(2) and applied css.
CSS:
.survey-extra {
background: #1e90ff;
color: #fff;
padding: 5px;
border-radius: 10px;
text-transform: uppercase;
}
.survey-extra:nth-of-type(2) {
width: 49%;
float: right;
}
.visit-redeem {
background: #56a4da;
margin-top: 5px;
margin-bottom: 6px;
color: #fff;
padding: 5px;
border-radius: 20px 20px 0 0;
text-transform: uppercase;
}
HTML:
<div class="container">
<div class="row visit-redeem text-center">
<h5>Visit Site To Redeem</h5>
</div>
<div class="row">
<div class="col-xs-6 survey-extra">
<h5>FROM OUR SPONSORS</h5>
<span class="money-extra">$0.00</span>
</div>
<div class="col-xs-6 survey-extra">
<h5>FREEBIES</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
</div>
fiddle here
.survey-extra {
display: inline-block;
float: none;
margin: 0 2% 2% 0;
width: 49%;
}
.survey-extra:last-child {
margin-right: 0;
}
And if you have more than 1 row you can replace last-child with nth-child(2n)
no need to change in css just change html like below:
<div class="container">
<div class="row visit-redeem text-center">
<h5>Visit Site To Redeem</h5>
</div>
<div class="row">
<div class="col-xs-6">
<div class="survey-extra">
<h5>FROM OUR SPONSORS</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
<div class="col-xs-6">
<div class="survey-extra">
<h5>FREEBIES</h5>
<span class="money-extra">$0.00</span>
</div>
</div>
</div>
</div>
The Above image shows this is how i want to make it.I have alignment display issue and line doesn't gets displayed. how can i achieve using with bootstrap grid.I want it make responsive. please advise where i am making mistake and how can i make it happen.
plunker link
I wan to see like this
<div class="container-fluid" style="background: white;">
<div class="row">
<div class="col-lg-9 col-xs-12 ">
<div class="parent col-md-3 col-xs-3">
<div class="child circle col-md-1 col-xs-1">1</div>
<div class="expenseItems col-md-1 col-xs-1">Text1</div>
<div class="hrcol-md-1 col-xs-1"></div>
</div>
<div class="parent col-md-3 col-xs-3">
<div class="child circle col-md-1 col-xs-1">2</div>
<div class="expenseItems col-md-2 col-xs-2">Text2</div>
<div class="hr col-md-1 col-xs-1"></div>
</div>
<div class="parent col-md-3 col-xs-3">
<div class="child circle col-md-1 col-xs-1">3</div>
<div class="expenseItems col-md-2 col-xs-2">Text3</div>
<div class="hr col-md-1 col-xs-1"></div>
</div>
<div class="parent col-md-3 col-xs-3">
<div class="child circle col-md-1 col-xs-1">4</div>
<div class="expenseItems col-md-2 col-xs-2">Text4</div>
<div class="hr col-md-1 col-xs-1"></div>
</div>
</div>
</div>
CSS
/*For drawing line*/
.hr {
color: gray;
background: gray;
width: 5px;
height: 1px;
margin-top:4px;
}
.circle
{
width: 28%;
border-radius: 100%;
text-align: center;
font-size: 14pt;
padding: 1pt;
position: relative;
background: gray;
color: white;
margin-top:11pt;
}
/*Parent div*/
.parent {
border-style: dashed;
border-width: 1px;
padding: 25px;
display:inline-block;
background-color:Aqua;
}
.child {
float: left;
background-color:Orange;
}
.expenseItems {
display: inline-block;
background-color:Green;
}
Using columns to acheive alignment inside other columns doesn't really make much sense when you can simply use a display property to do this with the content inside a column.
Use display: inline-block and remove all the nested columns.
Working Example: Open at FullPage
/*Use this rule below adjust the space between columns*/
.no-gutter > [class*='col-'] {
padding-right: 1px;
padding-left: 1px;
}
/*Use the above to adjust the space between columns*/
.parent {
border: 1px dashed red;
padding: 20px 25px 25px;
}
.circle {
width: 25px;
height: 25px;
border-radius: 50%;
padding-top: 3px;
display: inline-block;
text-align: center;
background-color: red;
color: white;
}
.expenseItems {
padding: 10px;
display: inline-block;
color: red;
}
.hr {
background: red;
height: 2px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row no-gutter">
<div class="col-sm-3">
<div class="parent">
<div class="circle">1</div>
<div class="expenseItems">TEXT</div>
<div class="hr"></div>
</div>
</div>
<div class="col-sm-3">
<div class="parent">
<div class="circle">1</div>
<div class="expenseItems">TEXT</div>
<div class="hr"></div>
</div>
</div>
<div class="col-sm-3">
<div class="parent">
<div class="circle">1</div>
<div class="expenseItems">TEXT</div>
<div class="hr"></div>
</div>
</div>
<div class="col-sm-3">
<div class="parent">
<div class="circle">1</div>
<div class="expenseItems">TEXT</div>
<div class="hr"></div>
</div>
</div>
</div>
</div>