Containers and divs in CSS - css

Good day,
I'm not new to CSS or DIVs but have been out of touch for long enough. Trying to work out with Containers and nested DIVs but not getting much success in doing what I'm trying to do. Have already searched enough on SO and Goog but, hopefully you can help me.
Here's the representation of what I wish to achieve.
Screenshot of the layout
And here is what I have done so far ..
.dealsglobal {
width: 45%;
display: inline-block;
float: left;
margin-right:20px;
height: auto;
overflow: auto;
}
.dealsglobal h2 {
margin-left: 10px;
}
.dealsindia {
width: 45%;
height: auto;
overflow: auto;
}
.dealsindia h2 {
margin-left: 10px;
}
.dealsleft {
margin: 0px 25px 10px 0px;
padding: 5px;
border: 1px solid #ccc;
height: auto;
position: relative;
width: 40%;
float: left;
display: inline-block;
overflow: auto;
}
.dealsleft img {
border: 1px solid #ddd;
background: #fff;
border-radius: 4px;
margin-left: auto;
margin-right: auto;
width: 100px;
}
.dealsright {
margin-bottom: 10px;
padding: 5px;
border: 1px solid #ccc;
height: auto;
position: relative;
width: 40%;
display: inline-block;
overflow: auto;
}
<div class="dealsglobal">
<h2>Global Coupons</h2>
<div class="dealsleft">
<img src="thumb-heavengifts.jpg" alt="HeavenGifts.com Web Store" align="middle" />
</div>
<div class="dealsright">
Test
</div>
</div>
<div class="dealsindia">
<h2>Indian Coupons</h2>
<div class="dealsleft">
Test
</div>
<div class="dealsright">
Test
</div>
</div>
The image just wont center, no matter what I do. I believe, somewhere I have set the property to align left or something. Can anyone please point me to the correct direction? Thanks for your help!

I changed your code a little bit, but you'll get idea :
Here is html :
<div class="container">
<div class="left">
<h2 class="inner-text">title</h2>
<div class="image">
<img src="http://via.placeholder.com/350x150" />
</div>
<h5 class="inner-text">description</h5>
</div>
<div class="right">
<h2 class="inner-text">title</h2>
<div class="image">
<img src="http://via.placeholder.com/350x150" />
</div>
<h5 class="inner-text">description</h5>
</div>
<div style="clear: both" />
</div>
And here is the css:
.container{
width: 98%;
border: 2px solid #f00;
padding: 10px;
}
.left {
width: 47%;
float: left;
margin: 0 1% 0 1%;
border: 1px solid green;
}
.right {
width: 47%;
float: left;
margin: 0 1% 0 1%;
border: 1px solid green;
}
.inner-text{
text-align:center;
}
.image{
padding: 20px;
}
.image img{
max-width: 100%;
}
Check here jsfiddle.

You missed adding this css property:
.dealsleft {
text-align:center;
}

You can center elements inside a div by using text-align:center; for all the text elements like: h1, p, h2, a etc. To center an img or a div inside another div you can use margin: 0 auto; the auto is the important part for centering the left and right margins.
More info here
i've updated your code snippet.
.dealsglobal {
width: 45%;
display: inline-block;
float: left;
margin-right:20px;
height: auto;
overflow: auto;
}
.dealsglobal h2 {
margin-left: 10px;
}
.dealsindia {
width: 45%;
height: auto;
overflow: auto;
}
.dealsindia h2 {
margin-left: 10px;
}
.dealsleft {
margin: 0px 25px 10px 0px;
padding: 5px;
border: 1px solid #ccc;
height: auto;
position: relative;
width: 40%;
float: left;
display: inline-block;
overflow: auto;
text-align: center;
}
.dealsleft img {
border: 1px solid #ddd;
background: #fff;
border-radius: 4px;
margin: 5px auto;
width: 100px;
}
.dealsright {
margin-bottom: 10px;
padding: 5px;
border: 1px solid #ccc;
height: auto;
position: relative;
width: 40%;
display: inline-block;
overflow: auto;
text-align: center;
}
<div class="dealsglobal">
<h2>Global Coupons</h2>
<div class="dealsleft">
<img src="thumb-heavengifts.jpg" alt="HeavenGifts.com Web Store" align="middle" />
</div>
<div class="dealsright">
Test
</div>
</div>
<div class="dealsindia">
<h2>Indian Coupons</h2>
<div class="dealsleft">
Test
</div>
<div class="dealsright">
Test
</div>
</div>

I have added background colors for visualization purposes.
* {
box-sizing: border-box;
}
#container {
width: 100%;
padding: 10px;
background-color: red;
display: flex;
justify-content: space-between;
}
.subcontainer-outer {
width: 49%;
background-color: green;
}
.subcontainer {
width: 100%;
background-color: blue;
display: flex;
justify-content: space-between;
}
.content {
width: 45%;
text-align: center;
background-color: yellow;
}
<h3>Container</h3>
<div id="container">
<div class="subcontainer-outer">
<h4>Sub container 1</h4>
<div class="subcontainer">
<div class="content">
<img src="http://placehold.it/100" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div class="content">
<img src="http://placehold.it/100" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
<div class="subcontainer-outer">
<h4>Sub container 2</h4>
<div class="subcontainer">
<div class="content">
<img src="http://placehold.it/100" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div class="content">
<img src="http://placehold.it/100" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
</div>

You can get it by using flex below an example as your requirement.
.dealsglobal {
width: 48%;
margin-right: 10px;
height: auto;
float: left;
}
.flex {
display: flex;
justify-content: flex-start;
align-items: center;
flex-flow: row nowrap;
border: 1px solid red;
padding: 10px;
}
.dealsglobal h2 {
margin-left: 10px;
}
.dealsindia h2 {
margin-left: 10px;
}
.dealsleft {
margin: 0px 25px 10px 0px;
padding: 5px;
border: 1px solid #ccc;
flex: 1 0 0;
align-self: flex-start;
}
.dealsleft img {
border: 1px solid #ddd;
background: #fff;
border-radius: 4px;
margin-left: auto;
margin-right: auto;
width: 100%;
}
.dealsright {
margin-bottom: 10px;
padding: 5px;
border: 1px solid #ccc;
overflow: auto;
flex: 1 0 0;
align-self: flex-start;
}
<div class="dealsglobal">
<h2>Global Coupons</h2>
<div class="flex">
<div class="dealsleft">
<img src="http://lorempixel.com/400/200/sports/" alt="HeavenGifts.com Web Store" align="middle" />
</div>
<div class="dealsright">
Test
</div>
</div>
</div>
<div class="dealsglobal">
<h2>Global Coupons</h2>
<div class="flex">
<div class="dealsleft">
<img src="http://lorempixel.com/400/200/sports/" alt="HeavenGifts.com Web Store" align="middle" />
</div>
<div class="dealsright">
Test
</div>
</div>
</div>
Here is working fiddle
fiddle

You are probably looking for any of these 2:
parentSelector {
display: block; /* can also be an inline-block, with set width */
text-align: center;
}
childSelector {
width: 60%; /* generic. Change it */
display: block;
margin: 0 auto;
}
... or:
parentSelector {
display: flex;
flex-direction: column;
align-items: center;
}
childSelector {
max-width: 60%; /* optional. Change it.
* You don't need to set width here and,
* it's OK not to limit max-width, either
*/
}

Related

Image does not shrink in Chrome

I'm having trouble understanding why my images don't shrink when I shrink/resize my Chrome. Can someone explain and help me?
I have been trying for a while now but I can't seem to figure it out or find the answer elsewhere. The image shrinks in firefox running on my localhost, but not inside jsfiddle. Still not working in Chrome(57.0.2987.110).
<div class="page">
<div class="container">
<div class="title">
<H1>FLEXBOX PRACTICE</H1>
</div>
<div class="content">
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur.</p>
</div>
<div class="images">
<img src="http://www.placebacon.net/1280/720" alt="Bacn">
</div>
</div>
</div>
body {
margin: 0;
}
p {
margin: 0;
padding: 0;
}
h1 {
font-size: 72px;
margin: 20px 0;
}
.page {
width: 100vw;
height: 100vh;
background-color: pink;
}
.container {
margin: 0 auto;
width: 80vw;
display: flex;
flex-direction: column;
align-items: center;
}
.content {
display: flex;
justify-content: space-between;
height: 80vh;
width: 60vw;
align-items: center;
background-color: salmon;
}
.text {
flex-grow: 0;
padding: 10px 20px 10px 20px;
background-color: red;
color: white;
border-radius: 10px;
width: 340px;
font-size: 24px;
font-family: verdana;
}
.images {
display: flex;
align-items: center;
flex-grow: 1;
flex-shrink: 1;
max-width: 600px;
width: 600px;
background-color: yellow;
}
.images img {
display: flex;
flex-grow: 1;
flex-shrink: 1;
max-width: inherit;
width: inherit;
}
https://jsfiddle.net/xb4obfce/
You're telling the image to inherit the width of its parent, which is at 600px.
Changing the .images class to width: 100%; should make it responsive.

How to align a css triangle vertically to a responsive rectangle

i created a responsive rectangle and a responsive triangle with css only.
How can i align the triangle so it is always vertically centered on the right side of the box?
I´d like to do it just with css but if it is not possible i appreciate any hint for alternative options.
HTML:
<div class="container">
<div class="box green rightbox">
<div class="innerbox">Lorem ipsum....</div>
</div>
<div class="mother-triangle">
<div class="triangle-right green"></div>
</div>
</div>
CSS:
.container {
max-width: 1200px;
margin-right: auto;
margin-left: auto;
z-index: 1;
position: relative;
}
.box {
height: auto!important;
min-height: 300px;
}
.box.green {
background-color: rgba(51, 223, 9, 0.75)!important;
}
.innerbox {
padding: 12px;
}
.triangle-right {
width: 0;
height: 0;
padding-top: 10%;
padding-bottom: 10%;
padding-left: 10%;
overflow: hidden;
position: relative;
margin-top: auto;
margin-bottom: auto;
display: inline-block;
vertical-align: middle;
}
.triangle-right:after {
content: "";
display: block;
width: 0;
height: 0;
margin-top: -500px;
margin-left: -500px;
border-top: 500px solid transparent;
border-bottom: 500px solid transparent;
border-left: 500px solid rgba(51, 223, 9, 0.75);
}
.rightbox {
width: 90%;
float: left;
}
JSFiddel demo:
You can use absolute positioning to do that.
Just change position: relative to position: absolute in .triangle-right.
Add top: 50% to move the triangle to the vertical middle.
Updated fiddle
.container {
max-width: 1200px;
margin-right: auto;
margin-left: auto;
z-index: 1;
position: relative;
}
.box {
height: auto!important;
min-height: 300px;
}
.box.green {
background-color: rgba(51, 223, 9, 0.75)!important;
}
.innerbox {
padding: 12px;
}
.triangle-right {
width: 0;
height: 0;
padding-top: 10%;
padding-bottom: 10%;
padding-left: 10%;
overflow: hidden;
position: absolute;
margin-top: auto;
margin-bottom: auto;
display: inline-block;
vertical-align: middle;
top: 50%;
}
.triangle-right:after {
position: absolute;
content: "";
display: block;
width: 0;
height: 0;
margin-top: -500px;
margin-left: -500px;
border-top: 500px solid transparent;
border-bottom: 500px solid transparent;
border-left: 500px solid rgba(51, 223, 9, 0.75);
}
.rightbox {
width: 90%;
float: left;
}
<!-----container start---->
<div class="container">
<div class="box green rightbox">
<div class="innerbox">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
<div class="mother-triangle">
<div class="triangle-right green"></div>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
<!-----container end ---->

Top collapsible menu with media queries

Here is a top menu:
When browser width is < 1000px, I would like to :
Hide the 3 top-right <input> fields (I achieved it with display:none in the media query)
The "Post" button now becomes a button that opens a collapsible menu with the 3 input fields now displayed one after another in a new line, like this:
But I think this would require to completely change the DOM element order with CSS / media query. Is this possible / needed here?
How would you implement such top menu collapsible menu?
* { margin: 0; padding: 0; }
a { text-decoration: none; }
img { border: 0; }
body { overflow: hidden; height: 100%; font-family: arial; }
#header { border-bottom: 1px solid #dedede; height: 60px; margin: 0; display: -ms-flexbox; display: -webkit-flex; display: flex; }
#topleft { border-right: 1px solid #dedede; padding: 0px; float: left; -ms-flex: 0 0 155px; -webkit-flex: 0 0 155px; flex: 0 0 155px; height:100%; }
#topmid { border-right: 1px solid #dedede; float: left; -ms-flex: 0 0 40%; -webkit-flex: 0 0 40%; flex: 0 0 40%; height:100%; transition: all 0.3s ease-in-out; }
#topright { -ms-flex: 1; -webkit-flex: 1; flex: 1; position: relative; }
#logo { color: #ff0048; font-family: arial; font-size: 1.625em; font-weight: bold; padding-top: 14px; padding-left: 7px; }
#snif { margin-left: 0px; border: 0; margin-top: 22px; outline: 0px !important; width: calc(100% - 55px);}
#searchpng { background: #ffffff url("search.png") no-repeat left top; width: 40px; height: 30px; float:left; margin: 17 0 10 10px; }
.post { border: 1px solid #c4c4c4; padding: 5 2 5 10px; border-radius: 2px; }
#input1 { margin-left: 12px; width: calc(40% - 75px); position: relative; top:-7px; }
#input2 { margin-left: 0px; margin-top: 22px; width: calc(35% - 75px); position: relative; top:-7px; }
#input3 { width: calc(35% - 75px); position: relative; top:-7px; max-width: 230px;}
#deposer { background-color: #fb0149; color: white; padding: 6 10 5 10px; border-radius: 2px; position: relative; top:-7px; width: 65px; display: inline-block; text-align: center; margin-left: 5px; font-size: 0.875em; font-weight: bold; }
#spacer { max-width: 15px; width: calc(100% - 552px); display: inline-block; }
#media (max-width: 1000px) {
#topmid { -webkit-flex: 0 0 30%; -ms-flex: 0 0 30%; flex: 0 0 30%; }
body { overflow-y: scroll; }
}
<div id="header">
<div id="topleft" class="unselectable">
<div id="logo"><img src="logo.png" /></div>
</div>
<div id="topmid">
<div id="searchpng"></div>
<input type="text" placeholder="Lorem ipsum" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Lorem ipsum'" autocomplete="off" id="snif"></input>
</div>
<div id="topright" class="unselectable">
<input id="input1" class="post" type="textarea" placeholder="" autocomplete="off"/>
<input id="input2" class="post" type="textarea" placeholder="" autocomplete="off"/>
<input id="input3" class="post unselectable" placeholder="" value="" autocomplete="off"/>
Post
</div>
</div>
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
I would just change the position of the current menu on the media query for <1000px.
You could also create new html elements and set them to display:none until the media query is activated, and set them to display:block or whatever you wanted.
added html:
<div id="mobile-topright" class="unselectable">
<input id="input1" class="post" type="textarea" placeholder="" autocomplete="off"/></div>
<input id="input2" class="post" type="textarea" placeholder="" autocomplete="off"/>
<input id="input3" class="post unselectable" placeholder="" value="" autocomplete="off"/>
Post
</div>
added CSS:
#media (max-width: 1000px) {
#topmid { -webkit-flex: 0 0 30%; -ms-flex: 0 0 30%; flex: 0 0 30%; }
body { overflow-y: scroll; }
#topright {display:none;}
#mobile-topright {margin-top:5%;
}
#input1, #input2, #input3 {width:60%;
max-width:60%;
margin:0 auto;
padding:5px;}
}

Multiple z-index elements

I' am doing a project and I have a little issue with z-index property.
Here is my code:
(HTML)
<div class="outer_obw">
<div class="obw1">
<div class="box" id="blue_box">
<div id="inn_blue" class="inner_box"><p>Box1</p></div>
</div>
</div>
<div class="main_box_content">
<div class="back_box">
<div class="main_box">
<p id="texts">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
<div class="obw3">
<div class="box" id="green_box">
<div id="inn_green" class="inner_box"><p>Box2</p></div>
</div>
</div>
</div>
</div>
(CSS)
.outer_obw {
width: 78.5%;
margin: 0 auto;
}
.obw1 {
min-height: 80px;
}
.obw3 {
min-height: 80px;
margin-top: -40px;
}
.box {
width: 25.25%;
min-height: 80px;
cursor:pointer;
position: relative;
}
.inner_box {
height: 68px;
margin: -10.5px 6px;
text-align: center;
position: relative;
}
#inn_blue {
background-color: #fff;
z-index: 5;
}
#inn_green {
background-color: #fff;
z-index: 5;
}
#blue_box {
background-color: blue;
float: left;
z-index: 1;
}
#green_box {
background-color: green;
float: right;
}
.main_box_content {
display: table;
width: 78.5%;
position: absolute;
margin-top: -40px;
}
.back_box {
display: table;
background-color: blue;
width: 65%;
margin: 0 17%;
position: relative;
z-index: 3;
}
.main_box {
display: table;
background-color: #f1f1f1;
margin: 6px;
padding: 0.5% 3%;
position: relative;
z-index: 10;
}
Here is all code and visualization.
I intended to achieve such an effect:
All what I need to do is insert inn_blue and inn_green (white fields of box1 and box2) between main_box (gray field with a text) and back_box (red background of the main box.
I don't know what I'm doing wrong. Z-index of the main_box should be greater than z-index of inn_blue/inn_green and z-index of the inn_blue/inn_green should be greater then back_box.
And so it is in my code, but the effect is not what I expected...
So the question is what am I doing wrong?
There are so many layers of complexity in your example. Instead, let's use the natural layers to our advantage and position with absolute and minimal markup.
The basics
Start off with a wrapper to contain your three boxes:
<div class="wrapper">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
The wrapper will be position: relative and its three children will be positioned with position: absolute and top / right / bottom / left. In order to allow a flexible size that resizes in proportion, we can make use of the viewport width (vw) unit for both the width and the height. Each child div is given a percentage height.
.wrapper {
position: relative;
background: #EEE;
height: 60vw;
width: 80vw;
}
.wrapper div {
position: absolute;
height: 25%;
width: 20%;
}
.wrapper .one {
top: 16px;
left: 16px;
background: blue;
}
.wrapper .two {
top: 50%;
left: 50%;
margin: -23% 0 0 -31%;
height: 60%;
width: 62%;
background: red;
}
.wrapper .three {
bottom: 16px;
right: 16px;
background: green;
}
<div class="wrapper">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
That gives us this:
Layer the main box
Now we want the red square to overlap both the blue and green squares. All we have to do is move the red <div> below them in the markup. The last element in the markup will overlap the elements before it naturally.
<div class="wrapper">
<div class="one"></div>
<div class="three"></div>
<div class="two"></div><!-- move it one line down -->
</div>
.wrapper {
position: relative;
background: #EEE;
height: 60vw;
width: 80vw;
}
.wrapper div {
position: absolute;
height: 25%;
width: 20%;
}
.wrapper .one {
top: 16px;
left: 16px;
background: blue;
}
.wrapper .two {
top: 50%;
left: 50%;
margin: -23% 0 0 -31%;
height: 60%;
width: 62%;
background: red;
}
.wrapper .three {
bottom: 16px;
right: 16px;
background: green;
}
<div class="wrapper">
<div class="one"></div>
<div class="three"></div>
<div class="two"></div><!-- move it one line down -->
</div>
Now we have the correct layers:
Add the border layers
In order to reduce complexity, we can create the box borders with :before pseudo elements. These will create the extra elements we need to create the overlapping borders.
Give each child div a :before element and background color like below:
.wrapper div:before {
content: '';
position: absolute;
top: -6px;
right: -6px;
bottom: -6px;
left: -6px;
z-index: -1;
}
.one:before {
background: blue;
}
.two:before {
background: red;
}
.three:before {
background: green;
}
The -1 z-index will ensure that they are overlapped by the div backgrounds and the -6px position on all sides pulls them outside by 6px to give us a 6px border.
The final product
We add z-index: 1 to the wrapper, so that it wont overlap our border pseudo elements. box-sizing: border-box is used so that the padding is incorporated into the widths and heights.
Example 1
Limitation of this example: We cannot use overflow to hide excessive text on the main box, as it will cut off our border or cause a scroll bar to always be present..
.wrapper {
position: relative;
background: #EEE;
height: 60vw;
width: 80vw;
max-width: 772px;
max-height: 579px;
min-width: 390px;
min-height: 292px;
z-index: 1;
}
.wrapper div {
position: absolute;
box-sizing: border-box;
background: #FFF;
height: 25%;
width: 20%;
text-align: center;
padding: 10px;
}
.wrapper div:before {
content: '';
position: absolute;
top: -6px;
right: -6px;
bottom: -6px;
left: -6px;
z-index: -1;
}
.one:before {
background: blue;
}
.two:before {
background: red;
}
.three:before {
background: green;
}
.wrapper .one {
top: 16px;
left: 16px;
}
.wrapper .two {
top: 50%;
left: 50%;
margin: -23% 0 0 -31%;
height: 60%;
width: 62%;
background: #EEE;
text-align: left;
}
.wrapper .three {
bottom: 16px;
right: 16px;
}
<div class="wrapper">
<div class="one">Box1</div>
<div class="three">Box3</div>
<div class="two">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
</div>
Example 2
Slightly less elegant, the main box border is positioned relative to the wrapper itself, we can use overflow in this example to cut off or scroll excessive text.
.wrapper {
position: relative;
background: #EEE;
height: 60vw;
width: 80vw;
max-width: 772px;
max-height: 579px;
min-width: 390px;
min-height: 292px;
z-index: 1;
}
.wrapper div {
position: absolute;
box-sizing: border-box;
background: #FFF;
height: 25%;
width: 20%;
text-align: center;
padding: 10px;
}
.wrapper:after {
content: '';
position: absolute;
margin: -23% 0 0 -31%;
top: calc(50% - 6px);
left: calc(50% - 6px);
height: calc(60% + 12px);
width: calc(62% + 12px);
background: #F00;
z-index: -1;
}
.wrapper div:before {
content: '';
position: absolute;
top: -6px;
right: -6px;
bottom: -6px;
left: -6px;
z-index: -1;
}
.one:before {
background: blue;
}
.three:before {
background: green;
}
.wrapper .one {
top: 16px;
left: 16px;
}
.wrapper .two {
top: 50%;
left: 50%;
margin: -23% 0 0 -31%;
height: 60%;
width: 62%;
background: #EEE;
text-align: left;
}
.wrapper .three {
bottom: 16px;
right: 16px;
}
<div class="wrapper">
<div class="one">Box1</div>
<div class="three">Box3</div>
<div class="two">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
</div>
By streamlining the markup and css a bit and only z-indexing the necessaries (namely .top-box-border and .mid-box-inner) I believe I have what you're looking for:
[class*="border"] {
width: 100px;
height: 100px;
border: 10px solid green;
position: relative;
}
[class*="inner"] {
width: 100%;
height: 100%;
background-color: #999;
position: relative;
text-align: center;
box-sizing: border-box;
padding: 1ex 1em;
}
.mid-box-border {
width: 200px;
height: 200px;
border-color: blue;
margin-top: -40px;
margin-left: 75px;
}
.mid-box-inner {
background-color: #ccc;
text-align: left;
z-index: 20;
}
.bot-box-border {
margin-top: -40px;
margin-left: 255px;
}
.top-box-border {
z-index: 10;
}
<div class="top-box-border">
<div class="top-box-inner">Box 1</div>
</div>
<div class="mid-box-border">
<div class="mid-box-inner">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Hic accusantium dicta sint a cum eveniet, id! Corrupti sit reprehenderit ad veniam ratione mollitia molestiae, sapiente quasi id esse, incidunt eligendi.</div>
</div>
<div class="bot-box-border">
<div class="bot-box-inner">Box 2</div>
</div>
Set position: initial; for .back_box
Just make position relative for each box and position absolute for the background(border) and content holder to make them out of their workflow, then first element will take higher z-index and the elements in the back will take lower, look at this one https://jsfiddle.net/s3y94x1w/
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
.cont {
width: 100%;
}
.blue-box {
width: 20%;
height: 150px;
position: relative;
margin: 10px 0px 0px 8%;
cursor: pointer
}
.blue-box .background {
background-color: blue;
height: 100%;
width: 100%;
position: absolute;
}
.blue-box .content {
background-color: #fff;
position: absolute;
top: 10px;
left: 10px;
right: 10px;
bottom: 10px;
z-index: 2
}
.red-box {
width: 40%;
height: 150px;
position: relative;
margin-left: 19%;
margin-top: -70px;
}
.red-box .background {
background-color: red;
height: 100%;
width: 100%;
position: absolute;
}
.red-box .content {
background-color: #eee;
position: absolute;
top: 10px;
left: 10px;
right: 10px;
bottom: 10px;
z-index: 3;
overflow: hidden
}
.green-box {
width: 20%;
height: 150px;
position: relative;
margin-left: 50%;
margin-top: -70px;
cursor: pointer
}
.green-box .background {
background-color: green;
height: 100%;
width: 100%;
position: absolute;
z-index: -1
}
.green-box .content {
background-color: #fff;
position: absolute;
top: 10px;
left: 10px;
right: 10px;
bottom: 10px;
}
<div class="cont">
<div class="blue-box">
<div class="background"></div>
<div class="content">Box1</div>
</div>
<div class="red-box">
<div class="background"></div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
</div>
<div class="green-box">
<div class="background"></div>
<div class="content">Box2</div>
</div>
</div>

Chrome bugging height property again

Okay, so I've been practicing yesterday and after a few hours I checked this in Chrome (was working with firefox). How should i fix that?
I don't know where does it take the ridiculous height from.
Here's the preview i get (left is firefox, right is chrome)
Styling:
html, body {
margin: 0;
padding: 0;
}
body {
background-color: #f0ca4d;
display: flex;
justify-content: center;
font-family: "Roboto";
color: white;
}
.popup {
margin-top: 100px;
width: 400px;
/* height: 300px;*/
background-color: #fff;
-webkit-box-shadow: 0px 0px 10px 1px rgba(51,51,51,0.2);
-moz-box-shadow: 0px 0px 10px 1px rgba(51,51,51,0.2);
box-shadow: 0px 0px 10px 1px rgba(51,51,51,0.2);
position: relative;
}
.top {
width: 100%;
height: 70px;
background-color: #324d5c;
display: flex;
justify-content: flex-start;;
flex-direction: row;
}
.top span {
margin: 32px 16px 16px 16px;
font-size: 24px;
font-weight: 300;
}
.content {
color: rgba(0,0,0,0.5);
margin: 32px 32px 0px 32px;
line-height: 150%;
}
.fab {
width: 48px;
height: 48px;
background-color: #de5b49;
border-radius: 50%;
margin-left: auto;
margin-right: 16px;
position: absolute;
right: 0px;
top: 46px;
text-align: center;
}
.fab:hover span {
cursor: pointer;
}
.fab span {
font-size: 30px;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
font-weight: 300;
line-height: 48px;
display: inline-block;
}
.bot span {
text-transform: uppercase;
color: #324d5c;
font-weight: 500;
padding: 16px 32px 16px 32px;
transition: background-color 0.45s cubic-bezier(0,1,.83,.67) 0.08s;
background-color: white;
}
.bot span:hover {
background-color: #f8f8f8;
cursor: pointer;
}
.bot {
width: 100%;
display: flex;
justify-content: flex-end;
}
#disabled {
color: #d1d1d1;
margin-right: auto;
}
#disabled:hover {
background-color: white !important;
cursor: default;
-webkit-user-select: none; /* Chrome all / Safari all */
-moz-user-select: none; /* Firefox all */
-ms-user-select: none; /* IE 10+ */
user-select: none; /* Likely future */
}
Sctructure:
<div class="popup">
<div class="top">
<span>Warning box</span>
</div>
<div class="fab">
<span>+</span>
</div>
<div class="content">
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<!-- <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> -->
</div>
<div class="bot">
<span id="disabled">disabled</span>
<span>ENABLED</span>
</div>
</div>
Can't get this to work.
This is what I have in chrome..
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<title> Stack Overflow issues</title>
<style>
html,
body {
margin: 0;
padding: 0;
}
body {
background-color: #f0ca4d;
display: flex;
justify-content: center;
font-family: "Roboto";
color: white;
}
.popup {
margin-top: 100px;
width: 400px;
/* height: 300px;*/
background-color: #fff;
-webkit-box-shadow: 0px 0px 10px 1px rgba(51, 51, 51, 0.2);
-moz-box-shadow: 0px 0px 10px 1px rgba(51, 51, 51, 0.2);
box-shadow: 0px 0px 10px 1px rgba(51, 51, 51, 0.2);
position: relative;
}
.top {
width: 100%;
height: 70px;
background-color: #324d5c;
display: flex;
justify-content: flex-start;
;
flex-direction: row;
}
.top span {
margin: 32px 16px 16px 16px;
font-size: 24px;
font-weight: 300;
}
.content {
color: rgba(0, 0, 0, 0.5);
margin: 32px 32px 0px 32px;
line-height: 150%;
}
.fab {
width: 48px;
height: 48px;
background-color: #de5b49;
border-radius: 50%;
margin-left: auto;
margin-right: 16px;
position: absolute;
right: 0px;
top: 46px;
text-align: center;
}
.fab:hover span {
cursor: pointer;
}
.fab span {
font-size: 30px;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
font-weight: 300;
line-height: 48px;
display: inline-block;
}
.bot span {
text-transform: uppercase;
color: #324d5c;
font-weight: 500;
padding: 16px 32px 16px 32px;
transition: background-color 0.45s cubic-bezier(0, 1, .83, .67) 0.08s;
background-color: white;
}
.bot span:hover {
background-color: #f8f8f8;
cursor: pointer;
}
.bot {
width: 100%;
display: flex;
justify-content: flex-end;
}
#disabled {
color: #d1d1d1;
margin-right: auto;
}
#disabled:hover {
background-color: white !important;
cursor: default;
-webkit-user-select: none;
/* Chrome all / Safari all */
-moz-user-select: none;
/* Firefox all */
-ms-user-select: none;
/* IE 10+ */
user-select: none;
/* Likely future */
}
</style>
</head>
<body>
<div class="popup">
<div class="top">
<span>Warning box</span>
</div>
<div class="fab">
<span>+</span>
</div>
<div class="content">
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<!-- <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> -->
</div>
<div class="bot">
<span id="disabled">disabled</span>
<span>ENABLED</span>
</div>
</div>
</body>
</html>

Resources