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/
Related
I have an issue with my bootstrap layout.
Basically, everything looks OK on larger screens but on smaller screens my footer overlaps the content or the content overlaps the footer!
This is the code I have: https://jsfiddle.net/xpvt214o/639029/
If you make the HTML part larger and smaller and look at the footer, you will see the issue.
This is my full code:
html,body,.col-md-12,.row {
height:100%;
}
.row > div {
height:100%;
}
.YOsidemenu{
padding:0;
font-weight:bold;
background-color: #ffc90e;
padding-top:10px;
max-width:200px;
}
#media only screen and (max-width:768px) {
.YOsidemenu{
display:none;
}
}
/* to make columns visible */
.row .col-sm-2 {
background-color:red;
}
.row .col-sm-10 {
background-color:green;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div style="height:100%; background:#fff;width:100%;padding:0;" class="container">
<div class="col-md-12">
<div class="row">
<div class="col-sm-2">
Sidebar content
</div>
<div class="col-sm-10">
Body content
</div>
</div>
</div>
</div>
<!-- Footer -->
<section id="footer" style="text-align:left; !important">
<div class="container">
<div class="row text-center text-xs-center text-sm-left text-md-left" style="text-align:left; !important">
<div class="col-xs-12 col-sm-4 col-md-4">
<h5>Quick links</h5>
<ul class="list-unstyled quick-links">
<li>Home</li>
<li>Help</li>
<li>Sign-in</li>
<li>affiliate</li>
<li>Promote</li>
</ul>
</div>
<div class="col-xs-12 col-sm-4 col-md-4">
<h5>Support</h5>
<ul class="list-unstyled quick-links">
<li><i class="fa fa-envelope"></i>support#email.com</li>
<li><i class="fa fa-phone-square"></i>+44 7842227819</li>
<li><i class="fa fa-globe"></i>www.website.com</li>
</ul>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 mt-2 mt-sm-2 text-center text-white">
<p>this site a registered company. </p>
<p class="h6">© All right Reversed.<a class="text-green ml-2" href="https://www.website.com" target="_blank">website</a></p>
</div>
</hr>
</div>
</div>
</section>
<!-- ./Footer -->
Could someone please be kind enough and help me with this issue?
Thanks in advance.
Try removing height: 100% from the div. On mobile the container is 100% high, but because the columns get stacked and each column inherits the height, you have a parent with 100% height and two columns with each 100%, making it 200% of height.
Is this what you are looking for?
html,
body,
.col-md-12,
.row {
height: 100%;
}
.row>div {
height: 100%;
}
.YOsidemenu {
padding: 0;
font-weight: bold;
background-color: #ffc90e;
padding-top: 10px;
max-width: 200px;
}
#media only screen and (max-width:768px) {
.YOsidemenu {
display: none;
}
}
/* to make columns visible */
.row .col-sm-2 {
background-color: red;
}
.row .col-sm-10 {
background-color: green;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div style="height:100%; background:#fff;width:100%;padding:0;" class="container">
<div class="col-md-12">
<div class="row">
<div class="col-sm-2 col-xs-2">
Sidebar content
</div>
<div class="col-sm-10 col-xs-10">
Body content
</div>
</div>
</div>
</div>
<!-- Footer -->
<section id="footer" style="text-align:left; !important">
<div class="container">
<div class="row text-center text-xs-center text-sm-left text-md-left" style="text-align:left; !important">
<div class="col-xs-12 col-sm-4 col-md-4">
<h5>Quick links</h5>
<ul class="list-unstyled quick-links">
<li>Home</li>
<li>Help</li>
<li>Sign-in</li>
<li>affiliate</li>
<li>Promote</li>
</ul>
</div>
<div class="col-xs-12 col-sm-4 col-md-4">
<h5>Support</h5>
<ul class="list-unstyled quick-links">
<li><i class="fa fa-envelope"></i>support#email.com</li>
<li><i class="fa fa-phone-square"></i>+44 7842227819</li>
<li><i class="fa fa-globe"></i>www.website.com</li>
</ul>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 mt-2 mt-sm-2 text-center text-white">
<p>this site a registered company. </p>
<p class="h6">© All right Reversed.<a class="text-green ml-2" href="https://www.website.com" target="_blank">website</a></p>
</div>
</hr>
</div>
</div>
</section>
<!-- ./Footer -->
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 would like to create 3 boxes with equal height using Bootstrap but I am not sure how to do it.
I found I can use flexbox and my main boxes will be equal height but I want some inner div to have border and that div to fill the main div and I cannot do it.
I have also some other problems: how to position button at the center bottom of that div and I have there also some description paragraph and I would like those paragrahps also to be equal heights, because I use some border at the bottom.
Here is my example code:
<div class="container text-center">
<div class="row">
<div class="col-md-4">
<div class="box">
<div class="box-header">
</div>
<div class="box-body">
<p class="box-info">Some description of product 1</p>
<ul class="box-list">
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
<button class="btn btn-default">Register</button>
</div>
</div>
</div>
<div class="col-md-4">
<div class="box">
<div class="box-header">
</div>
<div class="box-body">
<p class="box-info">Some description of product 2 which can be very loooooooooooooong</p>
<ul class="box-list">
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
<button class="btn btn-default">Register</button>
</div>
</div>
</div>
<div class="col-md-4">
<div class="box">
<div class="box-header">
</div>
<div class="box-body">
<p class="box-info">Some description of product 3</p>
<ul class="box-list">
<li>test</li>
<li>test</li>
<li>test</li>
</ul>
<button class="btn btn-default">Register</button>
</div>
</div>
</div>
</div>
</div><!-- /.container -->
Css:
body {
padding-top: 50px;
}
.box-header {
height: 100px;
background-color: blue;
text-align: center;
}
.box-body {
position: relative;
padding: 20px 30px;
border: 1px solid green;
border-top: none;
}
.box-info {
border-bottom: 1px solid #e7e7e7;
}
.box-list {
text-align: left;
}
My description can not be clear, so you can find a Bootply here.
I have a jsfiddle here - http://jsfiddle.net/gomwyt2j/1/
Super simple, I just need to center the text vertically so it lines up with the button
Nothing I try seems to work
<div class="container">
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-3 text-center text"><p>Some Info</p></div>
<div class="col-sm-4 text-center text"><p>Some more Info Her</p></div>
<div class="col-sm-3 text-center btn-btn"><a class="btn">Read More</a></div>
<div class="col-sm-1"></div>
</div>
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-3 text-center text"><p>Some Info</p></div>
<div class="col-sm-4 text-center text"><p>Some more Info Her</p></div>
<div class="col-sm-3 text-center"><a class="btn">Read More</a></div>
<div class="col-sm-1"></div>
</div>
</div>
One possible solution is to use line: height:
html
<div class="container">
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-3 text-center text">
<p>Some Info</p>
</div>
<div class="col-sm-4 text-center text">
<p>Some more Info Her</p>
</div>
<div class="col-sm-3 text-center btn-btn"><a class="btn">Read More</a>
</div>
<div class="col-sm-1"></div>
</div>
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-3 text-center text">
<p>Some Info</p>
</div>
<div class="col-sm-4 text-center text">
<p>Some more Info Her</p>
</div>
<div class="col-sm-3 text-center"><a class="btn">Read More</a>
</div>
<div class="col-sm-1"></div>
</div>
</div>
css
.row {
background: gray;
color: white;
padding: 5px 0;
margin: 0 0 10px 0;
}
.text p {
display: inline-block;
//padding: 9px 0 0 0;
vertical-align: middle;
}
.btn-btn {
}
.btn {
background: red;
color: white;
padding-top: 10px;
padding-bottom: 10px;
vertical-align: middle;
}
.col-sm-3, .col-sm-4 {
line-height: 35px; /*add line height*/
}
p {
margin: 0;/*remove margin from p*/
}
fiddle
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>