I have the following
<div class="row">
<div class="col-md-6">
<div class = "box-cell">
<p>
Slightly short text
</p>
</div>
</div>
<div class="col-md-6">
<div class = "box-cell">
<p>
Text that<br>literally<br>spans<br>4 lines
</p>
</div>
</div>
</div>
and css
.box-cell
{
position: relative;
margin: 3px;
border-style: groove ridge ridge groove;
border-width: 3px;
background-size: cover;
}
So the problem that I am facing is that one of the cells is usually taller than the other.IS there any way for me to equalize how much height each cell takes up?
Searching didn't yield me which property I can manipulate to get same height :(
Here is jsfiddle
However in this fiddle I can not get them to be side by side to prove my point
EDIT: I guess I didn't specify it properly. I would like to have the borders be as tall as the tallest cell. So all the examples provided here actually take out the borders and instead color the background. If I do that then yes it gives illusion of every cell being the same, but I would like there to be a border of same height.
I tried replicating what it sounds like you are looking for.
I would recommend you mess around with flexbox since it seems to do exactly what you are looking for.
<div class="myc">
<div class="col">
<p>Text of some sorts</p>
<p>Text of some sorts</p>
<p>Text of some sorts</p>
<p>Text of some sorts</p>
</div>
<div class="col">
<p>Text of some sorts</p>
<p>Text of some sorts</p>
<p>Text of some sorts</p>
</div>
</div>
And for the CSS
.myc {
display: flex;
}
.col {
background-color: yellow;
margin-right: 20px;
}
.row {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.row > [class*='col-'] {
display: flex;
flex-direction: column;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-xs-12 col-sm-4" style="background-color: green">
some content
</div>
<div class="col-xs-6 col-sm-4" style="background-color: orange">
some content
<img src="http://placehold.it/100x120">
</div>
<div class="col-xs-6 col-sm-4" style="background-color: magenta">
some of content
</div>
</div>
Some options to solve it:
Different Tricks on How to Make Bootstrap Columns All the Same Height
<style type="text/css">
.box-cell{
position: relative;
margin: 3px;
border-style: groove ridge ridge groove;
border-width: 3px;
background-size: cover;
}
</style>
<div class="row">
<div class="col-md-6">
<div class = "box-cell">
<p>
Slightly short text
</p>
</div>
</div>
<div class="col-md-6">
<div class = "box-cell">
<p>
<span>Text that</span>
<span>literally</span>
<span>s4 lines</span>
<span>ygthfg</span>
</p>
</div>
</div>
</div>
1- you need to add text in span tag.
2- Or take text in one line .
Related
I have the following four inner div container (small picture - text - small picture - text):
<div class="container">
<div class="col-md-12">
<div class="row">
<div class="col-sm-2">
<div class="components-circle inner-component"></div>
</div>
<div class="col-sm-4">
<h3>Title</h3>
<p class="description">
Some ... long ... text
</p>
</div>
<div class="col-sm-2">
<div class="components-circle inner-component"></div>
</div>
<div class="col-sm-4">
<h3>Title</h3>
<p class="description">
Some ... long ... text
</p>
</div>
</div>
</div>
</div>
The CSS for components-circle and inner-component:
.components-circle {
display: block;
margin: 0 auto;
background-repeat: no-repeat;
height: 115px;
width: 115px;
border-radius: 100%;
border: 2px solid #e0e0eb;
}
.inner-component {
background: url(http://...) no-repeat;
background-position: 20px 15px;
}
The problem is, that components-circle and inner-component are overlapping the text which is on the right side of them when I resize the browser, that means the template is not responsive.
How could I insert a line break when the browser is resized or make components-circle and inner-component responsive, so that they do not overlap the corrsponding text on the right side?
Is the content of the "col-sm-12" div overlapping the content of the page, or the text next to the image that is overlapping?
Anyway, you can fix both of these issues in this way, using a "container" or "row" div and adding a css for page resizing.
.components-circle {
display: block;
margin: 0 auto;
background-repeat: no-repeat;
height: 115px;
width: 115px;
border-radius: 100%;
border: 2px solid #e0e0eb;
}
.inner-component {
background: url(http://...) no-repeat;
background-position: 20px 15px;
}
.center-text{
text-align: left;
}
#media (max-width: 765px) {
.center-text{
text-align: center;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="col-md-12">
<div class="row">
<div class="col-sm-2">
<div class="components-circle inner-component"></div>
</div>
<div class="col-sm-4 center-text">
<h3>Title</h3>
<p class="description">
Some ... long ... text
</p>
</div>
<div class="col-sm-2">
<div class="components-circle inner-component"></div>
</div>
<div class="col-sm-4 center-text">
<h3>Title</h3>
<p class="description">
Some ... long ... text
</p>
</div>
</div>
</div>
</div>
You are already using row class so just setting the width of components-circle to 100% (rather than making it static) will work (as bootstrap will handle rest of the responsive stuff).
To keep the aspect ratio of height-width you have to remove height from components-circle and use padding-top. Have a look here to see how it works. (padding-top: 100% gives 1:1 aspect ratio)
Open the below snippet in full-page view and resize to see the effect :)
Though there can be other methods to achieve the same, IMO this one is quite simple and understandable.
.components-circle {
display: block;
margin: 0 auto;
background-repeat: no-repeat;
padding-top: 100%;
width: 100%;
border-radius: 100%;
border: 2px solid #e0e0eb;
}
.inner-component {
background: url(https://i.ebayimg.com/images/g/eiMAAOSwH3haAlKl/s-l300.png) no-repeat;
background-size: contain;
}
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js" integrity="sha384-u/bQvRA/1bobcXlcEYpsEdFVK/vJs3+T+nXLsBYJthmdBuavHvAW6UsmqO2Gd/F9" crossorigin="anonymous"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
</head>
<body>
<div class="col-md-12">
<div class="row">
<div class="col-sm-2">
<div class="components-circle inner-component"></div>
</div>
<div class="col-sm-4">
<h3>Title</h3>
<p class="description">
Some ... long ... text
</p>
</div>
<div class="col-sm-2">
<div class="components-circle inner-component"></div>
</div>
<div class="col-sm-4">
<h3>Title</h3>
<p class="description">
Some ... long ... text
</p>
</div>
</div>
</div>
</body>
</html>
Update: To keep the inner image at the centre during resize, you have to set it's position to 0px 0px (which is default) and add background-size: contain to the inner-component. This will scale the image to fit the parent. See the updated snippet above!
To make a breakpoint that is hidden on larger viewports, you can use these CSS classes with the line break:
.d-md-none To make it invisible on anything larger than md sized screens.
.d-sm-none To hide it on anything larger than sm sized screens.
You may also need to put the row inside a container.
This is what it would look like: <br class="d-md-none">
If you want a line break without using a <br> element, check out this guide.
I am using a responsive grid and I want each box to have all its contents vertically aligned. Each box will have a different position of the content (structure). In this case (for now), I have two boxes and they work fine separately. When I include them in the grid, the grid is no longer responsive.
For example, the first box will look like this:
and the second box will look like this:
So, far... I have built the main grid and I am trying to align the items using the first box template. I am trying to find the best solution. I am guessing the change is related to the .example-feature-staggered-row:
h1,h2{letter-spacing:-.04em;text-align:center;line-height:1.2em}h1,h2,h3{text-align:center}h1,h2,h4{line-height:1.2em}h3,h4{margin-bottom:12px;letter-spacing:-.03em}h2,h5{margin-bottom:16px}h3,h5{line-height:1.3em;margin-top:0}h1,h2,h3,h4,h5,h6{font-family:'Circular Medium',sans-serif;font-weight:500}h6,p{margin-bottom:10px}h2,h3,h4,h5,h6{margin-top:0}h1{font-size:3.875em}h2{font-size:2.75em}h3{font-size:2em}h4{font-size:1.375em}h5{font-size:1.25em;letter-spacing:-.02em}h6{font-size:.875em;line-height:1.4em}.grid{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;margin-right:-16px;margin-left:-16px;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;-webkit-align-content:flex-start;-ms-flex-line-pack:start;align-content:flex-start}.grid.gutter--small{margin-right:-8px;margin-left:-8px}.grid.no-gutter{margin-right:0;margin-left:0}.grid.justify--center{-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center}.example-body,.example-center{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;-webkit-flex-direction:column;-webkit-box-orient:vertical;-webkit-box-direction:normal}.example-body{display:flex;margin-bottom:64px;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:start;-webkit-justify-content:flex-start;-ms-flex-pack:start;justify-content:flex-start;-webkit-flex-wrap:nowrap;-ms-flex-wrap:nowrap;flex-wrap:nowrap;-webkit-box-align:stretch;-webkit-align-items:stretch;-ms-flex-align:stretch;align-items:stretch;border-radius:6px;box-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 6px 12px 0 rgba(0,0,0,.1)}.example-body.orange{background-color:#F2987D;color:#fff}.example-body.green{background-color:#E9F0E0;color:#000}.example-body.lightblue{background-color:#00a7f7;color:#00a7f7}.example-center{display:flex;min-height:512px;padding:48px;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1;color:#fff}.example-features-figure,.example-header{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox}.example-header{display:flex;margin-bottom:102px;padding-right:32px;padding-left:32px;-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center}.example-features-figure{display:flex;width:60px;height:60px;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-box-flex:0;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;border-radius:999px;background-color:#a4d7a5}.example-feature-columns,.example-fluid{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox}.example-features-text{padding-left:16px;-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1}.example-feature-title{margin-bottom:8px;text-align:left}.example-feature-subtitle,.example-logo{margin-bottom:0}.example-feature-title.reversed{-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;text-align:right}.example-feature-title.centered{text-align:center}.example-feature-subtitle.reversed{text-align:right}.example-feature-subtitle.centered{text-align:center}.example-logo{margin-top:0;text-transform:uppercase}.example-wrapper{padding-right:32px;padding-bottom:32px;padding-left:32px;background-color:#eef1f3}.example-wrapper.cyan{background-color:#dff7fa}.example-wrapper.blue{background-color:#e2f2fe}.example-wrapper.orange{background-color:#fff3df}.example-wrapper.deeppurple{background-color:#ede7f6}.example-wrapper.purple{background-color:#f3e5f5}.example-wrapper.red{background-color:#ffebee}.example-wrapper.teal{background-color:#dff2f1}.example-wrapper.pink{background-color:#fde4ec}.example-wrapper.green{background-color:#e8f5e9}.example-wrapper.lightblue{background-color:#e0f5ff}.example-wrapper.amber{background-color:#fff8e0}.example-fluid{display:flex;min-height:600px;padding:16px;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1}.example-center-title{margin-bottom:0;text-align:center}.example-center-figure{margin-bottom:12px}.example-equal-height-caption{padding:16px;font-size:.875em;line-height:1.5em}.example-feature-columns{display:flex;padding:32px 16px;-webkit-box-pack:start;-webkit-justify-content:flex-start;-ms-flex-pack:start;justify-content:flex-start;-webkit-box-align:stretch;-webkit-align-items:stretch;-ms-flex-align:stretch;align-items:stretch}.example-feature-column,.example-feature-column-figure{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox}.example-feature-column{display:flex;padding-right:16px;padding-bottom:12px;padding-left:16px;-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:start;-webkit-justify-content:flex-start;-ms-flex-pack:start;justify-content:flex-start;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1}.example-feature-column.sibling{-webkit-box-flex:0;-webkit-flex:0px;-ms-flex:0px;flex:0px;border-left:1px solid #63bc66}.example-feature-column-figure{display:flex;width:100px;height:100px;margin-bottom:16px;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;border-radius:999px;background-color:#a4d7a5}.example-feature-staggered,.example-feature-staggered-row{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox}.example-feature-staggered{display:flex;padding:0 40px;-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column}.example-feature-staggered-row{display:flex;padding-top:32px;padding-bottom:32px;-webkit-box-pack:start;-webkit-justify-content:flex-start;-ms-flex-pack:start;justify-content:flex-start;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;font-size:1.25em;line-height:1.4em}.example-feature-staggered-figure,.example-grid-container{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox}.example-feature-staggered-row.sibling{border-top:1px solid #63bc66}.example-feature-staggered-row.reverse{-webkit-box-orient:horizontal;-webkit-box-direction:reverse;-webkit-flex-direction:row-reverse;-ms-flex-direction:row-reverse;flex-direction:row-reverse}.example-feature-staggered-figure{display:flex;width:160px;height:160px;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-box-flex:0;-webkit-flex:0 0 auto;-ms-flex:0 0 auto;flex:0 0 auto;border-radius:999px}.example-feature-staggered-text{padding-right:24px;padding-left:24px}.example-grid{padding:32px 32px 12px}.example-grid-container{display:flex;margin-right:-8px;margin-left:-8px;-webkit-flex-wrap:nowrap;-ms-flex-wrap:nowrap;flex-wrap:nowrap}.cover-wrapper{position:relative;z-index:1;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;margin-bottom:80px;-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center}#media (max-width:991px){.cover-wrapper,.section-header{margin-bottom:64px}.grid{margin-right:-12px;margin-left:-12px}.grid.tablet-vertical{-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column}.example-center{min-height:480px}.example-header{padding-right:24px;padding-left:24px}.example-equal-height{min-height:400px;padding:48px 40px;font-size:14px;line-height:1.5em}.example-fluid,.example-hero{min-height:480px;line-height:1.5em}.example-equal-height-figure{height:140px}.example{padding-top:64px}.example-features-figure{width:48px;height:48px}.example-features-text{padding-left:12px}.example-wrapper{padding-right:24px;padding-bottom:0;padding-left:24px}.example-fluid{padding:12px;font-size:14px}.example-feature-columns{padding:24px 12px;font-size:14px;line-height:1.5em}.example-feature-column{padding-bottom:6px}.example-feature-column-figure{width:80px;height:80px}.example-feature-staggered{padding-right:24px;padding-left:24px;font-size:12px}.example-grid,.example-hero{font-size:14px}.example-feature-staggered-row{padding-top:24px;padding-bottom:24px}.example-feature-staggered-figure{width:120px;height:120px}.cover-item{-webkit-flex-basis:19%;-ms-flex-preferred-size:19%;flex-basis:19%}.example-hero{padding:12px}.example-hero-figure{width:128px;height:128px}}#media (max-width:767px){h3,h4,h5{margin-bottom:8px}body{font-size:14px;line-height:1.4em}h1{font-size:2.75em}h2{margin-bottom:12px;font-size:2em}h3{font-size:1.5em}.section-description,h4{font-size:1.25em}.section.padded{padding:48px 16px}.container.large.shifted,.container.medium.shifted{margin-top:-64px}.grid{margin-right:-8px;margin-left:-8px}.grid.mobilel-vertical{-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:start;-webkit-justify-content:flex-start;-ms-flex-pack:start;justify-content:flex-start;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center}.example-body{margin-bottom:32px}.example-center{min-height:320px;padding:22px}.example-header{margin-bottom:64px;padding-right:16px;padding-left:16px}.example-equal-height{min-height:0;padding:24px 16px;font-size:10px;line-height:1.4em}.example-equal-height-figure{height:120px}.cover-title{margin-bottom:16px}.cover-subtitle{margin-bottom:32px;font-size:1.25em}.section-header{margin-bottom:48px}.expander-body{margin-top:16px;margin-bottom:16px}.example-features-figure{width:32px;height:32px;padding:8px}.example-features-text{padding-left:8px}.example-feature-title{margin-bottom:4px}.example-wrapper{padding-right:16px;padding-left:16px}.example-fluid{min-height:320px;padding:8px;font-size:10px;line-height:1.4em}.example-center-figure{width:64px;height:64px}.example-equal-height-caption{padding:12px}.example-feature-columns{padding:16px 8px;font-size:11px}.example-feature-column-figure{width:64px;height:64px;margin-bottom:8px;padding:16px}.example-feature-staggered{padding-right:16px;padding-left:16px;font-size:10px}.example-feature-staggered-row{padding-top:16px;padding-bottom:16px}.example-feature-staggered-figure{width:96px;height:96px;padding:24px}.example-grid{padding:16px 16px 4px}.example-grid-container{margin-right:-6px;margin-left:-6px}.cover-item{-webkit-flex-basis:24%;-ms-flex-preferred-size:24%;flex-basis:24%}.logos-text{margin-bottom:12px;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;text-align:center}.cover-logo{position:absolute;left:0;top:0;right:0;z-index:2000;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;width:120px;height:48px;margin-right:auto;margin-left:auto;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center}.cover-logo-image{opacity:.6}}#media (max-width:479px){h1{font-size:2em}h2{font-size:1.75em}.grid.mobile-vertical{-webkit-box-orient:vertical;-webkit-box-direction:normal;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;-webkit-flex-wrap:nowrap;-ms-flex-wrap:nowrap;flex-wrap:nowrap}.cover{padding:1rem;-webkit-box-align:stretch;-webkit-align-items:stretch;-ms-flex-align:stretch;align-items:stretch}.example-body{margin-bottom:16px;border-radius:4px}.example-center{min-height:240px;padding:16px;font-size:12px}.example-header{padding-right:12px;padding-left:12px}.example-equal-height{padding:12px 8px;font-size:8px}.example-equal-height-card{margin-right:4px;margin-left:4px;border-radius:2px}.example-equal-height-figure{height:80px;padding-right:24px;padding-left:24px}.section-header{margin-bottom:48px}.example-features-text{padding-left:6px}.example-wrapper{padding-right:12px;padding-left:12px}.example-fluid{min-height:240px;padding:6px;font-size:6px}.example-equal-height-caption{padding:6px}.example-feature-columns{padding-top:12px;padding-bottom:12px;font-size:10px}.example-feature-column{padding-right:12px;padding-bottom:0;padding-left:12px}.example-feature-column-figure{width:48px;height:48px;padding:12px}.example-feature-staggered{padding-right:12px;padding-left:12px;font-size:8px}.example-feature-staggered-row{padding-top:12px;padding-bottom:12px}.example-feature-staggered-figure{width:64px;height:64px;padding:16px}.example-feature-staggered-text{padding-right:12px;padding-left:12px}.example-grid{font-size:12px}.example-grid-container{margin-right:-4px;margin-left:-4px}.cover-wrapper{margin-bottom:32px}}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="row">
<div class="col-xs-6 col-md-4">
<div class="example-body green">
<div class="example-feature-staggered">
<div class="example-feature-staggered-row">
<div class="example-feature-staggered-figure"><img src="https://cdn0.iconfinder.com/data/icons/simplicity/512/dollar-256.png" width="76"></div>
<div class="example-feature-staggered-text">
<p class="example-feature-title">111 111</p>
<h3 class="example-feature-subtitle">3.2M</h3>
</div>
<div class="example-feature-staggered-text">
<p class="example-feature-title">333</p>
<h3 class="example-feature-subtitle">-10%</h3>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-md-4">
<div class="example-body green">
<div class="example-feature-staggered">
<div class="example-feature-staggered-row">
<div class="example-feature-staggered-text">
<h3 class="example-feature-subtitle">111</h3>
<h3 class="example-feature-subtitle">222</h3>
<h3 class="example-feature-subtitle">333</h3>
</div>
<div class="example-feature-staggered-text">
<h3 class="example-feature-subtitle"><b>AAA</b></h3>
<h3 class="example-feature-subtitle"><b>BBB</b></h3>
<h3 class="example-feature-subtitle"><b>BBB</b></h3>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-md-4">
<div class="example-body orange">
<div class="example-feature-staggered">
<div class="example-feature-staggered-row">
<div class="example-feature-staggered-figure"><img src="https://cdn4.iconfinder.com/data/icons/dot/256/man_person_mens_room.png" width="96"></div>
<div class="example-feature-staggered-text">
<p class="example-feature-title">111 111</p>
<h3 class="example-feature-subtitle">105,306</h3>
</div>
<div class="example-feature-staggered-text">
<p class="example-feature-title">333333</p>
<h3 class="example-feature-subtitle">-44%</h3>
</div>
</div>
<div class="example-feature-staggered-row">
<div class="example-feature-staggered-figure"><img src="https://cdn4.iconfinder.com/data/icons/developer-set-3/128/arrowupright-256.png" width="76"></div>
<div class="example-feature-staggered-text">
<p class="example-feature-title">22222</p>
<h3 class="example-feature-subtitle">35.05%</h3>
</div>
<div class="example-feature-staggered-text">
<p class="example-feature-title">- </p>
<h3 class="example-feature-subtitle">+6%</h3>
</div>
</div>
</div>
</div>
</div>
</div>
I am trying to think of the best solution here. For example. the table might be a solution. Using two columns (for the first template). Each column will have two rows where the items (text and images) will be vertically aligned. The rows of the first column will have a sub-table. Each sub-table will have two columns. The first column will have the image. The second column will have two rows with the text. Is that a good idea? Or is it better to find a more responsive way to achieve that?
Separately, the boxes are fine. I just cannot make them work in the grid without problems (the height is not the same. If I make it the same, the content is not always vertically aligned).
With your current setup, you will need to add media queries at certain breakpoints to restyle the content.
You have giving a lot of elements fixed widths and set them to flex: 0 0 auto; which will stop them from shrinking below their given width.
Also, you could benefit from simplifying your code.
You can create this layout with flex containers. Below is a rough example of what this might look like.
.container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.wrap {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-pack: distribute;
justify-content: space-around;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
width: calc(50% - 40px);
background: #e9f0e1;
min-height: 100px;
min-width: 100px;
margin: 20px;
}
.one {
background: #f09880;
}
.three {
background: #e9f0e1;
}
.content {
padding: 10px;
margin: 10px;
background: seagreen;
color: white;
}
#media screen and (max-width: 500px) {
.wrap {
display: block;
}
}
#media screen and (max-width: 360px) {
.container {
display: block;
}
.wrap {
width: calc(100% - 40px);
}
}
<div class='container'>
<div class='wrap one'>
<div class='item'>
Icon
</div>
<div class='item'>
Text
</div>
<div class='item'>
Text
</div>
</div>
<div class='wrap two'>
<div class='item'>
<div class='content'>
one
</div>
<div class='content'>
two
</div>
</div>
<div class='item'>
<div class='content'>
one
</div>
<div class='content'>
two
</div>
</div>
<div class='item'>
<div class='content'>
one
</div>
<div class='content'>
two
</div>
<div class='content'>
three
</div>
</div>
</div>
<div class='wrap three'>
<div class='item'>
Icon
</div>
<div class='item'>
<div class='content'>
Text
</div>
<div class='content'>
Text
</div>
</div>
<div class='item'>
<div class='content'>
Text
</div>
<div class='content'>
Text
</div>
</div>
</div>
</div>
I'm pretty new to HTML and CSS so perhaps this is a crazy easy question to answer.
The question is:
How to do this using only divs and css?
I don't want to use <table> <tr> <th> <td>....
Here's a basic setup of what you're asking using the flexbox property.
The CSS3 Flexible Box, or flexbox, is a layout mode providing for the
arrangement of elements on a page such that the elements behave
predictably when the page layout must accommodate different screen
sizes and different display devices. For many applications, the
flexible box model provides an improvement over the block model in
that it does not use floats, nor do the flex container's margins
collapse with the margins of its contents.
Read more about it at MDN and experiment with it so you feel comfortable using it. The setup might not be pixel perfect, but it gives you a good start for the desired layout. Trial and error, that's the best way to learn.
div {
box-sizing: border-box;
border: 1px solid black;
min-height: 20px;
}
.container {
display: flex;
flex-flow: row-wrap;
width: 100%;
}
.column {
flex: 1 1 100%;
}
.middle {
flex-basis: 200%;
}
.middle-top,
.right-top,
.right-bottom {
display: flex;
flex-flow: row wrap;
width: 100%;
}
.language,
.search,
.login,
.signup,
.some-text,
.avatar {
flex: 1 1 50%;
}
<div class="container">
<div class="column left">
<div class="social">
Social icons
</div>
<div class="logo">
Logo
</div>
</div>
<div class="column middle">
<div class="middle-top">
<div class="language">
Language
</div>
<div class="search">
Search
</div>
</div>
<div class="slogan">
Slogan
</div>
<div class="menu">
Menu
</div>
</div>
<div class="column right">
<div class="right-top">
<div class="login">
Login
</div>
<div class="signup">
Signup
</div>
</div>
<div class="right-middle">
Welcome guest
</div>
<div class="right-bottom">
<div class="some-text">
<div class="something">
Some text
</div>
<div class="something">
Some text
</div>
</div>
<div class="avatar">
Avatar
</div>
</div>
</div>
</div>
How to stick the columns together with bootstrap and css?
I would like to create something like this:
What I have created:
Here is my HTML & CSS markup:
<div class="container">
<div class="row">
<div class="col-md-4 ">
<div class="box1">
<h1>this is box 1 one</h1>
</div>
</div>
<div class="col-md-4 ">
<div class="box2">
<h1>this is box 1 one</h1>
</div>
</div>
<div class="col-md-4 ">
<div class="box3">
<h1>this is box 1 one</h1>
</div>
</div>
</div>
</div>
My css
.box1 {
background: red;
}
.box2{
background: green;
}
.box3 {
background: yellow;
}
Every single help would be appreciate!
There are many possibilities depending on what you are trying to achieve exactly.
If you want to remove the gap (called gutters) between ALL the columns of your design, you can customize your own bootstrap at http://getbootstrap.com/customize/#grid-system you'll see the variable "#grid-gutter-width" that needs to be set to 0.
If you want to have some contents that span outside the gutters, so they can touch adjascent elements, use a class to negate the gutter. Something like
.no-pad{
padding-left:0;
padding-right:0;
}
And add it to all columns you want without gutter.
If you want the background color to touch but still keep a nice sepperation of columns for your text, you can simply apply the background styles on the column itself.
The only way to achieve the result you are after is to remove the padding from Bootstraps column classes, like so:
.col-md-4 {
padding: 0;
}
However the above code will remove the padding from all col-md-4 column classes in your HTML. Best practise would be to add a unique class/ID and target the column that way, like so:
<div class="myClass">
<div class="container-fluid">
<div class="row">
<div class="col-md-4 ">
<div class="box1">
<h1>this is box 1 one</h1>
</div>
</div>
<div class="col-md-4 ">
<div class="box2">
<h1>this is box 1 one</h1>
</div>
</div>
<div class="col-md-4 ">
<div class="box3">
<h1>this is box 1 one</h1>
</div>
</div>
</div>
</div>
</div>
.myClass .row .col-md-4 {
padding: 0;
}
This way you are only targeting specific code and not ALL the columns.
Bootstraps grid system adds "gutters" or padding to each column. Is is this that you want to overwrite. however if you were to simply apply padding:0px; to .col-md-4 you would remove padding from all instances of .col-md-4 which is unlikely.
The way around this would be to give a class to the "row" container which you can then target only instances of .col-md-4 within that class. In this example I have added the class boxes to the row. then in the css I use:
.boxes .col-md-4 {
padding-right: 0;
padding-left: 0;
}
this way, my padding changes are restricted to col-md-4 classes that are children of a boxes class.
I hope that helps.
Working example but using col-xs-4 as much smaller viewport:
.row {
background: #ccc;
}
.box {
height: 100px;
margin-bottom: 20px;
overflow: hidden;
}
.boxes .col-xs-4 {
padding-right: 0;
padding-left: 0;
}
.box1 {
background: red;
}
.box2 {
background: green;
}
.box3 {
background: yellow;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<div class="row boxes">
<div class="col-xs-4">
<div class="box box1">
<h1>this is box 1</h1>
</div>
</div>
<div class="col-xs-4 ">
<div class="box box2">
<h1>this is box 2</h1>
</div>
</div>
<div class="col-xs-4 ">
<div class="box box3">
<h1>this is box 3</h1>
</div>
</div>
I am using twitter bootstrap, and have a row which has two columns (span6). How do I create a vertical divider between both the spans.
Thanks,
Murtaza
If your code looks like this:
<div class="row">
<div class="span6">
</div>
<div class="span6">
</div>
</div>
Then I'd assume you're using additional DIVS within the "span6" DIVS for holding/styling your content? So...
<div class="row">
<div class="span6">
<div class="mycontent-left">
</div>
</div>
<div class="span6">
<div class="mycontent-right">
</div>
</div>
</div>
So you could simply add some CSS to the "mycontent-left" class to create your divider.
.mycontent-left {
border-right: 1px dashed #333;
}
In Bootstrap 4 there is the utility class border-right which you can use.
So for example you can do:
<div class="row">
<div class="col-6 border-right"></div>
<div class="col-6"></div>
</div>
.row.vertical-divider {
overflow: hidden;
}
.row.vertical-divider > div[class^="col-"] {
text-align: center;
padding-bottom: 100px;
margin-bottom: -100px;
border-left: 3px solid #F2F7F9;
border-right: 3px solid #F2F7F9;
}
.row.vertical-divider div[class^="col-"]:first-child {
border-left: none;
}
.row.vertical-divider div[class^="col-"]:last-child {
border-right: none;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="row vertical-divider" style="margin-top: 30px">
<div class="col-xs-6">Hi there</div>
<div class="col-xs-6">Hi world<br/>hi world</div>
</div>
Well here's another option which I've been using for some time now. It works great for me since I mostly need it do visually separate 2 cols. And it's also responsive. Which means that if I have columns next to each other in medium and large screen sizes, then I would use the class col-md-border, which would hide the separator on smaller screen sizes.
css:
#media (min-width: 992px) {
.col-md-border:not(:last-child) {
border-right: 1px solid #d7d7d7;
}
.col-md-border + .col-md-border {
border-left: 1px solid #d7d7d7;
margin-left: -1px;
}
}
In scss you can generate all needed classes probably from this:
scss:
#media(min-width: $screen-md-min) {
.col-md-border {
&:not(:last-child) {
border-right: 1px solid #d7d7d7;
}
& + .col-md-border {
border-left: 1px solid #d7d7d7;
margin-left: -1px;
}
}
}
HTML:
<div class="row">
<div class="col-md-6 col-md-border"></div>
<div class="col-md-6 col-md-border"></div>
</div>
How it works:
The cols must be inside an element where there are no other cols otherwise the selectors might not work as expected.
.col-md-border:not(:last-child) matches all but the last element before .row close and adds right border to it.
.col-md-border + .col-md-border matches the second div with the same class if these two are next to each other and adds left border and -1px negative margin. Negative margin is why it doesn't matter anymore which column has greater height and the separator will be 1px the same height as the highest column.
It does also have some problems...
When you try to be clever/lazy and use col-XX-X class together with hidden-XX/visible-XX classes inside the same row element.
When you have a lot of columns and need a pixel perfect thing. Since it moves n-1 column 1px to the left.
... But on the other hand it's responsive, works great for simple html and it's easy to create these classes for all bootstrap screen sizes.
To fix the ugly look of a divider being too short when the content of one column is taller, add borders to all columns. Give every other column a negative margin to compensate for position differences.
For example, my three column classes:
.border-right {
border-right: 1px solid #ddd;
}
.borders {
border-left: 1px solid #ddd;
border-right: 1px solid #ddd;
margin: -1px;
}
.border-left {
border-left: 1px solid #ddd;
}
And the HTML:
<div class="col-sm-4 border-right">First</div>
<div class="col-sm-4 borders">Second</div>
<div class="col-sm-4 border-left">Third</div>
Make sure you use #ddd if you want the same color as Bootstrap's horizontal dividers.
If you want a vertical divider between 2 columns, all you need is add
class="col-6 border-left"
to one of your column div-s
BUT
In the world of responsive design, you may need to make it disappear sometimes.
The solution is disappearing <hr> + disappearing <div> + margin-left: -1px;
<div class="container">
<div class="row">
<div class="col-md-7">
1 of 2
</div>
<div class="border-left d-sm-none d-md-block" style="width: 0px;"></div>
<div class="col-md-5" style="margin-left: -1px;">
<hr class="d-sm-block d-md-none">
2 of 2
</div>
</div>
</div>
https://jsfiddle.net/8z1pag7s/
tested on Bootstrap 4.1
With Bootstrap 4 you can use borders, avoiding writing other CSS.
border-left
And if you want space between content and border you can use padding. (in this example padding left 4px)
pl-4
Example:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="offset-6 border-left pl-4">First</div>
<div class="offset-6 border-left pl-4">Second</div>
</div>
If you are still seeking for the best solution in 2018, I found the way this works perfectly if you have at least one free pseudo element( ::after or ::before ).
You just have to add class to your row like this: <div class="row vertical-divider ">
And add this to your CSS:
.row.vertical-divider [class*='col-']:not(:last-child)::after {
background: #e0e0e0;
width: 1px;
content: "";
display:block;
position: absolute;
top:0;
bottom: 0;
right: 0;
min-height: 70px;
}
Any row with this class will now have vertical divider between all of the columns it contains...
You can see how this works in this example.
I have tested it. It works fine.
.row.vdivide [class*='col-']:not(:last-child):after {
background: #e0e0e0;
width: 1px;
content: "";
display:block;
position: absolute;
top:0;
bottom: 0;
right: 0;
min-height: 70px;
}
<div class="container">
<div class="row vdivide">
<div class="col-sm-3 text-center"><h1>One</h1></div>
<div class="col-sm-3 text-center"><h1>Two</h1></div>
<div class="col-sm-3 text-center"><h1>Three</h1></div>
<div class="col-sm-3 text-center"><h1>Four</h1></div>
</div>
</div>
Must Open in Full Page to See Borders!
Added media width clauses in the CSS so there isn't any nasty borders on the mobile-friendly side of things. Hope this helps! This will resize to the length of the longest column. Tested on .col-md-4 and .col-md-6 and my assumption is it is compatible with the rest. No guarantees though.
JSFiddle
.row {
overflow: hidden;
}
.cols {
padding-bottom: 100%;
margin-bottom: -100%;
overflow: hidden;
}
#media(min-width: 992px) {
.col-md-4:not(:first-child),
.col-md-6:not(:first-child) {
border-left: 1px solid black;
}
.col-md-4:not(:last-child),
.col-md-6:not(:last-child) {
border-right: 1px solid black;
margin-right: -1px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<h1>
.col-md-6
</h1>
<hr>
<div class="row text-center">
<div class="col-md-6 cols">
<p>Enter some text here</p>
</div>
<div class="col-md-6 cols">
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
</div>
</div>
<hr>
<h1>
.col-md-4
</h1>
<div class="row text-center">
<div class="col-md-4 cols">
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
</div>
<div class="col-md-4 cols">
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
</div>
<div class="cols col-md-4 cols">
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
<p>Enter some more text here</p>
</div>
</div>
</div>
Assuming you have a column space, this is an option. Rebalance the columns depending on what you need.
<div class="col-1">
<div class="col-6 vhr">
</div>
</div>
.vhr{
border-right: 1px solid #333;
height:100%;
}
As #WalterV answered above, changed for Bootstrap 5+:
<div class="row">
<div class="offset-6 border-start border-5">First</div>
<div class="offset-6 border-start border-5">Second</div>
</div>
As of bootstrap v4 you can use this code
<div class="row">
<div class="col-6 span6 border-right">
dummy content
</div>
<div class="col-6 span6">
right div content
</div>
</div>
In bootstrap 5 you can use the classes border-start or border-end.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<div class="container text-center">
<div class="row">
<div class="col-sm-6 border-end">
<h3>Column 1</h3>
</div>
<div class="col-sm-6">
<h3>Column 2</h3>
</div>
</div>
</div>
Also the borders will not be seen in extra small devices.
<style>
.vl {
border-left: 6px solid green;
height: 500px;
}
</style>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> Vertical Rule </title>
</head>
<body>
<div class="vl"></div>
</body>
</html>
Well what I did was remove the gutter between the respective spans then drawing a left border for the left span and a right border for the right span in such a way that their borders overlapped just to give a single line. This way the visible line will just be one of borders.
CSS
.leftspan
{
padding-right:20px;
border-right: 1px solid #ccc;
}
.row-fluid .rightspan {
margin-left: -0.138297872340425%;
*margin-left: -0.13191489361702%;
padding-left:20px;
border-left: 1px solid #ccc;
}
.row-fluid .rightspan:first-child {
margin-left: -0.11063829787234%;
*margin-left: -0.104255319148938%;
}
HTML
<div class="row-fluid" >
<div class="span8 leftspan" >
</div>
<div class="span4 rightspan" >
</div>
</div>
Try this it works for me
I was looking for a vertical divider in Bootstrap 3.3.7 but they're aren't any by default so I wrote a simple one-line div that did the job for me.
See if it works for you.
<div style="display: inline;border-right: 1px solid gray; padding:0 5px;"></div>
Thank you for reading. Cheers.
Bootstrap V5 introduced the .vr class you place on a <div> element.
If needed, place it inside an <li> element to separate elements inside <ul>element.
<ul class="navbar-nav">
<li>Element 1</li>
<li>
<div class="h-100 vr"></div>
</li>
<li>Element 2</li>
</ul>
Note : .navbar-nav class is related to navbars and sets the css property list-style of all children elements to none which is required for the wrapping <li> element to display the vertical rule (separator) correctly.
Use this, 100% guaranteed:-
vr {
margin-left: 20px;
margin-right: 20px;
height: 50px;
border: 0;
border-left: 1px solid #cccccc;
display: inline-block;
vertical-align: bottom;
}