I wanted to create three boxes and align them properly. It would be two boxes in 1 row and a third box under the second box. The second and third box would have the height equal to the first box. You can visually see what I'm trying to do here: http://codepen.io/sibraza/pen/KMzwWR
Here is an example of what I'm trying to achieve:
Snippet:
.block {
float: left;
display: inline-block;
margin: auto;
width: 250px;
height: 200px;
border: 3px solid #73AD21;
padding: 10px;
margin-left: 300px;
margin-top: 200px;
}
.block2 {
float: left;
display: inline-block;
margin: auto;
width: 250px;
margin-top: 200px;
border: 3px solid #73AD21;
padding: 10px;
}
.block3 {
float: left;
margin: auto;
width: 250px;
height: 200px;
margin-top: 290px;
border: 3px solid #73AD21;
padding: 10px;
}
<div class="container-fluid">
<div class="row">
<div class="col-4-md text-center block">
<h2> Some Text </h2>
</div>
<div class="col-4-md text-center block2">
<h2> Other Text </h2>
</div>
<div class="col-4-md text-center block3">
<h2> More Text </h2>
</div>
</div>
</div>
Flexbox can do that with a wrapper for the right side divs
* {
box-sizing: border-box;
}
.row {
display: flex;
}
div {
border: 1px solid #73AD21;
}
.block {
height: 200px;
}
.row > div {
flex: 1;
}
.col-wrap {
display: flex;
flex-direction: column;
}
.col-wrap > div {
flex: 1;
}
<div class="container-fluid">
<div class="row">
<div class="col-4-md text-center block">
<h2> Some Text </h2>
</div>
<div class="col-wrap">
<div class="col-4-md text-center block2">
<h2> Other Text </h2>
</div>
<div class="col-4-md text-center block3">
<h2> More Text </h2>
</div>
</div>
</div>
</div>
Easiest way to sort this is to have the bigger div ont he let as is, and create a container Div for the two on the right. so the css would be somehting like this:
.block_on_the_left {
float:left;
width:50%;
}
#container_on_the_right {
float:left;
width:50%;
}
.block2 {
width:100%;
}
.block3 {
width:100%;
}
Your HTML would need to be:
<div class="block_on_the_left">
some stuff here for the left bit
</div>
<div id="container_on_the_right">
<div class=".block2">
some stuff
</div>
<div class=".block3">
some more stuff
</div>
</div>
The container will hold both the smaller divs inside it, and group them together.
Here is a simple solution using flex-box.
Hope this will help. Thanks :)
.row{
display: flex;
}
.block {
width: 250px;
height: 400px;
border: 3px solid red;
box-sizing: border-box;
}
.block2 {
width: 250px;
height: 200px;
border: 3px solid #73AD21;
box-sizing: border-box;
}
.block3 {
width: 250px;
height: 200px;
border: 3px solid blue;
box-sizing: border-box;
align-self: flex-end;
margin-left: -250px;
}
<div class="container-fluid">
<div class="row">
<div class="col-4-md text-center block">
<h2> Some Text </h2>
</div>
<div class="col-4-md text-center block2">
<h2> Other Text </h2>
</div>
<div class="col-4-md text-center block3">
<h2> More Text </h2>
</div>
</div>
</div>
Related
I am trying to create three parallel columns of the same width (33.3%) and height (100%). In each column, I want to split it vertically into 80% - 20% ratios. The code below seems straight forward, but I couldn't achieve that. If someone could advise?
Note that I keep the flex and wrap stuff in the inner parts because I will be adding elements into them later. Thanks.
#outer-container {
height: 500px;
width: 100%;
}
#left-container, #mid-container, #right-container {
background-color: #495052;
width: 33.3%;
height: 100%;
border: 1px solid;
border-color: #cae329; /*Bright citrus*/
overflow: auto;
}
#left-top-container, #mid-top-container, #right-top-container {
display: flex;
flex-wrap: wrap;
background-color: #495052;
width: 100%;
height: 80%;
overflow: auto;
}
#left-bottom-container, #mid-bottom-container, #mid-bottom-container {
display: flex;
flex-wrap: wrap;
background-color: yellow;
width: 100%;
height: 20%;
border: 1px solid;
border-color: #cae329;
overflow: auto;
}
<div id="outer-container">
<div id="left-container">
<div id="left-top-container">
</div>
<div id="left-bottom-container">
</div>
</div>
<div id="mid-container">
<div id=mid-top-container">
</div>
<div id="mid-bottom-container">
</div>
</div>
<div id="right-container">
<div id="right-top-container">
</div>
<div id="right-bottom-container">
</div>
</div>
</div>
You've got a few typos in your code. Notably a missing quotation mark on one of your ids in your HTML (mid-top-container), and a duplicate rule for #mid-bottom-container instead of #right-bottom-container.
Also, your columns are still display:block, so they will not stay on the same line. I changed them to display: inline-block; to fix that. Their widths should be calc(100% / 3) to make them exactly one third of the width. They need box-sizing: border-box to make the padding/border part of the width figure, and finally, the parent #outer-container needs font-size:0 to remove any white space between the columns.
#outer-container {
height: 500px;
width: 100%;
font-size: 0;
}
#left-container, #mid-container, #right-container {
display: inline-block;
background-color: #495052;
width: calc(100% / 3);
height: 100%;
border: 1px solid;
border-color: #cae329; /*Bright citrus*/
overflow: auto;
box-sizing: border-box;
}
#left-top-container, #mid-top-container, #right-top-container {
display: flex;
flex-wrap: wrap;
background-color: #495052;
width: 100%;
height: 80%;
overflow: auto;
}
#left-bottom-container, #mid-bottom-container, #right-bottom-container {
display: flex;
flex-wrap: wrap;
background-color: yellow;
width: 100%;
height: 20%;
border: 1px solid;
border-color: #cae329;
overflow: auto;
}
<div id="outer-container">
<div id="left-container">
<div id="left-top-container">
</div>
<div id="left-bottom-container">
</div>
</div>
<div id="mid-container">
<div id="mid-top-container">
</div>
<div id="mid-bottom-container">
</div>
</div>
<div id="right-container">
<div id="right-top-container">
</div>
<div id="right-bottom-container">
</div>
</div>
</div>
Though there are some Typos. But some un-necessary ids and CSS is also present in the Code.
You may try CSS-GRIDS and Flexbox (in a better way) to achieve the same with much lesser code so that the performance of the app increases.
Have removed all extra selectors.
CODEPEN: https://codepen.io/emmeiWhite/pen/RwGyBLO
*{
margin:0;
padding:0;
box-sizing:border-box;
}
#outer-container {
height: 500px;
display:grid;
grid-template-columns:repeat(3,1fr);
width: 100%;
}
.column-wrapper{
display:flex;
flex-direction:column;
background-color: #495052;
border: 1px solid;
border-color: #cae329; /*Bright citrus*/
}
.top-section{
height:80%;
}
<div id="outer-container">
<div class="column-wrapper">
<div class="top-section">
left top
</div>
<div>
bottom
</div>
</div>
<div class="column-wrapper">
<div class="top-section">
mid-top
</div>
<div>
mid-bottom
</div>
</div>
<div class="column-wrapper">
<div class="top-section">
right-top
</div>
<div>
right-bottom
</div>
</div>
</div>
I want to display divs in 2 columns ordered from above to below:
I tried the following solution based on column-count which works nice if the number of divs is even but breaks if it's odd.
.container {
column-count:2;
}
.square {
box-sizing: border-box;
border: 1px solid black;
height: 200px;
padding: 5px;
}
<div class="container">
<div class="square">1</div>
<div class="square">2</div>
<div class="square">3</div>
</div>
Then I tried a solution based on flex, but I can't seem to find a solution for the order:
.container {
display:flex;
flex-wrap: wrap;
}
.square {
box-sizing: border-box;
border: 1px solid black;
flex: 0 0 50%;
height: 200px;
}
<div class="container">
<div class="square">1</div>
<div class="square">2</div>
<div class="square">3</div>
</div>
What I want to achieve is smoothing like this:
add display:inline-block;width:100%; to the square element:
.container {
column-count: 2;
}
.square {
border: 1px solid black;
height: 200px;
display:inline-block;
width:100%;
}
<div class="container">
<div class="square">1</div>
<div class="square">2</div>
<div class="square">3</div>
</div>
How would i align all these 6 divs vertically in a 3x3 pattern so that the top and bottom divs content are aligned with each other so it looks good. i've tried some vertical-align: middle; with no sucess.
It's a must to be 100% responsive and that the number also is centered and aligned so whatever number gets there is aligned.
.top-right-container {
position: absolute;
border: 1px solid white;
height: 20%;
width: 50%;
right: 0;
top: 0;
}
.stats-container {
position: relative;
float: left;
border: 1px solid white;
width: 75%;
height: 80%;
}
.Agility,
.Stamina,
.Respect,
.Intelligence,
.Strength,
.Cash {
display: inline-block;
color: black;
}
.Agility,
.Intelligence {
float: left;
margin-left: 10%;
}
.Stamina,
.Strength {
margin: 0 auto;
}
.Respect,
.Cash {
margin-right: 10%;
float: right;
}
.stats-container h2 {
font-family: Marker-Felt;
margin: 0;
font-size: calc(0.7vh + 1.2vw);
}
.stats-container p {
margin: 5%;
text-align: center;
font-size: calc(0.5vh + 0.8vw);
}
.top-stats,
.bottom-stats {
width: 100%;
text-align: center;
}
<div class="top-right-container">
<div class="stats-container">
<div class="top-stats">
<div class="Agility">
<h2>Agility</h2>
<p>10</p>
</div>
<div class="Stamina">
<h2>Stamina</h2>
<p>10</p>
</div>
<div class="Respect">
<h2>Respect</h2>
<p>10</p>
</div>
</div>
<div class="bottom-stats">
<div class="Intelligence">
<h2>Intelligence</h2>
<p>10</p>
</div>
<div class="Strength">
<h2>Strength</h2>
<p>10</p>
</div>
<div class="Cash">
<h2>Cash</h2>
<p>10</p>
</div>
</div>
</div>
</div>
You can do it with the Flexbox:
* {margin:0;padding:0;box-sizing:border-box}
html, body {width:100%}
.stats-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
.top-stats,
.bottom-stats {
display: flex;
width: 100%;
text-align: center;
}
.Agility,
.Stamina,
.Respect,
.Intelligence,
.Strength,
.Cash {
flex: 1;
}
.stats-container h2 {
font-size: calc(0.7vh + 1.2vw);
}
.stats-container p {
font-size: calc(0.5vh + 0.8vw);
}
<div class="top-right-container">
<div class="stats-container">
<div class="top-stats">
<div class="Agility">
<h2>Agility</h2>
<p>10</p>
</div>
<div class="Stamina">
<h2>Stamina</h2>
<p>10</p>
</div>
<div class="Respect">
<h2>Respect</h2>
<p>10</p>
</div>
</div>
<div class="bottom-stats">
<div class="Intelligence">
<h2>Intelligence</h2>
<p>10</p>
</div>
<div class="Strength">
<h2>Strength</h2>
<p>10</p>
</div>
<div class="Cash">
<h2>Cash</h2>
<p>10</p>
</div>
</div>
</div>
</div>
responsive 2 rows and 6 boxes
Here is some code you can work with.
The container of all the divs .container will take 100% of the page eg. its <body> .
The rows .statRow will take 100% of its parent the container.
Now the boxes .box will take 33% of its parent width.
Then adding 3 of these boxes 33%+33%+33% will take up 99% of the container.
Additionally borders usually take up more space so width + border is its actual width.
This is fixed with chancing the elements box-sizing to border-box.
.container {
border: 10px solid black;
width: 100%;
box-sizing: border-box;
border-radius: 5px;
}
.statRow {
width: 100%;
display: block;
}
.box {
color: white;
display: inline-block;
text-align: center;
width: 33%;
border: 10px solid white;
box-sizing: border-box;
border-radius: 15px;
background-color: #222;
}
<div class="container">
<div class="statBubble">
<div class="box">
<h5>Agility</h5>
<p>10</p>
</div><!--
--><div class="box">
<h5>Strength</h5>
<p>10</p>
</div><!--
--><div class="box">
<h5>Stat</h5>
<p>number</p>
</div>
</div>
<div class="statRow">
<div class="box">
<h5>Wisdom</h5>
<p>100</p>
</div><!--
--><div class="box">
<h5>Stat</h5>
<p>number</p>
</div><!--
--><div class="box">
<h5>Stat</h5>
<p>number</p>
</div>
</div>
</div>
I am trying to display multiple circles on the same horizontal axis but with different width and height. The problem is that the circles are shrinked.
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
.circles-container {
display: table;
border-spacing: 40px;
}
.row {
display: table-row;
}
.circle {
width: 100px;
height: 100px;
border: 1px solid #000;
border-radius: 50%;
text-align: center;
vertical-align: middle;
display: table-cell;
}
.cell {
display: table-cell;
}
.big-circle {
width: 300px;
height: 300px;
}
<div class="circles-container">
<div class="row">
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="big-circle circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="big-circle circle">
<span>TEXT</span>
</div>
</div>
</div>
</div>
JSFIDDLE: https://jsfiddle.net/cxuxgy0u/
You should not use the table layout for this. Your HTML does not semantically represent a table, so table element is worng to use.
What you want to do can be achieved with Flexbox.
article {
display: flex;
align-items: center;
}
article > div + div {
margin-left: 1rem;
}
article > div {
flex-shrink: 0;
height: 4rem;
width: 4rem;
border-radius: 50%;
border: solid 1px black;
display: flex;
justify-content: center;
align-items: center;
}
article > div:nth-child(2) {
height: 6rem;
width: 6rem;
}
<article>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
<div><span>TEXT</span></div>
</article>
You might want to read more about Flexbox on MDN.
A simple flexbox solution. Just be sure to set flex-shrink to 0, because the initial value is 1, which allows flex items to shrink when necessary to prevent overflowing the container.
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
.circles-container {
display: flex;
align-items: center;
}
.circle {
display: flex;
align-items: center;
justify-content: center;
text-align: center;
flex: 0 0 100px; /* flex-shrink: 0, to disable shrinking default */
height: 100px;
border-radius: 50%;
margin: 20px;
border: 1px solid #000;
}
.big-circle {
flex-basis: 300px;
height: 300px;
}
<div class="circles-container">
<div class="circle">
<span>TEXT</span>
</div>
<div class="circle">
<span>TEXT</span>
</div>
<div class="big-circle circle">
<span>TEXT</span>
</div>
<div class="circle">
<span>TEXT</span>
</div>
<div class="big-circle circle">
<span>TEXT</span>
</div>
</div>
https://jsfiddle.net/cxuxgy0u/7/
Try this:
HTML
<div class="container">
<div class="circle">Text</div>
<div class="circle">Text</div>
<div class="circle">Text</div>
<div class="circle">Text</div>
</div>
CSS
.container {
display:flex;
justify-content: space-around;
align-items: center;
height: 100vh;
}
.circle {
background: white;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
}
.circle:nth-child(odd) { width: 100px; height: 100px; }
.circle:nth-child(even) { width: 200px; height: 200px; }
Uses flexbox and is the simplest way to achieve what you want.
Here's a fiddle https://jsfiddle.net/itsag/sk3tdo4L/
Hope it helps!
I think your problem is found in the styling.
For each circle, you need to remove the style
display:table-cell
vertical-align: middle;
and then u need to bring in line-height. The line-height should be equal to the height of the circle, for for the smaller circle, you will have
line-height:100px //this brings the text to the middle of the circle vertically.
Then also, you need to increase the border-radius from 50% to 100%
border-radius:100%;
Therefore, your css will not look like this
body, html {
height: 100%;
margin: 0;
padding: 0;
}
.circles-container{
display: table;
border-spacing: 40px;
}
.row {
display: table-row;
}
.circle {
width: 100px;
height: 100px;
border: 1px solid #000;
border-radius: 100%;
text-align: center;
line-height:100px;
}
.cell {
display: table-cell;
}
.big-circle {
width: 300px;
height: 300px;
line-height:300px;
}
This should help you.
Flexbox:
container {
display: flex;
justify-content: center;
}
If you want space between the pictures, use:
margin-left:
or
margin-right:
try this
body, html {
height: 100%;
margin: 0;
padding: 0;
}
.circles-container{
display: table;
border-spacing: 40px;
}
.row {
display: flex;
}
.circle {
padding: 40px 30px;
border: 1px solid #000;
border-radius: 50%;
text-align: center;
vertical-align: middle;
position: relative;
}
.cell {
}
.big-circle {
padding: 150px;
}
<div class="circles-container">
<div class="row">
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="big-circle circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="circle">
<span>TEXT</span>
</div>
</div>
<div class="cell">
<div class="big-circle circle">
<span>TEXT</span>
</div>
</div>
</div>
</div>
I am trying to positionning 5 blocs in my page.
I would like to have 3 columns in fact :
First column : Two blocs (Favorites and meetings)
Second column : (recents news and tweets)
Third column : Other favorites column
Like this :
But i have a problem for positionning the third column.
Here is my HTML code :
<div class="containerBloc" >
<div class="box-1">
<div class="box-menu"><img src="src/ui_dashboard/img/ic_action_users.png" id="imgIntoMenu"><span id="textMenu">Favorites</span></div>
</div>
<div class="box-2">
<div class="box-menu"><img src="src/ui_dashboard/img/ic_action_feed.png" id="imgIntoMenu"><span id="textMenu">Recent news</span></div>
</div>
<div class="box-5">
<div class="box-menu"><img src="src/ui_dashboard/img/ic_action_users.png" id="imgIntoMenu"><span id="textMenu">Favorites</span></div>
</div>
<div class="box-3">
<div class="box-menu"><img src="src/ui_dashboard/img/ic_action_calendar_month.png" id="imgIntoMenu"><span id="textMenu">Upcoming meetings</span></div>
</div>
<div class="box-4">
<div class="box-menu"><img src="src/ui_dashboard/img/ic_action_twitter.png" id="imgIntoMenu"><span id="textMenu">Tweets de</span></div>
</div>
</div>
And CSS :
.containerBloc {
max-width: 1200px;
margin: 0 auto;
overflow: hidden;
margin-top: 150px;
}
.box-1, .box-2, .box-3, .box-4 {
float: left;
margin: 1%;
min-height: 150px;
box-sizing: border-box;
-moz-box-sizing: border-box;
background-color: #FFFFFF;
border: 1px solid #B0B0B0;
}
.box-1, .box-2 {
height: 200px;
}
.box-1, .box-3 {
width: 30%;
}
.box-2, .box-4 {
width: 60%;
}
.box-5 {
margin: 1%;
min-height: 150px;
box-sizing: border-box;
-moz-box-sizing: border-box;
background-color: #FFFFFF;
border: 1px solid #B0B0B0;
float : right;
height : 100%;
width : 40%;
}
.box-menu {
background-color: #EFEFEF ;
height : 40px;
color : #B0B0B0;
border-bottom: 1px solid #B0B0B0;
}
#imgIntoMenu {
margin-left : 10px;
margin-top : 4px;
}
#textMenu {
margin-left: 10px;
position: absolute;
margin-top: 13px;
}
My complete code is here : http://jsfiddle.net/mzV85/
Thanks a lot for your help.
This FIDDLE should get you going.there is some tydying up to do in the CSS code.
The point is to Use Divs to wrap your columns. To set there added widths to 100% and to float them to the left.
HTML:
<div class="containerBloc">
<div class="col">
<div class="box-1">
<div class="box-menu">
<img src="src/ui_dashboard/img/ic_action_users.png" id="imgIntoMenu" /> <span id="textMenu">Favorites</span>
</div>
</div>
<div class="box-2">
<div class="box-menu">
<img src="src/ui_dashboard/img/ic_action_feed.png" id="imgIntoMenu" /> <span id="textMenu">Recent news</span>
</div>
</div>
</div>
<div class="col">
<div class="box-3">
<div class="box-menu">
<img src="src/ui_dashboard/img/ic_action_calendar_month.png" id="imgIntoMenu" /><span id="textMenu">Upcoming meetings</span>
</div>
</div>
<div class="box-4">
<div class="box-menu">
<img src="src/ui_dashboard/img/ic_action_twitter.png" id="imgIntoMenu" /><span id="textMenu">Tweets de #__Erwan</span>
</div>
</div>
</div>
<div class="col">
<div class="box-5">
<div class="box-menu">
<img src="src/ui_dashboard/img/ic_action_users.png" id="imgIntoMenu" /><span id="textMenu">Favorites</span>
</div>
</div>
</div>
</div>
CSS:
.col{
float:left;
width:33%;
margin:0;
padding:0;
}
.containerBloc {
max-width: 1200px;
margin: 0 auto;
overflow: hidden;
margin-top: 150px;
}
.box-1, .box-2, .box-3, .box-4 {
margin: 1%;
min-height: 150px;
box-sizing: border-box;
-moz-box-sizing: border-box;
background-color: #FFFFFF;
border: 1px solid #B0B0B0;
}
.box-1, .box-2 {
height: 200px;
}
.box-1, .box-3 {
width: 98%;
}
.box-2, .box-4 {
width: 98%;
}
.box-5 {
margin: 1%;
min-height: 150px;
box-sizing: border-box;
-moz-box-sizing: border-box;
background-color: #FFFFFF;
border: 1px solid #B0B0B0;
float : right;
height : 100%;
width : 98%;
}
.box-menu {
background-color: #EFEFEF;
height : 40px;
color : #B0B0B0;
border-bottom: 1px solid #B0B0B0;
}
#imgIntoMenu {
margin-left : 10px;
margin-top : 4px;
}
#textMenu {
margin-left: 10px;
position: absolute;
margin-top: 13px;
}
You should really be using a responsive grid system like Bootstrap.
However if I understand correctly you're just wanting to put together a three column layout, like this - http://jsfiddle.net/webbymatt/ngxA6/
<div class="container">
<div class="col-1">
<div class="child">
Favourites
</div>
<div class="child clearfix">
Meetings
</div>
</div>
<div class="col-2">
<div class="child">
Recent
</div>
<div class="child clearfix">
Tweets
</div>
</div>
<div class="col-3">
<div class="child">
Favourites
</div>
</div>
</div>
The layout is breaking because the percentage widths you are using add up to more than 100%. If you reduce the width of your columns it works.
http://jsfiddle.net/mzV85/15/
CSS:
.box-1, .box-3 {
width: 25%;
}
.box-2, .box-4 {
width: 50%;
}
.box-5 {
width : 19%;
}
Have Done a fiddle. Please check http://jsfiddle.net/mzV85/21/ . Please check the width of the containers properly.
Problem : your markup has box-1, box-2 and box-5 in one line.....calculate their combined width and it comes > 100%; that's why your third box is not aligning
see this demo http://jsfiddle.net/mzV85/10/ (aligned the box in one line,not did the complete designing)
.box-1, .box-2 {
height: 200px;
width:20%; /* do some changes here */
}
.box-1, .box-3 {
width: 30%;/* do some changes here */
}
Play around with the width and you will get it in one line when its combined width <=100%