Im trying to put a background image over an image.
Basically its to show if a 'user' has approved or denied something.
I want if approved to display a green tick over the users display image.
I tried to create it but what i have does not work.
This is what i have so far:
Html
<img class="small-profile-img accepted" src="http://www.image.com/image.gif" alt="">
CSS
.small-profile-img{
width:30px;
display:inline;
border:2px solid #000000;
}
.accepted{
background-image:url("tick.png") !important;
background-repeat:no-repeat;
background-position:right bottom;
z-index:100;
background-size:18px;
}
See jsfiddle for working example.
jsfiddle
The solution would be is to use wrapper with after pseudo element for accepted class:
.accepted:after {
content: '';
display: block;
height: 18px;
width: 18px;
position: absolute;
bottom: 0;
right: 0;
background-image:url("http://cdn1.iconfinder.com/data/icons/checkout-icons/32x32/tick.png");
background-repeat: no-repeat;
background-position: right bottom;
z-index: 100;
background-size: 18px;
}
HTML
<div class="small-profile-img accepted">
<img src="http://2.bp.blogspot.com/-KLcHPORC4do/TbJCkjjkiBI/AAAAAAAAACw/zDnMSWC_R0M/s1600/facebook-no-image1.gif" alt="">
</div>
http://jsfiddle.net/vpgjr/7/
Background images go behind foreground content. An <img> is foreground content.
The only way you could see the background image would be if the foreground image had translucent pixels over the background image.
The tick appears to be content (rather than decoration) though, so it should probably be represented as an <img> anyway.
<div class="image-container">
<img class="small-profile-img"
src="http://www.image.com/image.gif"
alt="">
<img class="approved"
src="tick.png"
alt="Approved">
</div>
.image-container {
position: relative;
}
.image-container .small-profile-img {
position: relative;
z-index: 2;
}
.image-container .approved {
position: absolute;
z-index: 3;
top: 50px;
left: 50px;
}
Why dont you use position:absolute
HMTL
<div class="wrap">
<img src="http://2.bp.blogspot.com/-KLcHPORC4do/TbJCkjjkiBI/AAAAAAAAACw/zDnMSWC_R0M/s1600/facebook-no-image1.gif" alt="">
<div class="inner"> <img src="http://cdn1.iconfinder.com/data/icons/checkout-icons/32x32/tick.png" width="18"/></div>
</div>
CSS
.wrap{
position:relative;
background:red;
height:auto; width:30px;
font-size:0
}
.wrap > img{
width:30px;
display:inline;
}
.inner{
position:absolute;
top:30%;
left:50%;
margin:-5px 0 0 -9px
}
DEMO
set
position:absolute
Then set left,top (bottom,right if needed) property.
yea, i'd go the other way around.
change the class of the img when it's accepted.
HTML:
<div class='holder'>
<img class='unaccepted' src="http://cdn1.iconfinder.com/data/icons/checkout-icons/32x32/tick.png" alt="">
</div>
CSS:
.small-profile-img{
width:30px;
display:inline;
border:2px solid #000000;
}
.holder{
width:40px;
height:30px;
background-image:url("http://2.bp.blogspot.com/-KLcHPORC4do/TbJCkjjkiBI/AAAAAAAAACw/zDnMSWC_R0M/s1600/facebook-no-image1.gif");
background-size: 100%, 100%;
background-repeat:no-repeat;
background-position:center;
text-align: center;
}
.accepted{
border:none;
display:inline;
}
.unaccepted{
display:none;
}
Related
I am attempting to apply a css background behind an img icon I am importing into my project. When trying to do so the css background that I have applied completely covers the image. I am attempting to have the image set on top of the background to give it a border look.
I've attempted to adjust the z-index but it had no effect. I also attempted to use add a pseudo class but that does not show the css background color I applied.
How can I achieve this?
Here is some code sample:
img {
height:32px;
width:32px;
z-index: 500;
}
.background {
width:40px;
height:40px;
background: blue;
opacity: 0.08;
border-radius: 8px;
}
<div class="background">
<img src='https://i.ibb.co/GRJGJ2V/sharemoney.png'/>
</div>
<div class="">
<img src='https://i.ibb.co/GRJGJ2V/sharemoney.png'/>
</div>
I am expecting the image to sit in the center of the background: blue; I am attempting to apply.
img {
height:32px;
width:32px;
z-index: 500;
position: absolute;
left: 12px;
top: 12px;
}
.background {
width:40px;
height:40px;
background: blue;
opacity: 0.08;
border-radius: 8px;
position: absolute;
}
<div class="background">
<img src='https://i.ibb.co/GRJGJ2V/sharemoney.png'/>
</div>
<div class="">
<img src='https://i.ibb.co/GRJGJ2V/sharemoney.png'/>
</div>
I just set the position to absolute and set the offsets.
Picture describes all. I know how to make this circular image. But still don't know the way to place the image like this. Circular Image should stay middle of the div, as the div's width change.
you have to set the parent element as relative (position:relative) the wrap your img in a div with an absolute position 50% left or right depending on you.
<figure>
<figcaption class="top">assassin's creed</figcaption>
<div><img src=http://www.pulpfortress.com/wp-content/uploads/2010/11/Ezio-Assassins-Creed.jpg /><div>
</figure>
Demo
figure{
width:400px;
height:300px;
background:#444;
position:relative;
}
figure div{
width:150px;
height:150px;
overflow:hidden;
border-radius:100%;
position:absolute;
bottom:-75px;
left:50%;
margin-left:-75px;
}
figure img{
width:100%;
height:160px;
}
figcaption{
width:100%;
text-align:center;
padding-top:40px;
color:white;
font-size:20px;
}
You could use position relative to shift the image from the bottom div over the boundary between the two.
CSS
.top {
background: grey;
height: 120px;
}
.bottom {
background: white;
text-align: center;
height: 60px;
}
.bottom > img {
position: relative;
top: -50%;
}
HTML
<div class="wrap">
<div class="top">HELLO PROGRAMMERS!</div>
<div class="bottom"><img src="image.png" /></div>
</div>
How do I get a div background image to show above a img html tag. The reason for wanting to do this is for a semitransparent texture that overlays rotating images in a banner. I don't want to have to cut the texture with the image each time. That way adding/updating images in the future would be faster. I have tried the advice given in this post, but did not seem to work: CSS show div background image on top of other contained elements. Thanks for any help.
html:
<div id="sliderFrame">
<div id="slider">
<span id="slider-background">
<img src="/_images/rotating-banner/001.jpg" />
</span>
</div>
</div>
CSS:
#sliderFrame {position:relative;width:850px;margin: 0 auto;}
#slider {
width:850px;height:470px;/* Make it the same size as your images */
background:#fff url(/_images/marqueeLayout/loading.gif) no-repeat 50% 50%;
position:relative;
margin:0 auto;/*make the image slider center-aligned */
box-shadow: 0px 1px 5px #999999;
}
#slider-background{
position:absolute;
background: url(/_images/marqueeLayout/MarqueeTexture.png) no-repeat;
width: 850px;
height: 470px;
z-index: 100;
}
link to live site: http://lltc.designangler.com/
try:
HTML:
<div id="wrapper">
<div id="img"></div>
<div id="overlay"></div>
</div>
CSS:
#wrappaer{display:inline-block; position:relative; width:100px; height:100px;
box-shadow: 0px 1px 5px #999999;}
#img{display:block; position:absolute; z-index:1}
#overlay{display:block; position:absolute; z-index:2
opacity:0.3;
filter:alpha(opacity=30); /* For IE8 and earlier */}
make sure to adjust wrapper,img and overlay sizes, add your images etc'.
have you tried setting the opacity of the div element?
Edit:
After rereading your question, I believe this may not be what you're looking for. Have you tried explicitly setting the z-index of the slider element in the CSS as well?
I finally solved the issue by using an img of the background inside a div instead of making it a background image. My updated code is below:
<div id="sliderFrame">
<div id="overlay"><img src="/_images/marqueeLayout/MarqueeTexture.png" /></div>
<div id="slider">
<img src="/_images/rotating-banner/001.jpg" />
</div>
</div>
CSS:
#overlay{
display:block;
position:absolute;
width: 850px;
height: 470px;
z-index: 2;
}
The background image, as its name suggest, can never be in front of the child elements. Therefore, you will need to rely on absolute positioning to overlay that background image over the slideshow:
#sliderFrame {
position: relative;
width: 850px;
margin: 0 auto;
}
#slider {
width:850px;
height:470px;
background:#fff url(/_images/marqueeLayout/loading.gif) no-repeat 50% 50%;
position:relative;
margin:0 auto;
box-shadow: 0px 1px 5px #999999;
}
#slider-background {
display: block;
position: relative;
width: 850px;
height: 470px;
z-index: 100;
}
#slider-background:before {
background: url(/_images/marqueeLayout/MarqueeTexture.png) no-repeat;
content:"";
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 100;
}
#slider-background img {
display: block;
}
I have chosen to use a pseudo element that is positioned absolutely over the #slider-background element itself, and it is stretch to the element's dimension by setting all four offsets to 0. Remember that you will also need to declare the #slider-background and its child <img> element as block-level elements.
http://jsfiddle.net/teddyrised/XJFqc/
I have this code :
<div class="header_photo">
<div class="header_inside">
<div class="header_text">
Text
</div>
</div>
<div class="header_photo_transparent"> </div>
</div>
.header_inside
{
top: 0px;
left: 0px;
display: block;
width: 975px;
background: none repeat scroll 0% 0% transparent;
z-index: 4;
position: absolute;
}
.header_text
{
position:absolute;
bottom:15px;
width:500px;
z-index:201;
left:370px;
font-size:12px;
line-height:13px;
}
.header_photo_transparent
{
position:absolute;
bottom:0;
left:0;
width:960px;
height:64px;
background-color: red;
z-index:100;
}
and I'd like to display the string Text over the red background, without :
changing the z-index of header_photo_transparent;
without removing position:absolute from header_inside
In fact I don't see the string Text.
Why this behaviour? And how can I fix this trouble?
Z-index is not at fault, just remove the z-index and use the positioning. The positioning is out, not the layers.
http://jsfiddle.net/zaSKZ/1/
alt text http://img13.imageshack.us/img13/9776/dviswheretogo.png
Blue is where the image of the corners will go
Green is a repeating image on the x axis on the top, all part of the same template!
And orange is a simgle image repeating on the y axis
For clarification here is what I've tried so far, i'm angry about this because when I use relative position it breaks because of an with background that is above! Anyway I need to define a height and width for each item!
.sheet {position:relative;
top:140px;
width:1000px;}
.tl {
background:url(../images/sheet_top_left-trans.png) no-repeat;
width:20px;
height:20px;
top:0px;
left:0px;}
.tm {
background:url(../images/sheet_top-trans.png) repeat-x;
width:960px;
height:20px;}
.tr {
background:url(../images/sheet_top_right-trans.png) no-repeat;
width:20px;
height:20px;
top:0px;
right:0px;}
.content {
background:url(../images/sheet_middle.png) repeat-y;
top:20px;
width:1000px;
height:400px;}/* Demonstration only, please remove later */
.bl {
background:url(../images/sheet_bottom_left-trans.png) no-repeat;
width:20px;
height:30px;}
.bm {
background:url(../images/sheet_bottom-trans.png) repeat-x;
height:30px;
width:960px;
bottom:0px;
left:20px;}
.br {}
and the html
<div class="sheet"><!-- Glass Effect Starts here -->
<div class="tl"></div>
<div class="tm"></div>
<div class="tr"></div>
<div class="content">Here we go again</div>
<div class="bl"></div>
<div class="bm"></div>
<div class="br"></div>
If I use absolute postitioning I can't make the bottom images stick to it! tho it works at the top!
Now I've found I way to do it that is cross-browser (even IE6 just don't use transparent PNG as I did) here we go:
HTML:
<div class="sheet">
<div class="top_sheet">
<div class="tl"></div>
<div class="tm"></div>
<div class="tr"></div>
</div>
<div class="middle">.</div>
<div class="bottom_sheet">
<div class="bl"></div>
<div class="bm"></div>
<div class="br"></div>
</div>
</div><!-- End of the sheet class -->
CSS:
.sheet {position:relative;
width:1000px;
top:10px;}
.top_sheet {width:1000px;
height:20px;}
.tl {float:left;
background:url(../images/sheet_top_left-trans.png) no-repeat;
height:20px;
width:20px;}
.tm {float:left;
background:url(../images/sheet_top-trans.png) repeat-x;
height:20px;
width:960px;}
.tr {float:right;
background:url(../images/sheet_top_right-trans.png) no-repeat;
height:20px;
width:20px;}
.middle {position:relative;
background: url(../images/sheet_middle.png) repeat-y;
width:1000px;
height:400px;}
bottom_sheet {width:1000px;
height:30px;}
.bl {float:left;
background:url(../images/sheet_bottom_left-trans.png) no-repeat;
width:20px;
height:30px;}
.bm {float:left;
background:url(../images/sheet_bottom-trans.png) repeat-x;
width:960px;
height:30px;}
.br {float:right;
background:url(../images/sheet_bottom_right-trans.png) no-repeat;
width:20px;
height:30px;}
Trying to use the same html you already have, here is something that seems to work pretty well.
Move the corners into an all encompassing top and bottom bar. And then float the respective corners left and right.
CSS:
.sheet {
position:relative;
width:1000px;
top:140px;}
.tl {
background:url(images/sheet_top_left-trans.png) no-repeat;
float:left;
width:20px;
height:20px;
margin-left:-20px;}
.tm {
background:url(images/sheet_top-trans.png) repeat-x;
height:20px;
margin-left:20px;}
.tr {
background:url(images/sheet_top_right-trans.png) no-repeat;
float:right;
width:20px;
height:20px;}
.content {
background:url(images/sheet_content.png) repeat-y;
clear:both;
height:200px;}/* Demonstration only, please remove later */
.bl {
background:url(images/sheet_bottom_left-trans.png) no-repeat;
float:left;
width:20px;
height:30px;}
.bm {
background:url(images/sheet_bottom-trans.png) repeat-x;
height:30px;}
.br {
background:url(images/sheet_bottom_right-trans.png) no-repeat;
float:right;
width:20px;
height:30px;}
HTML:
<div class="sheet"><!-- Glass Effect Starts here -->
<div class="tm">
<div class="tl"></div>
<div class="tr"></div>
</div>
<div class="content">Here we go again</div>
<div class="bm">
<div class="bl"></div>
<div class="br"></div>
</div>
</div>
Have you tried some cross-browser css framework, e.g. http://www.blueprintcss.org?
These frameworks usually let you define grids and will help you to overcome browser-specific quirks by resetting certain css properties ...
Fluid width containers with rounded corners using valid CSS and XHTML
The method I usually see is nesting all the divs to layer them, then setting the background-repeat and background-position on each one. Basic example:
<div class="tl">
<div class="tr">
<div class="content">Here we go again</div>
</div>
</div>
With CSS:
.tl, .tr {
width: 100%;
height: 100%;
}
.tl {
background: url("tl.png") no-repeat 0 0;
}
.tr {
background: url("tr.png") no-repeat 100% 0;
}
Simply scale that up to use all your separate images. You'll need to have the sides first (on the outside of the 'div nest') and the corners last (on the inside, right before the content div).
It's a classic case of "divitis", but it's hard to avoid until CSS3 is well supported (where you can use multiple backgrounds or simply a border image). You might was to check out Sliding Doors, which shows a technique for reducing the number of elements/images needed.
css:
.sheet {
position:relative;
top:140px;
width:1000px;
}
.tl {
background:url(blue.bmp) no-repeat;
width:20px;
height:20px;
top:0px;
left:0px;
}
.tm {
position: absolute;
background:url(green.bmp) repeat-x;
width:960px;
height:20px;
left: 20px;
top: 0px;
}
.tr {
position: absolute;
background:url(blue.bmp) no-repeat;
width:20px;
height:20px;
top:0px;
right:0px;
}
.content {
background:url(orange.bmp) repeat-y;
top:20px;
width:1000px;
height:400px;}/* Demonstration only, please remove later */
.bl {
background:url(blue.bmp) no-repeat;
width:20px;
height:30px;}
.bm {
position: absolute;
background:url(green.bmp) repeat-x;
height:30px;
width:960px;
bottom:0px;
left:20px;}
.br {
position: absolute;
background:url(blue.bmp) no-repeat;
width:20px;
height:30px;
top:420px;
right:0px;
}
html:
<div class="sheet"><!-- Glass Effect Starts here -->
<div class="tl"></div>
<div class="tm"></div>
<div class="tr"></div>
<div class="content">Here we go again</div>
<div class="bl"></div>
<div class="bm"></div>
<div class="br"></div>
I put absolute positioning on each divs so that we can position it side by side. Hope it helps.
BTW, I changed the background url. :)
Winks as he says this and may regret it:
You know, if you used a table... ;>P!
(Now, waits for the tables vs. css crowd to unleash!)
This looks like your regular, garden-variety rounded corners 'section'.
Here's one without images:
http://www.html.it/articoli/nifty/index.html
Here's one with:
http://kalsey.com/2003/07/rounded_corners_in_css/
When you're finished coding it and it looks like what you want, turn it into a code snippet and keep it.
I don't mean to be a smartarse, but you hardly need 7 divs for what you try to achieve. Five divs are enough (in most case you don't even need that. I really don't know how to explain, but you can check http://www.nil.com/english (Quick links or Get support boxes) for source.
Also, there is a great book about it called "Bulletproof web design"
You were close. You yet have to position the containing element relative (so that all absolute positioned child elements are relative to it) and to position the corner parts absolute. Here's a SSCCE:
<!doctype html>
<html lang="en">
<head>
<title>SO question 1898479</title>
<style>
.sheet {
position: relative;
width: 200px;
}
.tl {
position: absolute;
width:20px;
height:20px;
top: 0;
left: 0;
background: blue;
}
.tm {
position: absolute;
height:20px;
top: 0;
left: 20px;
right: 20px;
background: green;
}
.tr {
position: absolute;
width: 20px;
height: 20px;
top: 0;
right: 0;
background: blue;
}
.content {
background: orange;
padding: 20px 0; /* Padding must be at least as much as the "borders" are thick. */
height: 300px;
}
.bl {
position: absolute;
width: 20px;
height: 20px;
bottom: 0;
left: 0;
background: blue;
}
.bm {
position: absolute;
height: 20px;
bottom: 0;
left: 20px;
right: 20px;
background: green;
}
.br {
position: absolute;
width: 20px;
height: 20px;
bottom: 0;
right: 0;
background: blue;
}
</style>
</head>
<body>
<div class="sheet">
<div class="tl"></div>
<div class="tm"></div>
<div class="tr"></div>
<div class="content">Here we go again</div>
<div class="bl"></div>
<div class="bm"></div>
<div class="br"></div>
</div>
</body>
</html>
You only need to ensure that you're using the strict doctype as used in the above example so that it works in IE as well.