Div with background-image overlayed by another div with background-image - html

I am trying to place 2 div elements containing background-image on the top of each other using the z-index property, but I'm struggling to make this work.
Ideally, I would like the div banner-image element to sort of slide underneath the div banner-image-overlay element as the screen is going smaller.
Here is my fiddle
HTML:
<div id="banner-container">
<div class="banner-image-overlay"></div>
<div class="banner-image"></div>
<div class="banner-text">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
</p>
<p>
Lorem ipsum dolor sit amet
</p>
<button class="banner-button" onclick="location.href='http://www.example.com'">
Button
</button>
</div>
</div>
CSS:
#banner-container {
width: 100%;
position:relative;
}
.banner-image {
height: 375px;
background-image: url('http://via.placeholder.com/502x375');
background-repeat: no-repeat;
background-position: left top;
}
.banner-image-overlay {
height: 375px;
background-image: url('http://via.placeholder.com/399x375');
background-repeat: no-repeat;
background-position: right top;
z-index: 99;
}
.banner-text {
max-width: 240px;
font-family: 'Helvetica Neue Light', arial;
color: #fff;
font-size: 1.6em;
float: right;
position: absolute;
right: 35px;
top: 15px;
z-index: 199;
}
.banner-button {
max-width: 240px;
font-size: 0.9em;
background-color: #fff;
border: none;
border-radius: 4px;
font-family: 'Helvetica Neue Light', arial;
color: #000;
text-decoration: none;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
margin: 4px 2px;
cursor: pointer;
}
I just can't figure out how to position them on the top of each other.
I've already had this working with the regular img tag and then using the position: absolute property, but this doesn't seem to work with the background-image: url
Any ideas?

You need to have position: absolute for z-index work.
I have a better solution by using flex box:
.banner{position:relative; display:flex;width:375px;height:500px; background:left top url(https://picsum.photos/300/300) no-repeat}
.banner-bg{flex:1 1;background:right top url(https://picsum.photos/200/280) no-repeat}
.banner-title{font-size:30px}
<div class="banner">
<div class="banner-bg">
<div style="position:absolute;width:150px;right:10px;top:100px">
<div class="banner-title">HERE IS LONG TEXT...</div>
<button>GET IN TOUCH</button>
</div>
</div>
</div>
As you see right background is placed above left background.

div elements by default are positioned relatively which means they will be next to each other. z-index will not change their positioning. If you want to stack them you'll have to change their positions. Positioning one of them absolutely with left and top set to 0 will stack them.
add position:absolute to .banner-image-overlay.

Related

Info box inside overflow:hidden container should be visible outside

I have a div table which has a lot of content inside, because of that I added overflow:hidden so the table is scrollable.
Inside I have an info link which on hover displays some additionally information.
The problem is, the info box on the first row of the table is most likely outside of the table and this piece gets cut off.
How to make this hidden piece infobox outside of the table visible, without removing overflow:hidden or using JS?
.outertable{
display:block;
overflow-x:auto !important;
}
.info:hover:after{
background: rgba(75,75,75, 0.85);
bottom: 32px;
color: #fff;
content: attr(data-tooltip);
left: -100px;
position: absolute;
z-index: 999;
width: 200px;
}
Here is some small example on jsfiddle:
https://jsfiddle.net/0tcbadk8/10/
.outertable {
box-shadow: 3px 3px 7px -3px rgba(0, 0, 0, 0.30);
display: block;
overflow-x: auto !important;
}
div.table {
display: table;
width: 100%;
background-color: rgba(0, 0, 0, 0.3);
border-radius: 10px;
}
div.tr {
display: table-row;
}
div.maintr {
display: table-row;
}
.maintr .td {
padding: 15px 5px;
}
div.td {
display: table-cell;
padding: 10px 5px;
text-align: center;
vertical-align: middle;
}
.info {
display: inline;
position: relative;
}
.info:hover:after {
background: #333;
background: rgba(75, 75, 75, 0.85);
border-radius: 5px;
bottom: 32px;
color: #fff;
content: attr(data-tooltip);
left: -100px;
padding: 15px 25px;
position: absolute;
z-index: 999;
width: 200px;
}
.info:hover:before {
border: solid;
border-color: #4b4b4b transparent;
border-width: 12px 12px 0 12px;
bottom: 20px;
content: "";
left: 0%;
position: absolute;
z-index: 99;
}
<br/><br/><br/><br/><br/><br/>
<div class="outertable">
<div class="table offerstyle">
<div class="tr">
<div class="td fixinfonooverflow"></div>
<div class="td"></div>
<div class="td"></div>
<div class="td"></div>
<div class="td"></div>
</div>
<div class="tr">
<div class="td"><img class="" data-original="images/logo/3.png" title="" alt="" src="images/logo/3.png" style=""></div>
<div class="td">BLABLABLA</div>
<div class="td">
<div class="nonewline more_info" title="4.8 von 5 Sternen und 5 Bewertungen"><i class="fa fa-star ratingtwo" aria-hidden="true"></i><i class="fa fa-star ratingtwo" aria-hidden="true"></i><i class="fa fa-star ratingtwo" aria-hidden="true"></i><i class="fa fa-star ratingtwo" aria-hidden="true"></i><i class="fa fa-star-half-o ratingtwo"
aria-hidden="true"></i></div>
</div>
<div class="td">
<a class="info" data-tooltip="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque a est ut justo interdum efficitur at id tortor. Cras lacinia, sapien sit amet suscipit sodales, mi velit bibendum risus, at dictum ligula mauris vel dui."><i class="fa fa-info-circle" aria-hidden="true"></i> info</a>
</div>
<div class="td">TEST<br>TEST2<br>TEST3<br></div>
</div>
<div class="tr">
<div class="td fixinfonooverflow"></div>
<div class="td"></div>
<div class="td"></div>
<div class="td"></div>
</div>
</div>
</div>
I see 3 options:
1) If you know the contents of the info box and the content is fixed size you could increase the spacing of the table to accommodate the size of the info box to stay "inside".
2) Quick solution: Instead of position: absolute you could use position: fixed on the info box, this works if it fits your needs (won't scroll with the content, it will stay fixed).
.info:hover:after{
background: #333;
background: rgba(75,75,75, 0.85);
border-radius: 5px;
color: #fff;
content: attr(data-tooltip);
left: 400px;
top: 0;
padding: 15px 25px;
position: fixed;
z-index: 999;
width: 200px;
}
.info:hover:before{
border: solid;
border-color: #4b4b4b transparent;
border-width: 12px 12px 0 12px;
content: "";
left: 420px;
top: 173px;
position: fixed;
z-index: 99;
}
Updated jsfiddle: https://jsfiddle.net/0tcbadk8/27/
3) Create the info box dynamically using jQuery / Javascript and position it depending on the position of the trigger element and checking if it overflows outside of boundaries of the table and reposition it. In the same time it could be place outside of overflow:hidden container in markup.
Demo :
https://jsfiddle.net/0tcbadk8/56/
Explanation:
You need to remove position: relative from parent in order to make it pop out of overflow: hidden
But now we cannot use top,right,bottom or left because that won't be relative to parent but will be relative to body
So in order to position them with translate and margin only
I will also require the width of owner of pseudo elements
So added JS which adds a --width css variable
Using some basic logic and maths, added the translateX and translateY to the pseudo elements
PS:
Here's a css only solution http://jsfiddle.net/keygcptw/1/ But the only problem is tooltip is positioned on extreme right instead of center

Center button horizontally with CSS

I am learning HTML and CSS and I am having difficulty centering a button within a <div>. Here is the code I currently have:
.box-information {
border: 2px solid #000000;
margin: 0 auto 15px auto;
padding: 0 10px 60px 10px;
width: 80%;
background-color: #ffffff;
position: relative;
}
.button-blue:link,
.button-blue:visited {
width: 7em;
display: block;
padding: 10px 15px;
background-color: rgba(66, 85, 123, 1);
font-size: 1.0em;
text-indent: 0;
text-align: center;
color: #ffffff;
position: absolute;
bottom: 10px;
left: auto;
}
<div class="box-information your-business">
<p class="title-information">
Your Business
</p>
<p class="text-information">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<a class="button-blue learn-more" href="#">Learn More</a>
</div>
I am able to offset the button from the bottom, and I can offset the button horizontally if I use anything but AUTO.
Please help me understand what I am doing wrong.
To center a block element in it's parent, all you need to do is add:
margin-left:auto;
margin-right:auto;
to the button's CSS properties.
(You will need to remove the position: absolute and the absolute positioning properties first.)
Take a look at this codepen: https://codepen.io/anon/pen/qXYEpd
Update
.box-information {
border: 2px solid #000000;
margin: 0 auto 15px auto;
padding: 0 10px 60px 10px;
width: 80%;
background-color: #ffffff;
position: relative;
}
.button-blue:link,
.button-blue:visited {
width: 7em;
display: block;
padding: 10px 15px;
background-color: rgba(66, 85, 123, 1);
font-size: 1.0em;
text-indent: 0;
text-align: center;
color: #ffffff;
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
}
<div class="box-information your-business">
<p class="title-information">
Your Business
</p>
<p class="text-information">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<a class="button-blue learn-more" href="#">Learn More</a>
</div>
Set margin-left:50%;. This set my button to the middle of its parent control.

How can I align these elements side by side?

I'm having difficulties in aligning these elements side by side, anyway this—
—is how it looks so far, but I want it look like this:
.reviewprofile {
background-color: transparent;
border: none;
margin-top: 5em;
}
.reviewentry {
display: inline-block;
font-family: 'Abhaya Libre', Times, Serif;
font-size: 0.8em;
font-weight: 400;
color: #5e5e5e;
text-align: left;
padding-left: 3.5em;
margin: 0;
}
.commbutton button {
float: left;
}
.starsrev {
padding-left: 2.8em;
}
<div class="commsec">
<div class="commbutton">
<button class="reviewprofile"><img src="img/reviewprofile.png"> </button>
</div>
<div class="commentry">
<p class="reviewentry">Cras ultricies dolor ac justo scelerisque, sit amet imperdiet<br> purus placerat.</p>
<img class="starsrev" src="img/stars.png" alt="stars" />
</div>
</div>
flex on the parent will create this layout with your existing markup. Here's a visual guide for help with syntax/options https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.reviewprofile {
background-color: transparent;
border: none;
}
.reviewentry {
font-family: 'Abhaya Libre', Times, Serif;
font-size: 0.8em;
font-weight: 400;
color: #5e5e5e;
text-align: left;
margin: 0;
}
.commsec {
display: flex;
align-items: center; /* this will affect vertical alignment */
}
<div class="commsec">
<div class="commbutton">
<button class="reviewprofile"><img src="http://cdn.quilt.janrain.com/2.1.2/profile_default.png"> </button>
</div>
<div class="commentry">
<p class="reviewentry">Cras ultricies dolor ac justo scelerisque, sit amet imperdiet<br> purus placerat.</p>
<img style="max-width: 100px" class="starsrev" src="http://www.moviesmacktalk.com/news/wp-content/uploads/2013/11/2.5-Stars.jpg" alt="stars" />
</div>
</div>
you can try floating them. thats what i usually do.
.commbutton{
float:left;
}
.commentry{
float:left;
}
Apply float:left to the div which you want to show on the left and apply float: right for the one to be shown on the right. That's the starting point. Based on results you may have to change them to be inline too.
Please add under CSS & check
img {
float: left;
}
I didn't run the code.

CSS Floats: clear on parent does not expand it to contain floated children

In this fiddle , the parent <p> tag contains an <img> tag which is floated left float: left however the parent <p> tag does not expand to fully encompass the floated img element although I have clear:both set on parent <p> tag.
I know that adding an extra div with clear:both before closing </p> or overflow:auto on <p> will do the job but I am at wits end as to why clear:both set on <p> tag does not work as I expect.
Can anybody explain this behavior?
.thumbnail-desc h2 {
display: inline-block;
background: blue;
color: #fff;
padding: 5px 7px;
margin-bottom: 0;
}
.thumbnail-desc img {
float: left;
width: 200px;
max-height: 200px;
margin-left: initial;
margin-right: 10px;
margin-bottom: 10px;
border: 1px solid #ddd;
overflow: hidden;
}
.thumbnail-desc p {
background-color: #fff;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.01);
padding: 15px;
font-size: 18px;
clear: both;
margin-bottom: 20px;
margin-top: 0;
}
<div class="thumbnail-desc">
<h2>Some title</h2>
<p>
<img src="http://i.huffpost.com/gen/1632280/images/n-VISION-200x150.jpg" alt="Our Vision">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi nihil dignissimos. Some crazy text.Some crazy text</p>
</div>
It seems you may misunderstand how clear works.
Setting clear:both on the <p> tag is telling the p to clear anything that comes before it - not the child items within it.
You can add overflow: hidden; for <p>. Here is example: https://jsfiddle.net/hnL0gLy2/
Instead of covering the image with a p tag, use a class and a div.
Fiddle.
HTML:
<div class="thumbnail-desc">
<h2>Some title</h2>
<div class="outer">
<img src="http://i.huffpost.com/gen/1632280/images/n-VISION-200x150.jpg" alt="Our Vision">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi nihil dignissimos. Some crazy text.Some crazy text
</div>
</div>
CSS:
.thumbnail-desc h2 { display: inline-block;
background: blue;
color: #fff;
padding: 5px 7px;
margin-bottom: 0; }
.thumbnail-desc img {
float: left;
width: 200px;
max-height: 200px;
margin-left: initial;
margin-right: 10px;
margin-bottom: 10px;
border: 1px solid #ddd;
overflow: hidden; }
.thumbnail-desc .outer {
background-color: #fff;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.01);
padding: 15px;
font-size: 18px;
height:150px;
}
Why your code does not work as you thought?
Because the p tag is for the text. It's height is as much as the text inside the div. For more height, you need to switch to a div or span.
You need to set your .thumbnail-desc p to the display of inline-block.

Overlapping elements in a responsive site design

I have to code something like this in html/css (I'm also using the Skeleton framework):
design preview
I tried lots of ways to make the background and the image overlap and used absolute positioning for the image. Not sure if it's the best option, especially since when I change the width of the browser the design starts to fall apart, and I want it to be responsive.
Is there a better way to implement this? If not, how do I make the image vertically centered with regard to the gray background. Thank you!
Here are the html/css files + skeleton and the image (for testing purposes): Dropbox folder
And here's the pure code. HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<div class="news twelve columns">
<div class="imgcont seven columns">
<img src="newsimg.jpg">
</div>
<div class="newsimage ten columns">
<div class="newstext six columns">
<div class="row">
<h2>Latest News</h2>
<h3>New video coming out soon!</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="row">
<div class="more">MORE</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
And CSS:
.news{
margin-top: 3.125em;
}
.newsimage{
position: relative;
float: right;
background-color: #594f4e;
height: 100%;
}
.imgcont{
position: absolute;
top: 6em;
left: 0;
z-index: 200;
}
.newstext{
float:right;
}
.newstext h2{
display: inline-block;
font-size: 2.6em;
text-transform: uppercase;
float: right;
padding: 0.5em 0.75em 0 0;
letter-spacing: 0.02em;
}
.newstext h3{
display: inline-block;
font-size: 2.35em;
float: left;
padding: 0 0.5em 0 0;
line-height: 1.2em;
}
.newstext p{
display: inline-block;
font-size: 1.55em;
float: left;
padding: 0 1em 0 0;
line-height: 1.3em;
margin-bottom: 0.5em;
}
.more{
display: inline-block;
background-color: #716960;
margin: 0 1em 1em auto;
float: right;
}
.more a{
display: block;
color: white;
padding: 0.5em 0.75em;
text-decoration: none;
font-size: 1.35em;
text-transform: uppercase;
letter-spacing: 0.03em;
float: right;
}
img{max-width:100%;}
h1, h2, h3, p{
color: white;
}
A possible solution, probably there is a better solution, i dont know skeleton.cssHTML-Code:
<div class="container">
<div class="row custom">
<div class="news nine columns">
<div class="newstext six columns">
</div>
</div>
</div>
</div>
CSS-Code:
.row.custom {
background: url(newsimg.jpg);
background-size: 40% 60%;
background-position: 20% center;
background-repeat: no-repeat;
margin: 50px auto;
}
.news.nine.columns {
position: relative;
float: right;
height: 100%;
background-color: #594f4e;
z-index:-1;
}
You have to adjust background-size, background-position...
Explanation:https://css-tricks.com/almanac/properties/b/background-position/ https://css-tricks.com/almanac/properties/b/background-size/
After that you need to add media queries to your CSS-Code, to adjust your design for smaller screens: http://www.w3schools.com/cssref/css3_pr_mediaquery.asp