Div with image obscured by next div down - css

I am creating a div that contains an image with text that overlays a large photo following these directions - How to position text over an image in css .
However, once I've done that the div below bleeds into this div with the image. What am I doing wrong.
HTML:
<div class="header-container">
<header class="wrapper clearfix">
<h1 class="title"><img src="img/ptmn_logo.gif" alt=""></h1>
<nav>
<ul>
<li>On Stage</li>
<li>Support</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>
</div>
<div class="main-container">
<div id="bg">
<img src="img/header.jpg" alt="">
<p>This is your theater.</p>
</div>
<div class="main wrapper clearfix">
And the CSS:
#bg {
position: relative;
top: -50%;
width: 200%;
height: 200%;
z-index: -1;
}
#bg img {
position: absolute;
display: block;
top: 0;
left: 0;
margin: auto;
min-width: 50%;
min-height: 50%;
z-index: 0;
}
#bg p {
position: absolute;
z-index: 100
}
.main {
position: relative;
}
I appreciate the help!

Looks like this is all you need. I'd get rid of all of those other styles, especially any margins. You can change the top and left properties of the p element to adjust its position over the header.jpg image.
img {
position: relative;
}
p {
position: absolute;
top: 0;
left: 0;
}
<header>
<img src="img/ptmn_logo.gif" alt="" />
<nav>
<ul>
<li>On Stage</li>
<li>Support</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>
<img src="img/header.jpg" alt="">
<p>This is your theater.</p>

Related

Top positioned horizontal scroll with css, scrollbar not visible with transform

I have an element on the page with horizontally scrolled content, scrollbar across the top.
This is working in FF/Chrome, and partially working in Safari.
The issue in Safari is the scroll bar is present & functional, but not visible. In the jsfiddle in Safari you can click and scroll across the top, even though no scrollbar shows.
jsfiddle
.testOne {
transform: rotateX(180deg);
overflow-x: scroll;
scrollbar-color: #ffde00 #f7f7f7;
}
.testOne::-webkit-scrollbar {
height: 20px;
}
.testOne::-webkit-scrollbar-thumb {
background-color: #ffde00;
}
.testTwo {
transform: rotateX(180deg);
width: 100%;
display: flex;
visibility: visible;
}
.item {
padding-right: 10px;
list-style: none;
}
<ul class="testContainer">
<span class="testOne">
<span class="testTwo">
<li class="item">
<img src='http://dummyimage.com/255x255/f0f0f0/000000' alt='' title=''/>
</li>
<li class="item">
<img src='http://dummyimage.com/255x255/f0f0f0/000000' alt='' title=''/>
</li>
<li class="item">
<img src='http://dummyimage.com/255x255/f0f0f0/000000' alt='' title=''/>
</li>
</span>
</span>
</ul>
Hoping someone has run into this and can advise a way to show the scrollbar.
When you have transforms on direct child elements it's having the issue. Try moving the transform up one level to the .testContainer element.
.testContainer {
width: 100%;
display: flex;
flex-direction: row;
margin: 0;
padding: 0;
position: relative;
overflow-x: hidden;
transform: rotateX(180deg);
}
.testOne {
overflow-x: scroll;
}
.testOne::-webkit-scrollbar {
height: 20px;
}
.testOne::-webkit-scrollbar-thumb {
background-color: #ffde00;
}
.testTwo {
transform: rotateX(180deg);
width: 100%;
display: flex;
visibility: visible;
}
.item {
padding-right: 10px;
list-style: none;
}
<ul class="testContainer">
<span class="testOne">
<span class="testTwo">
<li class="item">
<img src='http://dummyimage.com/255x255/f0f0f0/000000' alt='' title=''/>
</li>
<li class="item">
<img src='http://dummyimage.com/255x255/f0f0f0/000000' alt='' title=''/>
</li>
<li class="item">
<img src='http://dummyimage.com/255x255/f0f0f0/000000' alt='' title=''/>
</li>
</span>
</span>
</ul>

div not in correct order when use of other div with position absolute

I just wonder why the div with the CLASS = "optionsArea-1" is in the top, when I thought it should be below the div with the ID = "configContainer"? I know in part why and it's because of the position relative/absolute, but why does it act like that and why do I not get the common flow of divs?
Snippet:
#mainContainer {
margin: 0 auto;
width: 1000px;
height: auto;
}
#innerContainer {
width: 100%;
height: 100%;
}
#configContainer {
position: relative;
width: 100%;
height: auto;
}
.optionsArea-1 {
height: 100px;
}
.optionsArea-2 {
height: 100px;
}
.layer-1 {
z-index: 20;
position: absolute;
top: 0;
left: 0;
}
.layer-2 {
z-index: 10;
position: absolute;
top: 0;
left: 0;
}
<body>
<div id="mainContainer">
<div id="innerContainer">
<div id="configContainer">
<div class="layer-1">
<img src="http://via.placeholder.com/100x000" alt="">
</div>
<div class="layer-2">
<img src="http://via.placeholder.com/100x100" alt="">
</div>
</div>
<div class="optionsArea-1">
<div class="optionsMenu-1">
<ul>
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
</ul>
</div>
</div>
</div>
</div>
</body>
Absolute positioning completely breaks the flow of those elements from the DOM.
Using position:absolute while keeping it inside the document flow
When a parent element is left to determine its own height, it will ignore absolutely-positioned children. Your configContainer has two children, both absolutely-positioned, therefore its height is calculated as 0px.
absolute
The element is removed from the normal document flow, and no space is created for the element in the page layout.
position - CSS: Cascading Style Sheets | MDN
Solution 1: Set the height of the parent manually. The easiest, but probably the least extensible. The obvious caveat here is that if things move around, you could end up back in the same situation.
#mainContainer {
margin: 0 auto;
width: 1000px;
height: auto;
}
#innerContainer {
width: 100%;
height: 100%;
}
#configContainer {
position: relative;
width: 100%;
height: 100px;
}
.optionsArea-1 {
height: 100px;
}
.optionsArea-2 {
height: 100px;
}
.layer-1 {
z-index: 20;
position: absolute;
top: 0;
left: 0;
}
.layer-2 {
z-index: 10;
position: absolute;
top: 0;
left: 0;
}
<body>
<div id="mainContainer">
<div id="innerContainer">
<div id="configContainer">
<div class="layer-1">
<img src="http://via.placeholder.com/100x100" alt="">
</div>
<div class="layer-2">
<img src="http://via.placeholder.com/100x100" alt="">
</div>
</div>
<div class="optionsArea-1">
<div class="optionsMenu-1">
<ul>
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
</ul>
</div>
</div>
</div>
</div>
</body>
Solution 2: Combine the images in an image editor. If you're able to combine the images into one instead of layering them programatically, you could avoid position: absolute; altogether, and your parent would calculate the expected height.
#mainContainer {
margin: 0 auto;
width: 1000px;
height: auto;
}
#innerContainer {
width: 100%;
height: 100%;
}
#configContainer {
position: relative;
width: 100%;
}
.optionsArea-1 {
height: 100px;
}
.optionsArea-2 {
height: 100px;
}
.layer-1 {
z-index: 20;
position: absolute;
top: 0;
left: 0;
}
.layer-2 {
z-index: 10;
position: absolute;
top: 0;
left: 0;
}
<body>
<div id="mainContainer">
<div id="innerContainer">
<div id="configContainer">
<img src="http://via.placeholder.com/100x100" alt="">
</div>
<div class="optionsArea-1">
<div class="optionsMenu-1">
<ul>
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
</ul>
</div>
</div>
</div>
</div>
</body>

image with lower z-index goes on content

I'm trying to create a header hero but my problem is that my background image goes on all my contents. Actually it has lower z-index than content but I don't know why doesn't it go on background.
.header
{
width: 100vw;
background-color: blue;
position: relative;
}
.headerbakground
{
position: absolute;
width: 100%;
z-index: 1;
}
.header ul li img,.header ul li
{
width: 2vw;
float: right;
}
.header .container
{
z-index: 2;
}
<div class="header">
<!--background image-->
<img src="https://www.renonation.sg/wp-content/uploads/2015/01/title-header-hero-01.jpg" class="headerbakground">
<!--header top-->
<div class="container">
<ul>
<li><img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png" ></li>
<li><img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png" ></li>
<li><img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png" ></li>
<li><img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png" ></li>
<li><img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png" ></li>
</ul>
</div>
</div>
Only a positioned element can use z-index. According to MDN:
The z-index property specifies the z-order of a positioned (that is, one with any position other than static) element and
its descendants.
The .container doesn't have a position, so the z-index: 2 is ignored. Add position: relative to it:
.header .container {
position: relative;
z-index: 2;
}
.header {
width: 100vw;
background-color: blue;
position: relative;
}
.headerbakground {
position: absolute;
width: 100%;
z-index: 1;
}
.header ul li img,
.header ul li {
width: 10vw;
float: right;
}
.header .container {
position: relative;
z-index: 2;
}
<div class="header">
<!--background image-->
<img src="https://www.renonation.sg/wp-content/uploads/2015/01/title-header-hero-01.jpg" class="headerbakground">
<!--header top-->
<div class="container">
<ul>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
</ul>
</div>
</div>
You can also use a negative z-index: -1 on the element you want to push back:
.headerbakground {
position: absolute;
width: 100%;
z-index: -1;
}
.header {
position: relative;
width: 100vw;
background-color: blue;
}
.headerbakground {
position: absolute;
width: 100%;
z-index: -1;
}
.header ul li img,
.header ul li {
width: 10vw;
float: right;
}
<div class="header">
<!--background image-->
<img src="https://www.renonation.sg/wp-content/uploads/2015/01/title-header-hero-01.jpg" class="headerbakground">
<!--header top-->
<div class="container">
<ul>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
</ul>
</div>
</div>

Footer Overlaps Div before Dropping Below

I managed to make my footer to stick to the bottom of the window, then avoid my content div... but now, it's overlapping for about 15px before dropping below.
I want the footer to drop, but to never overlap the content. I think it may have something to do with my margins, but my tweaking has not yet solved this.
Any suggestions?
Adding margin-bottom:15px doesn't seem to help, because it's only shown once the footer overlaps enough to push the footer down. Then the margin is shown, but not before that small amount of overlap.
The #push div is supposed to make this all possible, from what I understood on Twitter's bootstrap example.
CSS:
* {
margin: 0;
padding: 0;
}
html {
height: 100%;
}
body {
margin: 0;
height: 100%;
}
#wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -50px;
min-width: 900px;
}
.main_nav {
list-style-type: none;
margin: 0;
width: 160px;
float: left;
padding-left: 40px;
overflow: hidden;
}
#bio_content {
width: 700px;
min-height: 445px;
margin-bottom: 15px;
float: left;
}
#bio_text {
padding: 10px;
}
#push {
height: 50px;
}
#footer {
height: 50px;
width: 100%;
float: left;
}
HTML:
<body>
<div id="wrapper">
<div id="header">
<h1></h1>
</div>
<ul class="main_nav">
<li>Home</li>
<li>About</li>
<li>Music</li>
<li>Services</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
<div id="bio_content">
<div id="bio_text"></div>
</div>
<div id="push"></div>
</div>
<div id="footer">
<div id="footer_content"></div>
</div>
</body>
</html>
I thin it's a float issue. A fiddle would help diagnose this better. I would suggest doing this
<body>
<div id="wrapper">
<div id="header">
<h1></h1>
</div>
<ul class="main_nav">
<li>Home</li>
<li>About</li>
<li>Music</li>
<li>Services</li>
<li>Gallery</li>
<li>Contact</li>
</ul>
<div id="bio_content">
<div id="bio_text"></div>
</div>
<div style="clear:both"></div> //add this to clear the bio_content div
<div id="push"></div>
</div>
<div id="footer">
<div id="footer_content"></div>
</div>
</body>
</html>
You need to clear the styles in your footer. Add a clear:both to your footer css.
#footer {
clear: both;
height: 50px;
width: 100%;
}

Using 960.gs and sticky footer content div background does not stretch to the bottom of the page

I'm using the 960.gs frameowrk and http://www.cssstickyfooter.com and want to have a separate back ground colour for the main content div. This div won't stretch the background to the bottom of the page.
HTML:
<div id="wrapper">
<div id="content" class="container_12">
<div class="grid_12" id="header"><img src=logo.png" alt="" width="145" height="160" border="0" /></div><!--header-->
<div class="clear"></div>
<div class="grid_12" id="navbar">
<ul>
<li>Home</li>
<li>menu 1</li>
<li>menu 2</li>
<li>menu 3</li>
<li>menu 4</li>
<li>menu 5</li>
</ul>
</div><!--navbar-->
<div class="clear"></div>
<div class="grid_12" id="content_body">
<div class="grid_4" id="sidebar">
sidebar left
</div> <!--sidebar-->
<div class="grid_7" id="body_right">
body right
</div> <!--body_right-->
</div> <!--content_body-->
<div class="clear"></div>
</div><!--content-->
</div> <!--wrapper-->
<div id="footer"> footer </div> <!--footer-->
CSS:
html, body, #wrapper {height: 100%;}
body > #wrapper { height: auto; min-height: 100%; }
/* must be same height as the footer */
#content { overflow: auto;
padding-bottom: -1.5em;
}
#footer {
position: relative;
margin-top: -1.5em; /* negative value of footer height */
height: 1.5em;
clear: both;
}
/*Opera Fix*/
body:before { /* thanks to Maleika (Kohoutec)*/
content: "";
height:100%;
float: left;
width: 0;
margin-top: -32767px; /* thank you Erik J */
}
body {
min-width: 960px;
background: #E9F2F9;
}
div#header{
background-color: #3399cc;
}
div#navbar {
background-color: #FF9900;
}
div#navbar LI{
margin: 0 auto;
display: inline;
padding-right: 5px;
}
div#content_body{
background: #9CC4E4;
}
You have a div class="clear" but clear isn't defined in your CSS - you need to specify "clear:both" in a .clear CSS class.

Resources