I want my div's to overlap - html

I'm trying to overlap some images, but whatever combination of positions I try, it doesn't seem to work.
this is the HTML
<li class="six">
<img class="06a" src="../inhouds/images/page06a.png">
<img class="06b" src="../inhouds/images/page06b.png">
<img class="06c" src="../inhouds/images/page06c.png">
</li>
this is the CSS
.06a {
position:absolute;
z-index: 250;
}
.06b {
position:absolute;
z-index: 260;
margin-left: 50px;
}
.06c {
position:absolute;
z-index: 270;
margin-left: 100px;
}
I hope someone can help me out!

Are you looking for this kind of overlap DEMO
Change markup to better semantic(alphabets for class,not numbers) :
<li class="six">
<img class="a" src="http://www.jonathanjeter.com/images/Square_200x200.png" />
<img class="b" src="http://www.jonathanjeter.com/images/Square_200x200.png" />
<img class="c" src="http://www.jonathanjeter.com/images/Square_200x200.png" />
</li>
CSS i did
li {
list-style:none
}

Click here for a working Demo
Do not start classnames with numbers. Use left instead of margin-left as you are using absolute positioning.
HTML
<img class="a06a" src="http://i.imgur.com/JMCU8.jpg">
<img class="a06b" src="http://i.imgur.com/UjdNhhO.jpg">
<img class="a06c" src="http://i.imgur.com/KOfaU.jpg">
CSS
.a06a {
position:absolute;
z-index: 250;
}
.a06b {
position:absolute;
z-index: 260;
left: 50px;
}
.a06c {
position:absolute;
z-index: 270;
left: 100px;
}

Here is a nice and clean example to understand how it works
CSS
.box1, .box2, .box3 {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
background: red;
}
.box2 {
background: green;
left: 50px;
}
.box3 {
background: blue;
left: 100px;
}
.container {
position: relative;
}
HTML
<div class="conatiner">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</div>
For something that you position absolute you should always have top and left defined.

Related

CSS Image on top of another image inside an anchor tag

I want to put two images inside an anchor tag where the second image is a player button which should be placed on top of the first image.
The anchor tag exists inside a span and that cannot change. Generally the HTML structure of the page cannot change.
Is it possible to achieve this?
This is what I have tried without success.
span.x {
display: block;
height: 40px;
width: 40px;
}
.x img {
width: 100%;
height: 100%;
.videoicon {
position: absolute;
top: 50%;
left: 50%;
}
}
<span class="x">
<a id="videolink" href="http://www.youtube.com/watch?v=ImTTW94ZicM"
class="video-class" target="_blank">
<img src="https://i.ytimg.com/vi/ImTTW94ZicM/mqdefault.jpg" border="2px" alt="Video">
<img class="videoicon" src="http://vignette3.wikia.nocookie.net/plazmabursttwo/images/a/a8/Play_button.p ng/revision/latest?cb=20121111212438" data-pin-nopin="true">
</a>
</span>
EDIT
There are many span elements with different sizes like the above that should be placed dynamically inside a div every time the page is rendered. So, I am not able to use hard-coded height/width/top etc values.
Thank you
This may help you, if videoicon has fixed height and width, you can set its position by calc(50% - half of videoicon's height) i.e., calc(50% - 20px)
span.x {
display: block;
position: relative;
height: 220px;
width: 220px;
}
.x img {
width: 100%;
height: 100%;
}
.x .videoicon {
position: absolute;
top:calc(50% - 20px);
left:calc(50% - 20px);
height:40px;
width:40px;
}
.small{
margin-top:20px;
height:100px!important;
width:100px!important;
}
<span class="x">
<a id="videolink" href="http://www.youtube.com/watch?v=ImTTW94ZicM" class="video-class" target="_blank">
<img src="https://i.ytimg.com/vi/ImTTW94ZicM/mqdefault.jpg" border="2px" alt="Video" />
<img class="videoicon" src="http://vignette3.wikia.nocookie.net/plazmabursttwo/images/a/a8/Play_button.png/revision/latest?cb=20121111212438" data-pin-nopin="true" />
</a>
</span>
<span class="x small">
<a id="videolink" href="http://www.youtube.com/watch?v=ImTTW94ZicM" class="video-class" target="_blank">
<img src="https://i.ytimg.com/vi/ImTTW94ZicM/mqdefault.jpg" border="2px" alt="Video" />
<img class="videoicon" src="http://vignette3.wikia.nocookie.net/plazmabursttwo/images/a/a8/Play_button.png/revision/latest?cb=20121111212438" data-pin-nopin="true" />
</a>
</span>
You can achieve that with positioning. Make the wrapper span position: relative to make the childrens position depending on the wrapper. Now just add position: absolute; with top:0; (or a value that suits your needs) to the second image:
span.x {
display: block;
position: relative;
height: 40px;
width: 40px;
}
.x img {
width: 100%;
height: 100%;
}
.videoicon {
position: absolute;
top: 0;
}
<span class="x">
<a id="videolink" href="http://www.youtube.com/watch?v=ImTTW94ZicM" class="video-class" target="_blank">
<img src="https://i.ytimg.com/vi/ImTTW94ZicM/mqdefault.jpg" border="2px" alt="Video" />
<img class="videoicon" src="http://vignette3.wikia.nocookie.net/plazmabursttwo/images/a/a8/Play_button.png/revision/latest?cb=20121111212438" data-pin-nopin="true" />
</a>
</span>
For demonstration purposes, I converted your LESS to CSS in the snippet above. The following code would be your LESS:
span.x {
display: block;
position: relative;
height: 40px;
width: 40px;
}
.x img {
width: 100%;
height: 100%;
.videoicon {
position: absolute;
top: 0;
}
}
this is Your code in which i have edit some portions
<html>
<head>
<style>
span.x {
display:block;
height:100%;
width:100%;
}
.x >img
{
width: 100%;
height:100%;
}
.videoicon{
position: absolute;
top: 50%;
left: 50%;
bottom: 0;
width: 50px;
z-index: 1000;
overflow: hidden;
right: 0;
}
#img11{
width:100%;
height:100%;
}
</style>
</head>
<body>
<span class="x">
<a id="videolink" href="http://www.youtube.com/watch?v=ImTTW94ZicM"
class="video-class" target="_blank">
<img id="img11" rc="https://i.ytimg.com/vi/ImTTW94ZicM/mqdefault.jpg" border="2px" alt="Video">
<img class="videoicon" src="http://vignette3.wikia.nocookie.net/plazmabursttwo/images/a/a8/Play_button.png/revision/latest?cb=20121111212438" data-pin-nopin="true">
</a>
</span>
</body>
</html>

:hover and :hover:before not working properly

I've gone through a lot of the resolved questions with a similar title but nothing I try seems to work.
I want the ava.png image to redirect to another page, but on hover I want a :before image (ava_background_hoover.png) to show up.
I may be going about it all wrong, but this is what I have so far:
#slide1 {
position: relative;
margin-left: 147px;
margin-top: 0px;
z-index: 100;
}
#slide1:hover {
position: relative;
}
#slide1:hover:before {
content: url("https://www.upload.ee/image/6050956/ava_background_hoover.png");
display: block;
position: absolute;
z-index: -1;
}
#slide2 {
opacity: 1;
position: relative;
z-index: 2;
margin-left: 7px;
margin-top: 0px;
}
#slide3 {
z-index: -1;
position: absolute;
}
<section id="header">
<div class="inner">
<img id="slide1" src="https://www.upload.ee/image/6050955/ava.png"/><img id="slide2" src="https://www.upload.ee/image/6050954/arrow.png" width="140" height="160" alt=""/>
</div>
</section>
Fiddle
You can set #slide1:before's content as the default image. Then, on :hover, change the content attribute to the hover image.
If you do so, you need to change the img to a div (or span, just not an img).
#slide1 {
position: relative;
margin-left: 147px;
margin-top: 0px;
z-index: 100;
display:inline-block;
}
#slide1:before {
content: url("https://www.upload.ee/image/6050955/ava.png");
}
#slide1:hover {
position: relative;
}
#slide1:hover:after {
content: url("https://www.upload.ee/image/6050956/ava_background_hoover.png");
display: block;
position: absolute;
z-index: -1;
}
#slide2 {
opacity: 1;
position: relative;
z-index: 2;
margin-left: 7px;
margin-top: 0px;
}
#slide3 {
z-index: -1;
position: absolute;
}
<section id="header">
<div class="inner">
<a id="slide1" href="http://google.com" target="_blank"></a>
<img id="slide2" src="https://www.upload.ee/image/6050954/arrow.png" width="140" height="160" alt=""/>
</div>
</section>
Working demo including the link: http://output.jsbin.com/cudimos
the :before and :after pseudo-elements are used to insert content before, or after, the content of an element . img doesn't have content. so you can't use pseudo-elements on img .
instead, you should use <div> with ids #slide1 and #slide2 in which you put img or use background-img on that divs , you choose.
i made a simple example below. click to show snippet. let me know if it helps
P.S. you can position the :before how you want. i just guessed how you wanted it
#slide1,#slide2 { display:inline-block}
#slide1 {
position: relative;
margin-left: 147px;
margin-top: 0px;
z-index: 100;
}
#slide1:hover {
position: relative;
}
#slide1:hover:before {
content: url("https://www.upload.ee/image/6050956/ava_background_hoover.png");
display: block;
position: absolute;
z-index: 1;
right: -150%;
bottom: -150%;
}
<section id="header">
<div class="inner">
<div id="slide1">
<img src="https://www.upload.ee/image/6050955/ava.png"/>
</div>
<div id="slide2">
<img src="https://www.upload.ee/image/6050954/arrow.png" width="140" height="160" alt=""/>
</div>
</div>
</section>

One img aligned on the left, and one on the center, both vertically aligned, inside same div

I am struggling aligning 2 imgs in the same div. I want one to be aligned on the left, and the other to be in the center. Any suggestion?
div {
background: red;
text-align: center;
}
div img{
vertical-align: middle;
}
.left {
float:left;
}
<div>
<img src="//placehold.it/50x50" class="left" />
<img src="//placehold.it/50x50" />
</div>
div {
text-align: center;
background: red;
}
.left {
float: left;
}
.center {
clear: left;
}
<div>
<img class="left" src="http://www.nasa.gov/sites/default/files/images/facebook-icon(3).png">
<img class="center" src="http://www.nasa.gov/sites/default/files/images/facebook-icon(3).png">
</div>
Fiddle
Its easy, just specify your div , and maybe give it a class
<div class="mydiv">
<img src="(your-image)" width="(size)" height="(size)" class="leftAlign">
<img src="(your second image)" width="(size)" height="(size)" class="centerAlign" >
</div>
And here is a stylesheet for alignment
.mydiv{
width:100%;
}
.leftAlign{
position:absolute;
top:20px;
left:0px;
}
.centerAlign{
position:absolute;
top:20px;
left:0;
right:0;
margin:auto;
}
This might work out for you.
I hope it helps.
Actually, bpeterson76, your code does not center the .center.
Check this out:
div {
position: relative;
}
.left {
position: absolute;
left: 0;
}
.center {
position: absolute;
left: 50%;
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%);
}
http://jsfiddle.net/4h8g9prb/
It works perfect, the only downside is browser support IE9 or later.
div {
position: relative;
text-align: center;
}
.left {
position: absolute;
left: 0;
}
<div>
<img src="http://placehold.it/50x50" class="left">
<img src="http://placehold.it/50x50">
</div>

How to add objects in a DIV and appear above the DIV

I am trying to add an image and a textbox inside a DIV that has a opacity of 60%. For some reason the two objects also inherits the opacity as well. How do I prevent it?
HTML:
<body>
<div id="sliderdiv">
<div id="slider">
<img src="i2.jpg" alt="" />
<img src="i3.jpg" alt="Pure Javascript. No jQuery. No flash." />
<img src="i4.jpg" alt="#htmlcaption" />
<img src="i5.jpg" />
</div>
<div id="htmlcaption" style="display: none;">
<em>HTML</em> caption. Link to Google.
</div>
</div>
<div id="bg">
<img src="wmlogo.jpg" width="140" height="30" alt="Westmed Medical Group" title="Westmed Medical Group Homepage" id="logoimg" />
<input type=text size=25 id=insidebgtext />
</div>
</body>
CSS:
* {
background-color: #CC0000;
padding: 0px;
margin: 0px;
}
#bg {
position: absolute;
background-color: #000000;
height: 50px;
width: 100%;
opacity:0.6;
filter:alpha(opacity=60); /* For IE8 and earlier */
z-index: 1;
}
#insidebgtext {
position: absolute;
top: 25%;
right: 20%;
background-color: #FFFFFF;
z-index: 25;
}
#sliderdiv
{
position:absolute;
left:0px;
top:0px;
width: 100%;
height: 306px;
z-index:-1;
background-color: #FCFCFC;
}
#logoimg {
position: absolute;
top: 15%;
left: 25%;
z-index: 25;
}
How it appears:
The inheritance of the properties of parents in the child in very obvious. For your purpose you can use a proxy way of using a transparent png image for the background and avoid the use of opacity all together.

align text to the right of an div container

CSS
div_p {
}
.img_block {
display: inline-block;
position: relative;
}
.img_o {
width: 100px;
height: 100px;
float: left;
}
.img_i {
position: absolute;
top: 0px;
right: 0px;
width: 50px;
height: 50px;
}
HTML
<div>
<div class="img_block gwd-div-0pxe">
<img class="img_o" src="images/scene1.jpg">
<img class="img_i" src="images/scene2.jpg"><span style="position:absolute; top:10px;right:10px;">100</span>
</div>
<div class="div_p"><p>hi hello how are you</p></div>
<div class="img_block">
<img class="img_o" src="images/scene2.jpg">
<img class="img_i" src="images/scene3.jpg"><span style="position:absolute; top:10px; right:10px;">100</span>
</div>
<div class="div_p"><p>hi hello how are you</p></div>
<div class="img_block">
<img class="img_o" src="images/scene4.jpg">
<img class="img_i" src="images/scene5.jpg"><span style="position:absolute; top:10px; right:10px;">100</span>
</div>
<div class="div_p"><p>hi hello how are you</p></div>
</div>
i need to bring the text of class div_p to the right of the images but currently its placed below the image by this code.
Set the images to float left.
.img_block {
float: left;
}
try it
<div class="img_block">
<img class="img_o" src="images/scene2.jpg">
<img class="img_i" src="images/scene3.jpg"><span style="position:absolute; top:10px; right:10px;">100</span>
<div class="div_p"><p>hi hello how are you</p></div>
</div>
Try this:
.div_p p {
float: right;
max-width: 80px;
min-width: 80px;
}
.img_o {
float: left;
max-width: 400px;
min-width: 400px;
}
And use max-width to limit its width so that it would not come in the container of the text. And the text will stay there.
Here is fiddle: http://jsfiddle.net/afzaal_ahmad_zeeshan/e2u4y/1/
you should apply
.div_p {
float: left;
}
or
.div_p {
position: absolute;
right: 10px; /* or whatever you want */
}
and then style it how you want to