Z-index doesn't working with pseudo - css

I'd like to put the arrow of the box (:after) above the image, but z-index doesn't work.
I have this code in html
<div class="example clearfix">
<div class="element item-large">
<div class="item-text">
<span>march 15, 2015</span>
<h2>Chapter One</h2>
<p>Lorem ipsum dolor sit amet, <br /> consectetur adipisicing elit. Qui, aspernatur!</p>
</div>
<div class="item-image">
<img src="assets/images/box-1.jpg">
</div>
</div>
<div class="element item">
<img src="assets/images/box-2.jpg">
</div>
</div> <!-- end example -->
And this in CSS
.example{
width: 100%;
position: relative;
height: auto;
}
.example img{
width: 100%;
display: block;
max-width: 100%;
height: 100%;
max-width: 100%;
}
.example .item-large{
width: 70%;
height: 300px;
float: left;
position: relative;
}
.example .item{
width: 30%;
height: 300px;
float: left;
position: relative;
}
.example .item-image{
width: 30%;
height: 300px;
float: left;
overflow: hidden;
z-index: 10;
}
.example .item-large .item-text{
padding: 50px;
width: 70%;
height: 300px;
float: left;
overflow: hidden;
z-index: 10;
background-color: #fff;
position: relative;
}
.example .item-large .item-image-large{
width: 100%;
height: 300px;
float: left;
overflow: hidden;
z-index: 10;
}
.item-text{
position: relative;
}
.item-text:after{
content: " ";
position: absolute;
right: -15px;
top: 15px;
border-top: 15px solid transparent;
border-right: none;
border-left: 15px solid black;
border-bottom: 15px solid transparent;
z-index: 10;
}
Can anyone tell me why z-index in not working in my case??? thanks in advance.
https://jsfiddle.net/sgmq70L4/embedded/result/

Related

How to extend the pseudo element placed absolutely until the page content gets the best?

I wrote such a code. I write this code so that .vertical_catch p: after is from the position where the element is absolutely placed to the bottom where the page content exists
body {
margin: 0;
}
.hero {
height: 100vh;
position: relative;
margin: 0 auto;
overflow: hidden;
background: #000;
}
.vertical_catch {
position: absolute;
top: 58%;
left: 4%;
height: 100%;
}
.vertical_catch p {
font-size: 1.8vw;
color: #ffffff;
writing-mode: vertical-rl;
height: 100%;
}
.vertical_catch p:after {
z-index: 50;
margin: 1em 0;
content: "";
position: absolute;
left: 50%;
height: 100%; /* I want to get 100% height of page content */
display: inline-block;
width: 1.7px;
transform: translateX(-50%);
background-color: #fff;
}
.box {
width: 100%;
}
.minibox {
height: 100vh;
padding: 150px;
background-color: #333;
}
h1 {
margin: 40px 0px;
color: #fff;
text-align: center;
}
.content {
margin: 0 auto;
width: 50%;
color: #fff;
overflow-wrap: break-word;
}
<body>
<div class="hero"></div>
<div class="vertical_catch">
<p>TEXTTEXTTEXTTEXT</p>
</div>
<div class="box">
<section class="minibox">
<h1>heading1</h1>
<section class="content">
<p>texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
</p>
</section>
</section>
</div>
<div class="box">
<section class="minibox">
<h1>heading2</h1>
<section class="content">
<p>texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
</p>
</section>
</section>
</div>
</body>
However, height: 100% only worked up to 100vh, and could not extend the border to the bottom of the content.
According to the developer tool verification,in html and body, the height includes all page content, but the element of absolute arrangement could not obtain the height. height: 100% only worked up to 100vh.
How can I extend the border?
You are setting 100% height for ::after element; it will take up the full height of the p, its main element. Consider editing as below:
body {
margin: 0;
height: auto;
position: relative;
}
.hero {
height: 100vh;
position: relative;
margin: 0 auto;
overflow: hidden;
background: #000;
}
.vertical_catch {
position: absolute;
top: 10%;
left: 4%;
height: 90%;
}
.vertical_catch p {
font-size: 1.8vw;
color: #ffffff;
writing-mode: vertical-rl;
height: 100%;
}
.vertical_catch p:after {
z-index: 50;
margin: 1em 0;
content: "";
position: absolute;
left: 50%;
height: 80%;
display: inline-block;
width: 1.7px;
transform: translateX(-50%);
background-color: #fff;
}
.box {
width: 100%;
}
.minibox {
height: 100vh;
box-sizing: border-box;
padding: 150px;
background-color: #333;
}
h1 {
margin: 40px 0px;
color: #fff;
text-align: center;
}
.content {
margin: 0 auto;
width: 50%;
color: #fff;
overflow-wrap: break-word;
}
<body>
<div class="hero"></div>
<div class="vertical_catch">
<p>TEXTTEXTTEXTTEXT</p>
</div>
<div class="box">
<section class="minibox">
<h1>heading1</h1>
<section class="content">
<p>texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
</p>
</section>
</section>
</div>
<div class="box">
<section class="minibox">
<h1>heading2</h1>
<section class="content">
<p>texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
</p>
</section>
</section>
</div>
</body>
body {
margin: 0;
height: auto;
position: relative;
}
.hero {
height: 100vh;
position: relative;
margin: 0 auto;
overflow: hidden;
background: #000;
}
.vertical_catch {
position: absolute;
top: 10%;
left: 4%;
height: 90%;
}
.vertical_catch p {
font-size: 1.8vw;
color: #ffffff;
writing-mode: vertical-rl;
height: 100%;
}
.vertical_catch p:after {
z-index: 50;
margin: 1em 0;
content: "";
position: absolute;
left: 50%;
height: calc(100% - 388px);
display: inline-block;
width: 1.7px;
transform: translateX(-50%);
background-color: #fff;
}
.box {
width: 100%;
}
.minibox {
height: 100vh;
box-sizing: border-box;
padding: 150px;
background-color: #333;
}
h1 {
margin: 40px 0px;
color: #fff;
text-align: center;
}
.content {
margin: 0 auto;
width: 50%;
color: #fff;
overflow-wrap: break-word;
}
<body>
<div class="hero"></div>
<div class="vertical_catch">
<p>TEXTTEXTTEXTTEXT</p>
</div>
<div class="box">
<section class="minibox">
<h1>heading1</h1>
<section class="content">
<p>texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
</p>
</section>
</section>
</div>
<div class="box">
<section class="minibox">
<h1>heading2</h1>
<section class="content">
<p>texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
</p>
</section>
</section>
</div>
</body>

why text appearing at the bottom of div?

I have placed several paragraphs into div element but text are appearing at the bottom of block. What might be the problem? As well would be great if you can suggest how to make the blocks more responsive.
HTML:
<div class="container">
<div class="content">
<div class="inner">
<h1><span>What</span> Clients Says</h1>
<div class="main-block">
<div class="testimonial-block-1">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTLdI6QE_lvzsCy_6VTsikYLz0iPFnWSv2vbGVzbwgQA8OlEbpH" alt="">
<p>- Staciya Trollio</p>
<p>Customer</p>
<p>Lorem Ipsum is simply dummy text of the printing
and industry. Lorem Ipsum has been the industry.</p>
</div>
<div class="testimonial-block-2">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTLdI6QE_lvzsCy_6VTsikYLz0iPFnWSv2vbGVzbwgQA8OlEbpH">
<p>- David Soul</p>
<p>Customer</p>
<p>Lorem Ipsum is simply dummy text of the printing
and industry. Lorem Ipsum has been the industry.</p>
</div>
</div>
</div>
</div>
</div>
CSS:
* {
padding: 0;
margin: 0;
box-sizing:border-box;
}
html, body {
height: 100%;
}
.container {
height: 100%;
background: url(bg.jpg);
min-width: 100%;
background-size: 100%;
font-family: sans-serif;
}
.content {
position:absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(16,21,26,.9);
width: 100%;
}
.inner {
position: absolute;
left: 50%;
top: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.inner h1 {
color: #3170a8;
text-align: center;
}
.inner h1 span {
color: #ee8129;
}
.main-block {
margin-top: 50px;
}
.testimonial-block-1 {
float: left;
max-width: 364px;
background-color: #fff;
min-height: 100px;
margin-right: 45px;
position:relative;
z-index:100;
}
.testimonial-block-1::after,
.testimonial-block-2::after {
position: absolute;
top: 25%;
left: -20px;
content: '';
width: 0;
height: 0;
border-right: solid 20px rgb(255,255,255);
border-bottom: solid 20px transparent;
border-top: solid 20px transparent;
z-index:2;
}
.testimonial-block-1 img {
position:relative;
right:150px;
}
.testimonial-block-2 img,
.testimonial-block-1 img{
position:relative;
right:150px;
max-width: 107px;
height: 106px;
}
.testimonial-block-2 {
float: right;
max-width: 364px;
background-color: #fff;
min-height: 100px;
position:relative;
left:160px;
z-index:100;
}
.testimonial-block-1 p:nth-child(3),
.testimonial-block-2 p:nth-child(3) {
border-bottom:1px dashed #222;
}
Jsfiddle
Use this for the images, otherwise (if you use position: relative , regardless of the settings) the space they usually occupy will remain reserved for them (i.e. empty) in the container:
position:absolute;
left: -150px;
and create a margin-bottom below the testemonial-blocks:
* {
padding: 0;
margin: 0;
box-sizing:border-box;
}
html, body {
height: 100%;
}
.container {
height: 100%;
background: url(bg.jpg);
min-width: 100%;
background-size: 100%;
font-family: sans-serif;
}
.content {
position:absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(16,21,26,.9);
width: 100%;
}
.inner {
position: absolute;
left: 50%;
top: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.inner h1 {
color: #3170a8;
text-align: center;
}
.inner h1 span {
color: #ee8129;
}
.main-block {
margin-top: 50px;
}
.testimonial-block-1 {
float: left;
max-width: 364px;
background-color: #fff;
min-height: 100px;
margin-right: 45px;
position:relative;
z-index:100;
}
.testimonial-block-1,
.testimonial-block-2 {
margin-bottom: 30px;
}
.testimonial-block-1::after,
.testimonial-block-2::after {
position: absolute;
top: 25%;
left: -20px;
content: '';
width: 0;
height: 0;
border-right: solid 20px rgb(255,255,255);
border-bottom: solid 20px transparent;
border-top: solid 20px transparent;
z-index:2;
}
.testimonial-block-2 img,
.testimonial-block-1 img{
position:absolute;
left: -150px;
max-width: 107px;
height: 106px;
}
.testimonial-block-2 {
float: right;
max-width: 364px;
background-color: #fff;
min-height: 100px;
position:relative;
left:160px;
z-index:100;
}
.testimonial-block-1 p:nth-child(3),
.testimonial-block-2 p:nth-child(3) {
border-bottom:1px dashed #222;
}
<div class="container">
<div class="content">
<div class="inner">
<h1><span>What</span> Clients Says</h1>
<div class="main-block">
<div class="testimonial-block-1">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTLdI6QE_lvzsCy_6VTsikYLz0iPFnWSv2vbGVzbwgQA8OlEbpH" alt="">
<p>- Staciya Trollio</p>
<p>Customer</p>
<p>Lorem Ipsum is simply dummy text of the printing
and industry. Lorem Ipsum has been the industry.</p>
</div>
<div class="testimonial-block-2">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTLdI6QE_lvzsCy_6VTsikYLz0iPFnWSv2vbGVzbwgQA8OlEbpH">
<p>- David Soul</p>
<p>Customer</p>
<p>Lorem Ipsum is simply dummy text of the printing
and industry. Lorem Ipsum has been the industry.</p>
</div>
</div>
</div>
</div>
</div>
Try this:
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
html,
body {
height: 100%;
}
.container {
height: 100%;
background: url(bg.jpg);
min-width: 100%;
background-size: 100%;
font-family: sans-serif;
}
.content {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(16, 21, 26, .9);
width: 100%;
}
.inner {
position: absolute;
left: 50%;
top: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.inner h1 {
color: #3170a8;
text-align: center;
}
.inner h1 span {
color: #ee8129;
}
.main-block {
margin-top: 50px;
}
.testimonial-block-1 {
float: left;
max-width: 364px;
background-color: #fff;
min-height: 100px;
margin-right: 45px;
position: relative;
z-index: 100;
}
.testimonial-block-1::after,
.testimonial-block-2::after {
position: absolute;
top: 25%;
left: -20px;
content: '';
width: 0;
height: 0;
border-right: solid 20px rgb(255, 255, 255);
border-bottom: solid 20px transparent;
border-top: solid 20px transparent;
z-index: 2;
}
.testimonial-block-1 img {
position: relative;
right: 150px;
}
.testimonial-block-2 img,
.testimonial-block-1 img {
position: absolute;
left: -150px;
max-width: 107px;
height: 106px;
}
.testimonial-block-2 {
float: right;
max-width: 364px;
background-color: #fff;
min-height: 100px;
position: relative;
left: 160px;
z-index: 100;
}
.testimonial-block-1 p:nth-child(3),
.testimonial-block-2 p:nth-child(3) {
border-bottom: 1px dashed #222;
}
<div class="container">
<div class="content">
<div class="inner">
<h1><span>What</span> Clients Says</h1>
<div class="main-block">
<div class="testimonial-block-1">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTLdI6QE_lvzsCy_6VTsikYLz0iPFnWSv2vbGVzbwgQA8OlEbpH" alt="">
<p>- Staciya Trollio</p>
<p>Customer</p>
<p>Lorem Ipsum is simply dummy text of the printing and industry. Lorem Ipsum has been the industry.</p>
</div>
<div class="testimonial-block-2">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTLdI6QE_lvzsCy_6VTsikYLz0iPFnWSv2vbGVzbwgQA8OlEbpH">
<p>- David Soul</p>
<p>Customer</p>
<p>Lorem Ipsum is simply dummy text of the printing and industry. Lorem Ipsum has been the industry.</p>
</div>
</div>
</div>
</div>
</div>
I've changed the position: relative to position: absolute and added a negative left: -150px and removed the right: 150px.
i think this will do the trick, i used display:flex to set everything in the right place i also removed a few of the position:absolute. i believe this will save you a lot of unnecessary code and positioning and will make your code much cleaner.
https://jsfiddle.net/Lsjo988z/3/
html:
<div class="container">
<div class="content">
<div class="inner">
<h1><span>What</span> Clients Says</h1>
<div class="main-block">
<div class="chat-container align-start" >
<div class="row">
<div>
<img class="img" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTLdI6QE_lvzsCy_6VTsikYLz0iPFnWSv2vbGVzbwgQA8OlEbpH" alt="">
</div>
<div class="testimonial-block">
<p>- Staciya Trollio</p>
<p>Customer</p>
<p>Lorem Ipsum is simply dummy text of the printing
and industry. Lorem Ipsum has been the industry.</p>
</div>
</div>
</div>
<div class="chat-container align-center" >
<div class="row">
<div>
<img class="img" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTLdI6QE_lvzsCy_6VTsikYLz0iPFnWSv2vbGVzbwgQA8OlEbpH">
</div>
<div class="testimonial-block">
<p>- David Soul</p>
<p>Customer</p>
<p>Lorem Ipsum is simply dummy text of the printing
and industry. Lorem Ipsum has been the industry.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
css:
* {
padding: 0;
margin: 0;
box-sizing:border-box;
}
html, body {
height: 100%;
}
.container {
height: 100%;
background: url(bg.jpg);
min-width: 100%;
background-size: 100%;
font-family: sans-serif;
}
.content {
width: 100%;
height: 100%;
background-color: rgba(16,21,26,.9);
}
.inner {
width: 100%;
}
.inner h1 {
color: #3170a8;
text-align: center;
}
.inner h1 span {
color: #ee8129;
}
.main-block {
margin-top: 50px;
}
.chat-container{
display:flex;
flex-wrap:wrap
}
.row{
display:flex;
-webkit-box-orient: horizontal;
-webkit-flex-direction: row;
flex-direction: row;
}
.align-start{
justify-content: flex-start;
}
.align-center{
justify-content: center;
}
.img{
max-width: 107px;
height: 106px;
}
.testimonial-block {
width:290px;
margin-left:43px;
//float: left;
max-width: 364px;
background-color: #fff;
min-height: 100px;
//margin-right: 45px;
position:relative;
z-index:100;
}
.testimonial-block::after {
position: absolute;
top: 25%;
left: -20px;
content: '';
width: 0;
height: 0;
border-right: solid 20px rgb(255,255,255);
border-bottom: solid 20px transparent;
border-top: solid 20px transparent;
z-index:2;
}
.testimonial-block-1 img {
position:relative;
right:150px;
}
.testimonial-block p:nth-child(3) {
border-bottom:1px dashed #222;
}
for more information about display flex abilities you can read this really good explanation https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Dropdown ignore parent overflow

I have a modal where I have dropdowns in the element.
The problem is since I have an overflow set, the dropdown, although it appears, does not appear on top of the modal. I understand since it's because I set an overflow:auto on the parent.
Is there any way via CSS that I can ignore the parent and show the dropdown above the "modal"?
You'll see in the example, the content in the red line is visible if you scroll. Which is the expected behaviour based on my code at the moment. What is the adjustment I will need to make to show that dropdown above the modal?
Tried fixing with z-index and I read somewhere on SO to set the grandparent to position relative.
Prefer a CSS only solution.
Thanks!
.w-100 {
width: 100%;
height: 100%;
}
.h-100 {
width: 100%;
height: 100%:
}
.modal-overlay {
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
display: block;
z-index: 65;
padding-top: 100px;
overflow: auto;
background-color: rgba(0,0,0,.6);
}
.modal-small {
max-width: 600px;
width: 40%;
margin: 0 auto;
float: none;
display: block;
position: relative;
background-color: #fff;
padding: 0;
}
.container {
min-height: 120px;
max-height: 400px;
overflow: auto;
padding: 15px;
}
.element-container {
height: 100px;
width: 100%;
display: inline-block;
padding: 10px;
margin-bottom: 10px;
position: relative;
}
.element-flex-container {
display: flex;
align-items: center;
height: 100%;
padding: 5px 15px;
border-radius: 2px;
border-bottom: 3px solid rgba(0,0,0,.1);
border-left: 1px solid rgba(0,0,0,.1);
border-right: 1px solid rgba(0,0,0,.1);
border-top: 1px solid rgba(0,0,0,.1);
}
.avatar {
height: 32px;
width: 32px;
border-radius: 100%;
margin-right: 10px;
}
.flex-1 {
flex: 1;
}
.dropdown-width {
text-align: right;
width: 100px;
}
.dropdown-container {
display: inline;
position: relative;
}
.toggle-dropdown {
color: #4caf50
}
.dropdown {
position: absolute;
border: 1px solid red;
left: auto;
right: 0;
width: 120px;
display: block;
background-color: #fff;
z-index: 10;
margin-bottom: 20px;
padding: 0;
}
<div class="modal-overlay">
<div class="modal-small">
<div class="w-100 h-100"> <!-- this is since I inject an ui-view -->
<div class="w-100 h-100"> <!-- this is since I inject an ui-view -->
<div class="container">
<!-- Repeat of elements -->
<div class="element-container">
<div class="element-flex-container">
<img src="http://images.freeimages.com/images/previews/7ab/chrysanthemum-3-1621562.jpg" class="avatar" />
<div class="flex-1">
Something here
</div>
<div class="dropdown-width">
<div class="dropdown-container">
<div class="toggle-dropdown">
Toggle
</div>
<div class="dropdown">
Something here
<br />
Something else
<br />
Something else
<br />
Something else
<br />
Something else
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
You need to make the dropdown element position: fixed, the dropdown container positon: absolute and the parent position:relativefor this to work. You can adjust the positining of the container element using top, right, left, bottom but you'll need to use negative margins on the fixed element.
.w-100 {
width: 100%;
height: 100%;
}
.h-100 {
width: 100%;
height: 100%:
}
.modal-overlay {
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
display: block;
z-index: 65;
padding-top: 100px;
overflow: auto;
background-color: rgba(0,0,0,.6);
}
.modal-small {
max-width: 600px;
width: 40%;
margin: 0 auto;
float: none;
display: block;
position: relative;
background-color: #fff;
padding: 0;
}
.container {
min-height: 120px;
max-height: 400px;
overflow: auto;
padding: 15px;
}
.element-container {
height: 100px;
width: 100%;
display: inline-block;
padding: 10px;
margin-bottom: 10px;
position: relative;
}
.element-flex-container {
display: flex;
align-items: center;
height: 100%;
padding: 5px 15px;
border-radius: 2px;
border-bottom: 3px solid rgba(0,0,0,.1);
border-left: 1px solid rgba(0,0,0,.1);
border-right: 1px solid rgba(0,0,0,.1);
border-top: 1px solid rgba(0,0,0,.1);
}
.avatar {
height: 32px;
width: 32px;
border-radius: 100%;
margin-right: 10px;
}
.flex-1 {
flex: 1;
}
.dropdown-width {
text-align: right;
width: 100px;
}
.dropdown-container {
display: inline;
position: absolute;
top: 0;
right:0;
}
.toggle-dropdown {
color: #4caf50
}
.dropdown {
position: fixed;
border: 1px solid red;
width: 120px;
display: block;
background-color: #fff;
z-index: 10;
margin-bottom: 20px;
padding: 0;
}
<div class="modal-overlay">
<div class="modal-small">
<div class="w-100 h-100"> <!-- this is since I inject an ui-view -->
<div class="w-100 h-100"> <!-- this is since I inject an ui-view -->
<div class="container">
<!-- Repeat of elements -->
<div class="element-container">
<div class="element-flex-container">
<img src="http://images.freeimages.com/images/previews/7ab/chrysanthemum-3-1621562.jpg" class="avatar" />
<div class="flex-1">
Something here
</div>
<div class="dropdown-width">
<div class="dropdown-container">
<div class="toggle-dropdown">
Toggle
</div>
<div class="dropdown">
Something here
<br />
Something else
<br />
Something else
<br />
Something else
<br />
Something else
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
you need used z-index 999, and position relative in dropdown css.
Example:
.w-100 {
width: 100%;
height: 100%;
}
.h-100 {
width: 100%;
height: 100%:
}
.modal-overlay {
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
display: block;
z-index: 65;
padding-top: 100px;
overflow: auto;
background-color: rgba(0,0,0,.6);
}
.modal-small {
max-width: 600px;
width: 40%;
margin: 0 auto;
float: none;
display: block;
position: relative;
background-color: #fff;
padding: 0;
}
.container {
min-height: 120px;
max-height: 400px;
overflow: auto;
padding: 15px;
}
.element-container {
height: 100px;
width: 100%;
display: inline-block;
padding: 10px;
margin-bottom: 10px;
position: relative;
}
.element-flex-container {
display: flex;
align-items: center;
height: 100%;
padding: 5px 15px;
border-radius: 2px;
border-bottom: 3px solid rgba(0,0,0,.1);
border-left: 1px solid rgba(0,0,0,.1);
border-right: 1px solid rgba(0,0,0,.1);
border-top: 1px solid rgba(0,0,0,.1);
}
.avatar {
height: 32px;
width: 32px;
border-radius: 100%;
margin-right: 10px;
}
.flex-1 {
flex: 1;
}
.dropdown-width {
text-align: right;
width: 100px;
}
.dropdown-container {
display: inline;
position: relative;
}
.toggle-dropdown {
color: #4caf50
}
.dropdown {
position: relative;
z-index: 9999;
border: 1px solid red;
left: auto;
right: 0;
width: 120px;
display: block;
background-color: #fff;
z-index: 10;
margin-bottom: 20px;
padding: 0;
}
<div class="modal-overlay">
<div class="modal-small">
<div class="w-100 h-100"> <!-- this is since I inject an ui-view -->
<div class="w-100 h-100"> <!-- this is since I inject an ui-view -->
<div class="container">
<!-- Repeat of elements -->
<div class="element-container">
<div class="element-flex-container">
<img src="http://images.freeimages.com/images/previews/7ab/chrysanthemum-3-1621562.jpg" class="avatar" />
<div class="flex-1">
Something here
</div>
<div class="dropdown-width">
<div class="dropdown-container">
<div class="toggle-dropdown">
Toggle
</div>
<div class="dropdown">
Something here
<br />
Something else
<br />
Something else
<br />
Something else
<br />
Something else
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

three divs in header, one left, one dynamic, one right

I have a problem concerning three divs in the header of my website: http://www.pianoson.nl.
What I want:
The middlemenu needs to fill up the space between the left and the right menu. When you make the browser smaller, only the middle-menu should get smaller too.
The middle menu needs to have a minimum width, so the text in it does not get messed up.
At the moment the rightmenu drops down below the leftmenu at some point, but the three menu's should always stay together in the top.
I hope this is possible with css/html.
Thanks in advance!
The html-page:
<body>
<div id="menu">
<div id="leftmenu">
<a href="http://www.pianoson.nl">
<div class="key white"ID="home">
<img src="http://www.pianoson.nl/images/home_32.png"></img>
</div></a>
<div class="key black"ID="Csharp"></div>
<a href="http://www.pianoson.nl/genres.htm">
<div class="key white"ID="repertoire">
<img src="http://www.pianoson.nl/images/music2_32.png"></img>
</div></a>
<div class="key black"ID="Dsharp"></div>
<a href="http://www.pianoson.nl/samples.htm">
<div class="key white "ID="samples">
<img src="http://www.pianoson.nl/images/music_32.png"></img>
</div></a></div>
<div ID="middlemenu"></div>
<div id="rightmenu">
<a href="https://www.linkedin.com/e/fpf/184174635">
<div class="key white "ID="linkedin">
<img src="http://www.pianoson.nl/images/linkedin_32.png"></img>
</div></a>
<div class="key black"ID="Csharp"></div>
<a href="https://www.facebook.comthijs.waleson">
<div class="key white"ID="facebook">
<img src="http://www.pianoson.nl/images/facebook_32.png"></img>
</div></a>
<div class="key black"ID="Dsharp"></div>
<a href="https://plus.google.com/u/0/112443072032497378793/">
<div class="key white "ID="googleplus">
<img src="http://www.pianoson.nl/images/google_32.png"></img>
</div></a></div>
</div>
And the css page:
body {
background-color: #F2F2F2;
width: auto;
overflow: hidden;}
div {
display: inline-block;}
#middlemenu {
height: 230px;
float: none;
width: 100%;
border: 1px solid #000000;
position: relative;
border-radius: 5px;
z-index: 1;}
.key {
float: left;
border-radius: 5px;
border: 1px solid #000000;
position: relative;
text-align:center;}
.white {
background-color: #FFFFFF;
height: 230px;
width: 40px;
z-index: 2;}
.black {
background-color: #000000;
height:150px;
width: 24px;
z-index: 3;
margin-left:-15px;
margin-right: -15px;}
.white:hover {
background-color: #FFFFFF;
height: 345px;
width: 60px;
z-index: 1;}
.key:hover img {
position: static;
vertical-align: -335px;
bottom: 5px;
padding: 14px;}
#menu{
width: 100%;
display: inline;
position: relative;}
#leftmenu{
float: left;}
#rightmenu{
float: right;}
div a div img{
vertical-align: -210px;
position: static;
bottom:5px;
color: #000000;}
Is this you are looking for..
modify the css to this
body {
background-color: #F2F2F2;
width: auto;
overflow: hidden;
}
div {
}
#middlemenu {
height: 230px;
margin-left: 130px;
margin-right: 130px;
min-width:300px;
border: 1px solid #000000;
position: relative;
border-radius: 5px;
z-index: 1;
}
#menu {
width: 100%;
position: relative;
}
#leftmenu {
float: left;
}
#rightmenu {
float: right;
position:absolute;
top:0;
right:0;
}
div a div img {
vertical-align: -210px;
position: static;
bottom:5px;
color: #000000;
}
.key {
float: left;
border-radius: 5px;
border: 1px solid #000000;
position: relative;
text-align:center;
}
.white {
background-color: #FFFFFF;
height: 230px;
width: 40px;
z-index: 2;
}
.black {
background-color: #000000;
height:150px;
width: 24px;
z-index: 3;
margin-left:-15px;
margin-right: -15px;
}
.white:hover {
background-color: #FFFFFF;
height: 345px;
width: 60px;
z-index: 1;
}
.key:hover img {
position: static;
vertical-align: -335px;
bottom: 5px;
padding: 14px;
}

Header and Footer DIVs overlapping with middle contents

To make the issue easier to analyze I have created this jsFiddle:
Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
body {margin:0; }
#mainContainer { position: absolute; right: 4%; left: 4%; height: 100%; }
#headerContainer { width: 100%; z-index: 10; position: absolute; background: #323232; color: white; height: 30px; }
#middleContainer { height: 100%; }
#leftSection { position: absolute; float: left; width: 175px; background: #71ABD1; height: 100%; overflow: auto; color: black; padding-top: 30px; }
#middleSection { position: absolute; height: 100%; background-color: yellow; left: 175px; right: 175px; color: black; padding-top: 30px; }
#rightSection { float: right; height: 100%; width: 175px; border-left: 1px dotted black; background: red; color: black; padding-top: 30px; }
#footerContainer { position: absolute; bottom: 0; width: 100%; height: 30px; background: #323232; color: white; }
</style>
</head>
<body>
<div id="mainContainer">
<div id="headerContainer">
headerContainer
</div>
<div id="middleContainer">
<div id="leftSection">
leftSection
</div>
<div id="middleSection">
middleSection
</div>
<div id="rightSection">
rightSection
</div>
</div>
<div id="footerContainer">
footerContainer
</div>
</div>
</body>
</html>
With the markup of top, middle, and bottom sections, problem is:
1- As you can see the footer colored in black is not really on the bottom of the page despite having position:absolute and bottom:0px on the footer div
2- More importantly, leftSection, middleSection and rightSection DIVs overlap with the header and footer DIVs, in fact, in this fiddle the only way to see the text displayed of the 3 middle sections is to have padding placed to avoid having it displayed underneath the header DIV.
I have tried placing top and bottom values of 30px on middleContainer to fix the overlap issue but this does not solve the problem, all I want is to keep headerContainer on top and footerContainer on the bottom while all the 3 middle sections adjust to 100% height. leftSection and rightSection have fixed width, but middleSection has flexible width and height.
http://jsfiddle.net/grc4/XTQuT/2/ does what I wanted exactly without specifying solid height values.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
body {
margin: 0;
height:100%;
}
#mainContainer {
position: absolute;
right: 4%;
left: 4%;
height: 100%;
}
#headerContainer {
width: 100%;
position: relative;
background: #323232;
color: white;
height: 30px;
}
#middleContainer {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: 30px 0;
}
#leftSection {
float: left;
width: 175px;
background: #71ABD1;
height: 100%;
overflow: auto;
color: black;
}
#middleSection {
position: absolute;
background-color: yellow;
left: 175px;
right: 175px;
top: 0;
bottom: 0;
color: black;
}
#rightSection {
float: right;
height: 100%;
width: 175px;
border-left: 1px dotted black;
background: red;
color: black;
}
#footerContainer {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
background: #323232;
color: white;
}​
</style>
</head>
<body>
<div id="mainContainer">
<div id="headerContainer">
headerContainer
</div>
<div id="middleContainer">
<div id="leftSection">
<div style="margin-top: 30px;">leftSection</div>
</div>
<div id="middleSection">
<div style="margin-top: 30px;">middleSection</div>
</div>
<div id="rightSection">
<div style="margin-top: 30px;">rightSection</div>
</div>
</div>
<div id="footerContainer">
footerContainer
</div>
</div>
</body>
</html>
The "padding-top: 30px;" on your 3 inner elements is making them 30px taller than the height of the actual body, creating your problem.
Remove the top padding from those 3 elements, then make your header and footer relatively positioned, rather than absolute, and you should be set.
Like this: http://jsfiddle.net/BPJxD/28/
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
body {margin:0; }
#mainContainer { position: absolute; right: 4%; left: 4%; height: 100%; }
#headerContainer { width: 100%; z-index: 10; position: relative; background: #323232; color: white; height: 30px; }
#middleContainer { height: 100%; }
#leftSection { position: absolute; float: left; width: 175px; background: #71ABD1; height: 100%; overflow: auto; color: black; }
#middleSection { position: absolute; height: 100%; background-color: yellow; left: 175px; right: 175px; color: black; }
#rightSection { float: right; height: 100%; width: 175px; border-left: 1px dotted black; background: red; color: black; }
#footerContainer { position: relative; width: 100%; height: 30px; background: #323232; color: white; }
</style>
</head>
<body>
<div id="mainContainer">
<div id="headerContainer">
headerContainer
</div>
<div id="middleContainer">
<div id="leftSection">
leftSection
</div>
<div id="middleSection">
middleSection
</div>
<div id="rightSection">
rightSection
</div>
</div>
<div id="footerContainer">
footerContainer
</div>
</div>
</body>
</html>
Your problem was that you were using needless absolute positioning in headercontainer and footercontainer, solution
HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div id="mainContainer">
<div id="headerContainer">
headerContainer
</div>
<div id="middleContainer">
<div id="leftSection">
leftSection
</div>
<div id="middleSection">
middleSection
</div>
<div id="rightSection">
rightSection
</div>
</div>
<div id="footerContainer">
footerContainer
</div>
</div>
</body>
</html>
CSS:
body { margin:0; }
#mainContainer
{
position: absolute;
right: 4%; left: 4%;
height: 100%;
}
#headerContainer
{
width: 100%;
z-index: 10;
position: relative;
background: #323232;
color: white;
height: 30px;
}
#middleContainer { height: 100%; }
#leftSection
{
position: absolute;
float: left;
width: 175px;
background: #71ABD1;
height: 100%;
overflow: auto;
color: black;
padding-top: 30px;
}
#middleSection
{
position: absolute;
height: 100%;
background-color: yellow;
left: 175px;
right: 175px;
color: black;
padding-top: 30px;
}
#rightSection
{
float: right;
height: 100%;
width: 175px;
border-left: 1px dotted black;
background: red;
color: black;
padding-top: 30px;
}
#footerContainer
{
position: relative;
bottom: 0; width: 100%;
height: 30px;
background: #323232;
color: white;
}
Reviewing your whole Fiddle I noticed that you are using absolute positioning on every div. This is plane wrong.
You should only absolute positioning when:
You need a container that is free of the document's usual formatting. Such as a popup or a floating box.
You need to use a div inside a parent div with fixed positioning, but this will only work if parent positioning is set to relative.
You can remove all 3 of
padding-top: 30px;
like
#leftSection { position: absolute; float: left; width: 175px; background: #71ABD1; height: 100%; overflow: auto; color: black; }
#middleSection { position: absolute; height: 100%; background-color: yellow; left: 175px; right: 175px; color: black; }
#rightSection { float: right; height: 100%; width: 175px; border-left: 1px dotted black; background: red; color: black; }
and change your html like this
<div id="mainContainer">
<div id="headerContainer">
headerContainer
</div>
<div id="middleContainer">
<div id="leftSection">
<div style="margin-top:30px;">leftSection</div>
</div>
<div id="middleSection">
<div style="margin-top:30px;">middleSection</div>
</div>
<div id="rightSection">
<div style="margin-top:30px;">rightSection</div>
</div>
</div>
<div id="footerContainer">
footerContainer
</div>
</div>
I hope this can be helpful.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
body {margin:0; }
#mainContainer { position: relative; right: 4%; left: 4%; height: 100%; width:1000px; }
#headerContainer { width: 1000px; z-index: 10; position: absolute; background: #323232; color: white; height: 30px; }
#middleContainer { height: 100%; width:1000px; position:relative; display: table-cell;}
#leftSection { float: left; width:25%; background: #71ABD1; overflow: auto; color: black; padding-top: 30px; height: 100%;}
#middleSection { float: left; height:100%; width:50%; background-color: yellow; color: black; padding-top: 30px; }
#rightSection { float:left; height:100%; width: 25%; background: red; color: black; padding-top: 30px; }
#footerContainer { bottom: 0; width:1000px; height: 30px; background: #323232; color: white; float:left;}
</style>
</head>
<body>
<div id="mainContainer">
<div id="headerContainer"> headerContainer </div>
<div id="middleContainer" >
<div id="leftSection"> leftSection </div>
<div id="middleSection"> middleSection </div>
<div id="rightSection"> rightSection
rightSection rightSection rightSection rightSection rightSection rightSection rightSection </div>
</div>
<div id="footerContainer" > footerContainer </div>
</div>
</body>
</html>

Resources