I am trying to align 3 boxes and 2 images.
2 boxes vertically with there is an img between
3rd box standing right of them with an arrow img pointing it like this:
Example box css:
.box{
width: 80px;
height: 80px;
background: #8C8C8C;
margin:0 auto;
border: solid 3px #8B0000;
}
Use flexbox and divide to 3 section(3 divs) inside the wrap div
.wrap{
display:flex;
}
.box{
width: 80px;
height: 80px;
background: #8C8C8C;
margin:0 auto;
border: solid 3px #8B0000;
}
.img1 img{
width: 80px;
height: 150px;
}
.part2 img{
width: 150px;
height: 80px;
}
.part2,.part3{
margin-top: 100px;
}
.part3 .box{
margin-left: 40px;
}
<div class="wrap">
<div class="part1">
<div class="box">
</div>
<div class="img1">
<img src="https://material.angular.io/assets/img/examples/shiba1.jpg"/>
</div>
<div class="box">
</div>
</div>
<div class="part2">
<img src="https://material.angular.io/assets/img/examples/shiba1.jpg"/>
</div>
<div class="part3">
<div class="box">
</div>
</div>
</div>
If you have constant number of elements. (3 boxes and 2 images with fixed width and height), you can create wrapper box with relative position, then add position absolute to child nodes and write needed positions. for example:
.wrapper {
width: 100%;
box-sizing: border-box;
position: relative;
}
.child-arrow {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
You can use flexbox to position your boxes by rows and columns.
#cont1 {
display:flex;
flex-direction:row;
}
.box{
width: 80px;
height: 80px;
background: #8C8C8C;
border: solid 3px #8B0000;
}
<div>
<div class="box">Box 2
</div>
<div id="cont1">
<div> IMG1 </div>
<div> IMG2 </div>
<div class="box">Box 3</div>
</div>
<div class="box">
Box 1
</div>
</div>
You should try to use the float/clear attribute:
.box1{
float: left;
}
.box2{
float: right;
}
.image{
float: left;
}
.box3{
float: left;
}
Afterwards just use position: relative within your classes fix the positioning.
Related
I have a vertical list of element and I want to add a divider that has bulb on top with an icon and is clickable.
For example like in the code bellow but where the divider has a circle on top with an icon( in the margin on top).
.container {
display:flex;
}
.left, .right {
width: 150px;
height: 150px;
background-color:red;
margin-top: 24px;
}
.divider {
background-color: grey;
width: 4px;
height:150px;
margin-top: 24px;
}
<div class="container">
<div class="left">left</div>
<div class="divider"></div>
<div class="right">right</div>
</div>
Do you mean something like this?
.container {
display:flex;
}
.left, .right {
width: 150px;
height: 150px;
background-color:red;
margin-top: 24px;
}
.divider {
display: block;
margin: 20px 0;
text-align: center;
min-height: 20px;
position: relative;
}
<div class="container">
<div class="left">left</div>
<div class="divider"> <img src="https://icons-for-free.com/download-icon-lightbulb+outline+24px-131985192644521589_16.png"></div>
<div class="right">right</div>
</div>
I've got the following setup http://jsfiddle.net/47x60k4w/529/.
HTML
<div class="header">
header
</div>
<div class="inner_block">
<div class="column">
<img src="xxx" />
</div>
<div class="column">
<img src="xxx" />
</div>
<div class="column">
<img src="xxx" />
</div>
</div>
<div class="footer">
footer
</div>
The inner_block should overlap the header class and the footer should be placed right behind the inner_block.
In my solution I just don't get the footer behind the inner_block without doing not responsible stuff like calling a margin-top with x.xem on it. I just found some links with z-index stuff which didn't worked for me because the inner_block lost his passed height and width from the nested block.
The result should look like this beautiful mockup.
Do you have any ideas?
Thanks in advance.
So I made the following changes to your code:
Remove the position: absolute for the inner-block.
As you are floating the contents of the inner-block you have clear the floats so that the parent container will not lose height.
.inner_block:after {
content: '';
display: block;
clear: both;
}
Whenever using floats, remember to clear it.
Added position: relative to the inner_block to position it over the header and footer.
Added display: block to the img so that you can remove the small space below it characteristic on inline elements (the default display).
Also tinkered a bit with the margins and widths to achieve the layout.
.header {
position: relative;
background-color: black;
width: 100%;
height: 50px;
}
.footer {
clear: both;
background-color: red;
width: 100%;
height: 50px;
}
.inner_block {
position: relative;
/*width: 100%;*/
border: solid 1px black;
padding: 5px;
margin-left: 2.5%;
margin-top: -2.5%;
margin-right: 2.5%;
margin-bottom: 2.5%;
background-color: white;
}
.inner_block:after {
content: '';
display: block;
clear: both;
}
.column {
max-width: 30%;
float: left;
margin-right: 2.5%;
}
.column:first-child{
margin-left: 2.5%;
}
.column:last-child{
margin-left: 0;
}
.column img {
max-width: 100%;
height: auto;
display: block;
}
<div class="header">
</div>
<div class="inner_block">
<div class="column">
<img src="http://www.healthytravellovers.com/wp-content/uploads/2016/09/photo233227749810088605.jpg" />
</div>
<div class="column">
<img src="http://www.healthytravellovers.com/wp-content/uploads/2016/09/photo233227749810088607.jpg" />
</div>
<div class="column">
<img src="http://www.healthytravellovers.com/wp-content/uploads/2016/09/photo233227749810088606.jpg" />
</div>
</div>
<div class="footer">
test
</div>
Hope this gives you a head-start. Check it out and let me know your feedback on this. Thanks!
Alternate Solution:
So here is a solution using a flexbox which is easier to set up:
First remove the floating container and the clearfix.
Now Wrap the inner_block with another div
.inner_block_wrapper {
margin: -2.5% 2.5% 2.5% 2.5%;
background-color: white;
position: relative;
}
.inner_block {
border: solid 1px black;
background-color: white;
padding: 5px;
display: flex;
justify-content: center;
}
.column {
margin: 5px;
}
Using display: flex allows the images to take the available space along the row and justify-content: center aligns it along the center. Check this out!
.header {
position: relative;
background-color: black;
width: 100%;
height: 50px;
}
.footer {
clear: both;
background-color: red;
width: 100%;
height: 50px;
}
.inner_block_wrapper {
margin: -2.5% 2.5% 2.5% 2.5%;
background-color: white;
position: relative;
}
.inner_block {
border: solid 1px black;
background-color: white;
padding: 5px;
display: flex;
justify-content: center;
}
.column {
margin: 5px;
}
.column img {
max-width: 100%;
height: auto;
display: block;
}
<div class="header">
</div>
<div class="inner_block_wrapper">
<div class=" inner_block ">
<div class="column ">
<img src="http://www.healthytravellovers.com/wp-content/uploads/2016/09/photo233227749810088605.jpg " />
</div>
<div class="column ">
<img src="http://www.healthytravellovers.com/wp-content/uploads/2016/09/photo233227749810088607.jpg " />
</div>
<div class="column ">
<img src="http://www.healthytravellovers.com/wp-content/uploads/2016/09/photo233227749810088606.jpg " />
</div>
</div>
</div>
<div class="footer ">
test
</div>
You can even try something as below, your codes were fine just set your .footer margin-top equal to the height of .header and .inner_block using css calc() function.
.header{
position:relative;
background-color:black;
width:100%;
height:50px;
}
.footer{
background-color:red;
width:100%;
height:50px;
margin-top:calc(100% - 82%);
}
.inner_block{
position: absolute;
width:90%;
border:solid 1px black;
padding: 5px;
background-color:white;
margin:-2.5% calc(100% - 97%);
}
.column {
width:30%;
float:left;
margin:0 1.6%;
}
.column img {
max-width:100%;
height:auto;
}
<div class="header">
</div>
<div class="inner_block">
<div class="column">
<img src="http://www.healthytravellovers.com/wp-content/uploads/2016/09/photo233227749810088605.jpg" />
</div>
<div class="column">
<img src="http://www.healthytravellovers.com/wp-content/uploads/2016/09/photo233227749810088607.jpg" />
</div>
<div class="column">
<img src="http://www.healthytravellovers.com/wp-content/uploads/2016/09/photo233227749810088606.jpg" />
</div>
</div>
<div class="footer">
test
</div>
is this what you were looking for ?
.header{
position:relative;
background-color:black;
width:100%;
height:50px;
}
.footer{
clear:both;
background-color:red;
width:100%;
height:50px;
}
.inner_block{
position: absolute;
width:100%;
border:solid 1px black;
padding: 5px;
margin-left: 2.5%;
margin-top:-2.5%;
background-color:white;
}
http://jsfiddle.net/8y4e8L08/
.header {
height: 200px;
width:800px;
background-color:#000;
margin:20px;
}
.header {
margin-bottom: -25px;
}
.inner_block {
width: 35%;
height: 150px;
margin: auto 200px;
background-color:#FFF;
border:1px solid #000;
margin-top: -45px;
}
.column{
max-width:20%;
float:left;
border: 2px soid #999;
margin:25px;
}
.column img{
max-width:100%;
height:auto;
}
.footer {
height: 100px;
margin-top: -25px;
margin:20px;
background-color:#F00;
width:800px;
}
.content {
position: relative;
z-index: 1;
}
<div class="header"></div>
<div class="inner_block">
<div class="column">
<img src="download.jpg"/>
</div>
<div class="column">
<img src="download.jpg"/>
</div>
<div class="column">
<img src="download.jpg"/>
</div>
</div>
<div class="footer">
</div>
Well just using the z-index won't always work. You also need to specify the 'position' property as well so as to define the z-index wrt some position of the frame.
Z-index is a property which defines the 'depth' or 'height' of an element. If your <header> has z-index of '100' and; <div> element defined inside the header, usually it would be shown above it but once you define the z-index:50; since 50<100, <div> element would be hidden behind it.
Example of z-index
1) http://www.w3schools.com/cssref/tryit.asp?filename=trycss_zindex
2) https://css-tricks.com/almanac/properties/z/z-index/
Hope it helps.
Probably a fairly basic solution to this, but I can't seem to figure it out... have set up a jsfiddle to demonstrate:
http://jsfiddle.net/AxKq8/1/
HTML
<div class="wrapper">
<div id="box-1" class="box">
</div>
<div id="box-2" class="box">
</div>
<div id="box-3" class="box">
</div>
</div>
CSS
.wrapper{
width: 100%;
}
.box {
width: 50%;
}
#box-1 {
height: 200px;
background-color: blue;
}
#box-2 {
height: 100px;
background-color: red;
}
#box-3 {
height: 300px;
float:right;
background-color: green;
position: relative;
top:0px;
right:0px;
}
I have 3 divs. What I'd like to do is have the top of the green div align with the top of the blue div.
As you can see I tried floating the first two divs left, and the third div right. That didn't work, so tried a relative positioning. Also tried using clear aswell, but it's eluding me!
Any suggestions on how to make this work?
Thanks!
Jon
Positioned the third div absolute with top:0
#box-3 {
height: 300px;
float:right;
background-color: green;
position: absolute;
top:0px;
right:0px;
}
Working CODE:JSFIDDLE
You can put the blue and red box in a container, and then a green box in another container. Float the two containers rather than the boxes.
http://jsfiddle.net/AxKq8/9/
HTML
<div class="wrapper">
<div class="container">
<div id="box-1" class="box">
</div>
<div id="box-2" class="box">
</div>
</div>
<div class="container">
<div id="box-3" class="box">
</div>
</div>
</div>
CSS
.wrapper{
width: 100%;
}
.container {
float: left;
width: 50%
}
#box-1 {
height: 200px;
background-color: blue;
}
#box-2 {
height: 100px;
background-color: red;
}
#box-3 {
height: 300px;
background-color: green;
}
Give this a try: JSFiddle
HTML:
<div class="wrapper">
<div class="box-group box">
<div id="box-1" class="box2"></div>
<div id="box-2" class="box2"></div>
</div>
<div class="box-group box">
<div id="box-3" class="box2"></div>
</div>
</div>
CSS:
.wrapper{ width: 100%; }
.box { width: 50%; }
.box2 { width: 100%; }
.box-group { float: left; }
#box-1 { height: 200px; background-color: blue; }
#box-2 { height: 100px; background-color: red; }
#box-3 { height: 300px; background-color: green; }
I created columns with the .box-group class, I grouped the first two items into the first column div so the stacking and floating will appear properly.
I have a div with a height en width of 33.33%. I want text in the middle of the div.
HTML
<div class="blogs" id="content">
<div id="blog1">tests</div>
<div id="blog2"></div>
<div id="blog3"></div>
</div>
CSS
#blog1 {
width: 33.33%;
padding-bottom: 33.33%;
background: red;
float: left;
}
How can i make this?
I suggest this:
html
<div class="blogs" id="content">
<div id="blog1">text in the middle
<span>blog 1</span>
</div>
<div id="blog2"><span>blog 2</span></div>
<div id="blog3"><span>blog 3</span></div>
</div>
css
#blog1{
width: 33.33%;
/*padding-bottom: 33.33%;*/
background: red;
text-align: center;
display:table-cell;
vertical-align:middle;
position: relative;
}
.blogs > div > span{
position: absolute;
bottom: 0px;
width: 100%;
left: 0px;
}
#blog2{
width: 33.33%;
padding-bottom: 33.33%;
background: green;
text-align: center;
display:table-cell;
position: relative;
}
#blog3{
width: 33.33%;
padding-bottom: 33.33%;
background: blue;
text-align: center;
display:table-cell;
position: relative;
}
#content{
display:table;
}
fiddle
And another example with static width e.g. 500px fiddle
Have a look at this fiddle.
Just set height and line-height equal and add vertical-align:middle;
Your code will look like this:
#blog1{
width: 33.33%;
height:300px;
background: red;
float: left;
text-align:center;
vertical-align:middle;
line-height:300px; /* has to bee the same value as the height of the div */
}
<div class="blogs" id="content">
<div id="blog1">tests</div>
<div id="blog2"></div>
<div id="blog3"></div>
<!-- You need to add this after the last <div> -->
<div style="clear:right;"></div>
</div>
#blog1, #blog2, #blog3 {
float:left;
padding: 3% 0;
background: red;
width: 100px;
height:100%;
text-align:center;
}
JS Fiddle
[SOLVED]
Here's the Fiddle
<div id="container">
<div class="content">
<div class="column">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</div>
<div class="column">
<div class="top">
TOP
</div>
<div class="bottom">
BOTTOM
</div>
</div>
<div class="column">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</div>
</div>
</div>
#container .content .column {
position: relative;
display:inline-block;
height: 100%;
width: 100px;
border: 1px solid red;
}
#container .content .top,
#container .content .bottom {
position: absolute;
background-color: #AAA;
}
#container .content .top {
top: 0;
}
#container .content .bottom {
bottom: 0;
}
#container {
min-height: 349px;
}
I have three inline columns, the left and right ones have the same dynamic height (they contain generated tables with a variable number of rows)
I want the middle column to have the same height as its neighbours and I want his TOP div to clamp to the top and BOTTOM div to clamp to the bottom.
I've read this thread but can't manage to make it work.
Any idea what I'm doing wrong ?
Thanks a lot !
EDIT
Using Sowmya's solution :
JS Fiddle
<div id="container">
<div style="position: relative;">
<div class="content">
<div class="column">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</div>
<div class="column">
<div class="top">
TOP
</div>
<div class="bottom">
BOTTOM
</div>
</div>
<div class="column">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
</div>
</div>
</div>
</div>
#container .content .column {
display:table-cell;
height: 100%;
width: 100px;
border: 1px solid red;
vertical-align: top;
}
#container .content .top,
#container .content .bottom {
position: absolute;
background-color: #AAA;
}
#container .content .top {
top: 0;
}
#container .content .bottom {
bottom: 0;
}
Use display:table-cell; to .column
#container .content .column {
position: relative;
display:table-cell;
height: 100%;
width: 100px;
border: 1px solid red;
}
DEMO