How to align two text elements, one to the left and the other to the right, also on the same line. I'm aware it can be done using floats but I would like a float less solution. I'm looking for a way to do it using display:inline.
HTML:
<div class="contailner">
<div class="inlineLeft">Item 1</div>
<div class="inlineRight">Item 2</div>
</div>
CSS:
.container {
width: 600px;
border: 1px solid blue;
}
.inlineLeft, .inlineRight {
display: inline;
}
.inlineRight {
...align right...
}
you could just use position:absolute on the inline elements and position:relative on the container. Then you can align the inline elements the way you want relative to the container. Something like this:
.container {
position: relative;
width: 600px;
border: 1px solid blue;
}
.inlineLeft, .inlineRight {
position: absolute;
display: inline;
}
.inlineRight {
right: 0;
}
DEMO
UPDATE - 2019, April
We can also work with css flex.
div.flex-box {
display: flex;
justify-content: space-between;
border: 2px deeppink dashed;
}
<div class="flex-box">
<span>span element 1</span>
<span>span element 2</span>
</div>
PREVIOUS ANSWER
We can achieve this with display:table:
.container {
border: 2px blue dashed;
display: table;
width: 100%;
/*MARGIN (NOT REQUIRED)*/
margin: auto;
margin-top: 100px;
width: 500px;
}
.inlineRight {
display: table-cell;
text-align: right;
}
.inlineLeft {
display: table-cell;
text-align: left;
}
<div class="container">
<div class="inlineLeft">Item 1</div>
<div class="inlineRight">Item 2</div>
</div>
Good Luck...
add this to your css
.inlineLeft, .inlineRight {
display: inline-block;
}
.inlineRight {
display:inline-block;
position:absolute;
right:0;
margin-right:8px;
}
Demo
Why are you doing it like this?
You can easily have the same result with an un-ordered list without those extra divs.
Make sure you set the text-align property for the first list item to "left" (ul li:first-child), and set the text-align property for the other list items (ul li) to "right".
UPDATE - Here's the code for this as requested:
HTML
<ul>
<li>item 1</li>
<li>item 2</li>
</ul>
CSS
ul{
padding: 0 0;
margin: 0 0;
list-style: none;
width: 600px;
border: 1px solid blue;
height: 30px;
}
ul li{
width: 300px;
display: block;
float: left;
text-align: right;
line-height: 30px;
}
ul li:first-child{
text-align: left;
}
DEMO
You could use text-align:justify + after pseudo element to justify that first line:
http://codepen.io/anon/pen/JeAgk
.contailner {
line-height:0;
text-align:justify;
background:lightgray;
margin:1em;
}
.contailner > * {
display:inline-block;
line-height:1.2em;
}
.contailner:after {
content:'';
display:inline-block;
width:99%;
vertical-align:top;/* or bottom to swallow last gaps */
}
/* some extra possibilities */
ul {padding:0;margin:0;}
.w3 {padding-left:1%;}
.w3 .box {margin:1% 1% 1% 0; border:solid;width:31%;text-align:center;box-shadow:0 0 5px;}
.w3 .w5 {width:48%;}
.w3 .w15 {width:14%;}
.w3 .w25 {width:23%;}
<div class="contailner">
<div class="inlineLeft">Item 1</div>
<div class="inlineRight">Item 2</div>
</div>
<div class="contailner">
<span>Item 1</span>
<span>Item 2</span>
<span>Item 3</span>
</div>
<ul class="contailner">
<li>link item</li>
<li>link item</li>
<li>link item</li>
<li>link item</li>
<li>link item</li>
<li>link item</li>
</ul>
<div class="contailner w3">
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
</div>
<div class="contailner w3">
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w5">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w5">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w5">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w25">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w25">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w25">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w25">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
</div>
.contailner {
line-height:0;
text-align:justify;
}
.contailner > div {
display:inline-block;
line-height:1.2em;
}
.contailner:after {
content:'';
display:inline-block;
width:100%;
}
If you use an extra empty element instead of pseudo-element, then you have a technic that is usable since text-align:justify exists, wich means compatible with any browsers.
Edit 2020
For simple inline elements , nowdays , text-align-last works with every browsers. , the pseudo element can be dropped.
.contailner {
text-align: justify;
text-align-last: justify;
background: lightgray;
margin: 1em;
}
.contailner>* {
display: inline-block;
}
/* some extra possibilities */
ul {
padding: 0;
margin: 0;
}
.w3 {
padding-left: 1%;
}
.w3 .box {
margin: 1% 1% 1% 0;
border: solid;
width: 31%;
text-align: center;
box-shadow: 0 0 5px;
}
.w3 .w5 {
width: 48%;
}
.w3 .w15 {
width: 14%;
}
.w3 .w25 {
width: 23%;
}
<div class="contailner">
<div class="inlineLeft">Item 1</div>
<div class="inlineRight">Item 2</div>
</div>
<div class="contailner">
<span>Item 1</span>
<span>Item 2</span>
<span>Item 3</span>
</div>
<ul class="contailner">
<li>link item</li>
<li>link item</li>
<li>link item</li>
<li>link item</li>
<li>link item</li>
<li>link item</li>
</ul>
<div class="contailner w3">
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
</div>
<div class="contailner w3">
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w5">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w5">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w5">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w15">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w25">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w25">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w25">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
<div class="box w25">
<header>header</header>
<article>Article</article>
<footer>footer</footer>
</div>
</div>
also, nowdays
there is flex and space-between to easily do the job and to use if it is to build a grid layout.
text-align/text-align-last should be used only for its original purpose : text alignment, not a workaround to something else.
So what would you choose for a nav ?
.txt {
text-align-last: justify
}
/* or ? */
.flx {
display: flex;
justify-content: space-between;
}
<nav class="txt">
Link Link Link
</nav>
<nav class="flx">
Link Link Link
</nav>
Related
How can I keep the margin-bottom only for the elements that are not in the last line ?
.container {
display: flex;
flex-flow: row wrap;
background: green;
justify-content: space-between;
}
.block {
height: 60px;
max-width: calc((100% - (12px * 2)) / 3);
flex-basis: calc((100% - (12px * 2)) / 3);
background: orange;
box-shadow: inset 0 0 0 3px black;
margin-bottom: 12px;
}
<div class="container">
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
</div>
Thanks in advance.
This is what you are looking for:
.container .block:nth-last-child(-n+3){
margin-bottom: 0px;
}
for flex and grid, you can use the gap propertie to avoid playing with margins:
https://developer.mozilla.org/en-US/docs/Web/CSS/gap
The gap CSS property sets the gaps (gutters) between rows and columns. It is a shorthand for row-gap and column-gap.
Applies to multi-column elements, flex containers, grid containers
see https://www.caniuse.com/?search=gap for support
to set 3 elements on a line, give a min-width bigger than 25% and set them to grow via flex-grow. for the demo i used 26%, should be small enough to leave room for the gaps .
Demo of your code witout margins but still a gap in between elements
.container {
display: flex;
flex-flow: row wrap;
background: green;
gap: 12px;
/* see https://www.caniuse.com/?search=gap for support */
}
.block {
height: 60px;
flex: 1 1 0; /* or flex:1; */
/* to stretch them at the most and even their sizes*/
min-width: 26%;
/* it cannot be more than 3 on a row */
background: orange;
box-shadow: inset 0 0 0 3px black;
padding:5px; /* padding is fine */
}
<div class="container">
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
</div>
<hr>
<div class="container">
<div class="block">A single line
</div>
<div class="block">
</div>
<div class="block">
</div>
</div>
<hr>
<div class="container">
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">a second and last line
</div>
<div class="block">
</div>
<div class="block">
</div>
</div>
<hr>
<div class="container">
<div class="block">2 blocks , is that okay ?
</div>
<div class="block">
</div>
</div>
You can also use CSS grid:
.container {
display: grid;
grid-template-columns:repeat(3,1fr);
grid-gap:12px;
background: green;
}
.block {
height: 60px;
background: orange;
box-shadow: inset 0 0 0 3px black;
}
<div class="container">
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
<div class="block">
</div>
</div>
I'm trying to generate a layout which has varying number of divs, I.e.
| Large | Large |
|Small | Small | Small |
| Large | Large |
...
Large divs will have 50% width, whereas smaller one's will have 33%.
How can I go about this? I'm floating the div's so that they're in a row, but unsure on how I can get three smaller divs, below the larger ones, whilst still ensuring everything is central?
Current approach:
.case-card--large {
width: 50%;
float: right;
}
.case-card {
float: right;
text-align: center;
padding: 40px;
width: 33%;
border: 1px solid blue;
}
<div class="case-card case-card--large">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card case-card--large">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
Here is my solution.
I have used display:inline-block for each box
* {
box-sizing: border-box;
}
.container {
font-size: 0; /* to remove space betwen inline elements*/
}
.wrapper {
font-size: initial;
}
.case-card {
text-align: center;
padding: 40px;
width: calc(100% / 3);
border: 1px solid blue;
display: inline-block;
}
.case-card--large {
width: 50%;
}
<div class="container">
<div class="case-card case-card--large">
<div class="wrapper">
<p>Dummy text Large</p>
</div>
</div>
<div class="case-card case-card--large">
<div class="wrapper">
<p>Dummy text Large</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card case-card--large">
<div class="wrapper">
<p>Dummy text Large</p>
</div>
</div>
<div class="case-card case-card--large">
<div class="wrapper">
<p>Dummy text Large</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
</div>
You can work with a CSS technique: flex (MDN docs).
Put those elements in a parent container, set its width and make it behave as a flex-box by using display: flex. Here below is an example of how I did it. The CSS rules below the /* show case rules below */ are used to have a visual result of what you can have by using flex boxes.
#cont {
display: flex;
flex-direction: row;
width: 600px;
flex-wrap: wrap;
justify-content: space-between;
}
.case-card {
width: 33%;
box-sizing: border-box;
/* show case rules below */
background-color: red;
border: 1px solid black;
}
.case-card--large {
width: 50%;
/* show case rules below */
background-color: yellow;
}
<div id="cont">
<div class="case-card case-card--large">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card case-card--large">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card case-card--large">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card case-card--large">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
</div>
edit: I have used justify-content: space-around; first which aligns the elements with width: 33% somewhat nicely in the middle towards each other. Changing that to justify-content: space-between; ensures that the outer boxes are aligned to the same border as the container which may appeal the OP more. Credits for D.Schaller
You need to include box-sizing:border-box because you are using padding or to put width as width: calc(33% - 80px), also .large class create as subclass or otherwise in your case put !important, because now doesn't work and everything is width 33%
body{
text-align:center;
}
.case-card {
box-sizing: border-box;
display:inline-block;
text-align: center;
padding: 40px;
width: 33.33%;
border: 1px solid blue;
margin: 0 -2px;
}
.case-card.large{
width: 50%;
}
<div class="case-card large">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card large">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
Ok.. So I made little modification in the code and it works quite fine. Hope it helps you out.
Instead of float:right I used
float:left
and added the border to the wrapper class.
https://codepen.io/anon/pen/oMWMBE
.case-card--large {
width: 50%;
float: left;
text-align: center;
}
.wrapper { border: 1px solid blue; }
.case-card {
float: left;
text-align: center;
width: 33.33%;
}
<div class="case-card--large">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card--large">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
<div class="case-card">
<div class="wrapper">
<p>Dummy text</p>
</div>
</div>
I want to automatically resize the container based on <div>. If there are 4 <div> inside container then it looks fine but if there is only 1 <div> then there will be plenty of space in right side. So wanted to adjust container size according to <div>. How can I achieve this? Please help me.
main page looks like this
When there are 4 panels it fits perfectly fine like this
When there are 2 panels then there is plenty of space in the right side which which is marked by color. I want to adjust the container width here automatically.
<div class="container">
<div class="row">
<div>
<ul class="nav nav-tabs" id="ATab">
<li class="active"><a data-toggle="tab" href="#Select">Select</a></li>
<li><a data-toggle="tab" href="#Criteria">Criteria</a></li>
</ul>
<div class="tab-content">
<div id="Select" class=" tab-pane fade in active"></div>
<div id="Criteria" class="tab-pane fade"></div>
<div class="container active col-md-3 col-sm-6 ">
<div class="panel panel-default">
<div class="panel-heading">First Name</div>
</div>
</div>
<div class="container active col-md-3 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Last Name</div>
</div>
</div>
</div>
</div>
</div>
</div>
You can use flexbox for this behavior. Check this codepen for demo.
HTML:
<div class="parent">
<ul class="nav">
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
<li>Item 1</li>
</ul>
</div>
CSS:
.parent {
background-color: orange;
}
.parent ul.nav {
list-style: none;
padding: 0px;
margin: auto;
display: flex;
}
.parent ul.nav li {
background-color: grey;
padding: 10px 15px;
border-right: 1px solid black;
width: 100%;
text-align: center;
}
.parent ul.nav li:last-child {
border: 0px;
}
Hope this would help!
EDIT 1:
Check this other codepen for demo.
body {
padding: 0px;
margin: 0;
}
.parent {
background-color: orange;
padding: 20px;
}
.parent .tabFrame .itemContainer {
display: inline-block;
margin-bottom: 50px;
padding: 5px;
border: 1px solid;
overflow: hidden;
}
.parent .tabFrame .myItem {
background-color: grey;
display: inline-block;
width: 100px; /* can be any fixed width */
padding: 10px;
color: white;
border: 1px solid black;
}
<div class="parent">
<div class="tabFrame">
<div>Tab area</div>
<div class="itemContainer">
<div class="myItem">Item 1</div>
<div class="myItem">Item 2</div>
<div class="myItem">Item 3</div>
<div class="myItem">Item 4</div>
</div>
</div>
<div class="tabFrame">
<div>Tab area</div>
<div class="itemContainer">
<div class="myItem">Item 1</div>
<div class="myItem">Item 2</div>
<div class="myItem">Item 3</div>
</div>
</div>
<div class="tabFrame">
<div>Tab area</div>
<div class="itemContainer">
<div class="myItem">Item 1</div>
<div class="myItem">Item 2</div>
</div>
</div>
<div class="tabFrame">
<div>Tab area</div>
<div class="itemContainer">
<div class="myItem">Item 1</div>
</div>
</div>
</div>
EDIT: 2
See this codepen
.myTab {
border: 1px solid #dddddd;
display: inline-block;
margin-top: -1px;
}
.myTab .tab-pane .myPanel {
display: inline-block;
margin: 10px;
}
.myPanel {
min-width: 200px;
}
#ATab {
border-bottom: 0px;
}
<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>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div>
<ul class="nav nav-tabs" id="ATab">
<li class="active">
<a data-toggle="tab" href="#Select">Select</a>
</li>
<li>
<a data-toggle="tab" href="#Criteria">Criteria</a>
</li>
</ul>
<div class="tab-content clearfix myTab">
<br>
<div id="Select" class=" tab-pane fade in active clearfix">
<div class="panel panel-default myPanel">
<div class="panel-heading">First Name</div>
</div>
<div class="panel panel-default myPanel">
<div class="panel-heading">Last Name</div>
</div>
</div>
<div id="Criteria" class="tab-pane fade">
<div class="panel panel-default myPanel">
<div class="panel-heading">First Name</div>
</div>
<div class="panel panel-default myPanel">
<div class="panel-heading">Last Name</div>
</div>
<div class="panel panel-default myPanel">
<div class="panel-heading">First Name</div>
</div>
<div class="panel panel-default myPanel">
<div class="panel-heading">Last Name</div>
</div>
</div>
</div>
</div>
</div>
</div>
Try using css flexbox to get rid of unwanted spaces.
.nav {
display:flex;
}
a {
text-decoration: none;
color:white;
}
li {
background-color:#232323;
list-style-type: none;
padding: 20px;
flex: 1 1 auto;
}
li.active{
background-color:gray;
}
<div class="container">
<div class="row">
<div>
<ul class="nav nav-tabs" id="ATab">
<li class="active"><a data-toggle="tab" href="#Select">Select</a></li>
<li><a data-toggle="tab" href="#Criteria">Criteria</a></li>
</ul>
<div class="tab-content">
<div id="Select" class=" tab-pane fade in active"></div>
<div id="Criteria" class="tab-pane fade"></div>
</div>
</div>
</div>
</div>
The flex: 1 1 auto on the li makes the li fill up any remaining space on the main flex axis (horizontal line because the default flex direction is row)
You can read up on flex box :
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://css-tricks.com/almanac/properties/f/flex/
In my code,
Within one container Three blocks will be there. one freezes on the left and one freezes on the right and the other will scroll in between these two divs. Just like modern grids. But I don't want to use the grid.
I have tried, but the center block is not getting the Horizontal scroll.
I want no breakage of the center block, instead, it should scroll horizontally.
* {
box-sizing: border-box;
}
.container {
width: 100%;
overflow: auto;
white-space: nowrap
}
.scroll-center {
width: auto;
overflow: auto;
display: block;
white-space: nowrap
}
.row {
float: left;
}
.cell {
padding: 3px;
border: 1px solid #bbb;
min-height: 25px;
min-width: 200px;
}
<div class="container">
<div class="row">
<div class="cell">HeaderL1</div>
<div class="cell">HeaderL2</div>
<div class="cell">HeaderL3</div>
</div>
<div class="scroll-center">
<div class="row">
<div class="cell">HeaderT2</div>
<div class="cell">Data21</div>
<div class="cell">Data22</div>
</div>
<div class="row">
<div class="cell">HeaderT3</div>
<div class="cell">Data31</div>
<div class="cell">Data32</div>
</div>
<div class="row">
<div class="cell">HeaderT4</div>
<div class="cell">Data41</div>
<div class="cell">Data42</div>
</div>
<div class="row">
<div class="cell">HeaderT5</div>
<div class="cell">Data51</div>
<div class="cell">Data52</div>
</div>
<div class="row">
<div class="cell">HeaderT6</div>
<div class="cell">Data61</div>
<div class="cell">Data62</div>
</div>
<div class="row">
<div class="cell">HeaderT7</div>
<div class="cell">Data71</div>
<div class="cell">Data72</div>
</div>
<div class="row">
<div class="cell">HeaderT8</div>
<div class="cell">Data81</div>
<div class="cell">Data82</div>
</div>
<div class="row">
<div class="cell">HeaderT9</div>
<div class="cell">Data91</div>
<div class="cell">Data92</div>
</div>
</div>
<div class="right">
<div class="row">
<div class="cell">HeaderTR</div>
<div class="cell">DataR1</div>
<div class="cell">DataR2</div>
</div>
</div>
</div>
You probably need to add width to your container. Right now it's set to 100% so it will not size beyond the browser window. Instead you could do something like this:
.container {
overflow: auto;
white-space: nowrap;
width:2000px;
}
I realize that you may need to change this value dynamically but hopefully this gets you started
Example:http://codepen.io/nilestanner/pen/jAjbdK
Try with For example:
css:
* {
box-sizing: border-box;
}
.left, .center, .right{
float:left
}
.center {
width:400px;
overflow: scroll;
display: block;
white-space: nowrap
}
#center-scroll{
width:2000px;
}
.center .row{
display:inline-block;
width:33%;
}
.center .row .cell{
min-width:100%;
}
.row{
float:left;
}
.cell {
padding: 3px;
border: 1px solid #bbb;
min-height: 25px;
min-width: 200px;
}
HTML
<div class="container">
<div class="left">
<div class="row" >
<div class="cell">HeaderL1</div>
<div class="cell">HeaderL2</div>
<div class="cell">HeaderL3</div>
</div>
</div>
<div class="center">
<div id="center-scroll">
<div class="row">
<div class="cell">HeaderT2</div>
<div class="cell">Data21</div>
<div class="cell">Data22</div>
</div>
<div class="row">
<div class="cell">HeaderT3</div>
<div class="cell">Data31</div>
<div class="cell">Data32</div>
</div>
<div class="row">
<div class="cell">HeaderT4</div>
<div class="cell">Data41</div>
<div class="cell">Data42</div>
</div>
<div class="row">
<div class="cell">HeaderT5</div>
<div class="cell">Data51</div>
<div class="cell">Data52</div>
</div>
<div class="row">
<div class="cell">HeaderT6</div>
<div class="cell">Data61</div>
<div class="cell">Data62</div>
</div>
<div class="row">
<div class="cell">HeaderT7</div>
<div class="cell">Data71</div>
<div class="cell">Data72</div>
</div>
<div class="row">
<div class="cell">HeaderT8</div>
<div class="cell">Data81</div>
<div class="cell">Data82</div>
</div>
<div class="row">
<div class="cell">HeaderT9</div>
<div class="cell">Data91</div>
<div class="cell">Data92</div>
</div>
</div>
</div>
<div class="right">
<div class="row">
<div class="cell">HeaderTR</div>
<div class="cell">DataR1</div>
<div class="cell">DataR2</div>
</div>
</div>
</div>
I want to achieve a grid like the shown below:
I have been looking to Twitter Bootstrap grid system, but since it is oriented to rows, I can't see how to achieve this.
Is there any way of doing it, or should I stick to manually css?
You can nest Rows and cols:
<div class="row">
<div class="col-md-9">
<div class="row">
<div class="col-md-12">left top</div>
<div class="col-md-12">left bottom</div>
</div>
</div>
<div class="col-md-3">
<div class="row">
<div class="col-md-12">right top</div>
<div class="col-md-12">right bottom</div>
</div>
</div>
</div>
See http://getbootstrap.com/css/#grid under "Nesting Columns"
You can still use Bootstrap grid with some custom styles:
.block {
border: 3px #222 solid;
padding: 10px;
margin-bottom: 10px;
}
.block-1 {
height: 100px;
}
.block-2 {
height: 50px;
}
.block-3 {
height: 50px;
}
.block-4 {
height: 100px;
}
<link data-require="bootstrap-css#*" data-semver="3.3.1" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
<div class="container">
<div class="row">
<div class="col-xs-8">
<div class="block block-1">Block 1</div>
<div class="block block-2">Block 2</div>
</div>
<div class="col-xs-4">
<div class="block block-3">Block 3</div>
<div class="block block-4">Block 4</div>
</div>
</div>
</div>
Just set 2 parents width col-xs-* with children
main{padding: 20px}
section, article{display: inline}
article, div{border: 4px solid black; margin-bottom: 10px}
article:nth-child(1){height: 80px}
article:nth-child(2){height: 40px}
div:nth-child(1){height: 30px}
div:nth-child(2){height: 90px}
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<main class=row>
<section class="col-xs-8">
<article></article>
<article></article>
</section>
<aside class="col-xs-4">
<div></div>
<div></div>
</aside>
</main>
Read more about Grid system .