keeping image contained within another image. - css

How can I keep a close button contained inside an image even is I change the img size using jquery
#full_image {
width: 200px;
height: 200px;
left: 0px;
top:10px;
position: relative;
opacity: 1;
z-index: 9;
}
#full_image img {
left: 20px;
width: 339px;
height: 211px;
position: relative;
overflow: hidden;
}
#full_image .close{
background: url("http://www.sobral.ce.gov.br/saudedafamilia/close.jpg") no-repeat;
top: 5px;
right: 0px;
cursor: pointer;
height: 29px;
opacity: 1;
position: absolute;
width: 29px;
z-index: 999;
}
<div id="full_image"><img src="http://coe.berkeley.edu/forefront/fall2005/images/woz1.jpg" />
<span> </span>
</div>
JSFIDDLE

Use the following CSS:
#full_image {
position: relative;
}
#full_image span {
position: absolute;
top: 0;
right: 0;
}
This tells the span to be a positioned relatively to #full_image, and stick to top right of it.
Hope this helps :)

You don't specify what "close button contained inside an image" means. I would have tried to put my image and button like this:
HTML:
<div>
<img id="myImage"></img>
<button id="myButton" />
</div>
CSS:
#myImage {
position: relative;
}
#myButton {
position: absolute;
top: ???;
left: ???;
}
jQuery:
You have to calculate where to place your button (what you should give the CSS-attributes for f ex top: and left: )

Related

How to create a rectangle with a high side and a lower one in css

i'm struggling with CSS trying to create special shape.
This is the shape i wanna create
enter image description here
Do you have any solution ?
Thank's
How about this:
div {
position: relative;
height: 300px;
overflow: hidden;
border-radius: 25px;
}
.bg {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
width: 100%;
height: 100%;
background-color: blue;
transform: skewY(-6deg);
transform-origin: top right;
border-radius: 25px;
<div>
<div class="bg"></div>
</div>

CSS - Why does pattern overlap button?

Here's my JS fiddle: https://jsfiddle.net/aeh8hxys/
Can somebody please tell me why (and how to stop!) the pattern overlaps my button? Thanks!
CSS:
.pattern
{
width:500px;
height:300px;
background-color: #FF0000;
}
.pattern:after {
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAA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Fja2V0IGVuZD0iciI/PtWxVHsAAABESURBVHjahI9BDgAgCMO0///zjBcDZk6OpIF2Shpm9nLWBQFSAuulBpPeVZgANZgPdGCcuAvEibtAnLgL5FV5uy8BBgBvsBUQrZ/GBQAAAABJRU5ErkJggg==") repeat;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
content: "\0020";
opacity: .5;
z-index: 0;
}
and HTML:
<div class="pattern">
<button class="btn btn-info">This is a button</button>
</div>
Because the pattern is "positioned" (a position value other than static), and has a z-index, which means it will appear over the button, which is non-positioned and has no z-index.
To make the button appear over the pattern, give it a position other than static and a z-index higher than pattern.
https://jsfiddle.net/aeh8hxys/1/
.pattern
{
width:500px;
height:300px;
background-color: #FF0000;
}
.pattern:after {
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZG93cykiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MkRGNDcyQ0Y4ODQ4MTFFNEFFRjVERDUwMjZBRDgzNUYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MkRGNDcyRDA4ODQ4MTFFNEFFRjVERDUwMjZBRDgzNUYiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDoyREY0NzJDRDg4NDgxMUU0QUVGNURENTAyNkFEODM1RiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDoyREY0NzJDRTg4NDgxMUU0QUVGNURENTAyNkFEODM1RiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PtWxVHsAAABESURBVHjahI9BDgAgCMO0///zjBcDZk6OpIF2Shpm9nLWBQFSAuulBpPeVZgANZgPdGCcuAvEibtAnLgL5FV5uy8BBgBvsBUQrZ/GBQAAAABJRU5ErkJggg==") repeat;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
content: "\0020";
opacity: .5;
z-index: 0;
}
button {
position: relative;
z-index: 1;
}
<div class="pattern">
<button class="btn btn-info">This is a button</button>
</div>

setting opacity for background image with url in css

I am using bootstrap along with HTML5 to develop a website.
I have a website header.
I wish to have an image in the website header with some opacity value and also some text in it.
I have referred this link setting opacity for background image and tried implementing it. I have got the text but not the image.
Here is the code:
HTML:
<div class="page-header head">
<div class="hbg"></div>
Hi there
</div>
CSS:
.head{
position: relative;
z-index: 1;
margin-top:10px;
height: 170px;
}
.head .hbg
{
background: url('hbg.png');
background-size: 100% 100%;
opacity: 0.3;
z-index: -1;
}
What is the issue here?
.head .bg doesnt exist in the code above. Change to .hbg.
How about this instead?
<div class="page-header head">
Hi there
</div>
-
.head{
width: 300px;
height: 250px;
display: block;
position: relative;
}
.head::after {
content: "";
background: url(hbg.png);
opacity: 0.3;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
}
You need to add position: absolute; top: 0; left: 0; to .hbg and width and height of 100% so it spreads all over the parent container:)
.head {
position: relative;
z-index: 1;
margin-top: 10px;
height: 170px;
}
.head .hbg {
position: absolute;
top: 0px;
left: 0px;
background: url('http://gillespaquette.ca/images/stack-icon.png');
background-size: cover;
opacity: 0.3;
z-index: -1;
width: 100%;
height: 100%;
}
<div class="page-header head">
<div class="hbg"></div>
Hi there
</div>

z-index attribute not working on container with image

do not know what I might be doing wrong, I tried to put it this way:
.container-image{
background: url('http://i.imgur.com/Dl8UBO7.png');
width: 226px;
height: 169px;
display: inline-block;
position: relative;
z-index: 20; // dont work
}
.container-image img{
position: absolute;
left: 14px;
top: 13px;
width: 199px;
height: 141px;
z-index: 10; // dont work
}
jsfiddle
I need the image is behind the edge (.container-image)
Put a container around the border div and the image. http://jsfiddle.net/7fqAu/2/
<div class='example'>
<div class="container-image"></div>
<img src="http://i.imgur.com/T0KMwIs.jpg">
</div>
body {
background: red;
}
.container-image {
background: url('http://i.imgur.com/Dl8UBO7.png');
width: 226px;
height: 169px;
position: relative;
z-index: 20;
}
.example {
width: 226px;
height: 169px;
position: relative;
}
.example img {
position: absolute;
left: 14px;
top: 13px;
width: 199px;
height: 141px;
z-index: 10;
}
You could add the border image to .container-image:after instead of as a background to .container-image - no need for z-index at all then.
jsfiddle here

width not inheriting from parent?

I'm attempting to have an overlay of an image. I've done it a bit before but for some reason today I'm obviously forgetting something. It seems to take the width of the entire page and not its parent:
#work_item {
position: relative;
width: auto;
}
#work_item img {}
#work_item a {
display: block;
position: absolute;
top: 0;
left: 0;
z-index: 30;
height: 100%;
width: 100%;
background: #000;
color: #FFF;
}
<div id='work_item'>
<img src="" />
Click Here!
</div>
Any Help?
#work_item {
display: inline-block;
position: relative;
left: 0px;
top: 0px;
z-index: 1;
height: auto;
width: auto;
}
#work_item img {
position: relative;
z-index: 1;
left: 0px;
top: 0px;
}
#work_item a {
display: block;
position: absolute;
top: 0px;
left: 0px;
z-index: 30;
height: 100%;
width: 100%;
background: rgba(0,0,0,0.8);
color: #FFF;
}​
<div id='work_item'>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQfMwj05-cLtN4hGPTSKJcsElDOeNTW65rlmQKXzRo5ZCbFmvuY0dccZMU" />
Click Here!
</div>
Demo: http://jsfiddle.net/38v3h/
Add this code, if you meant the #work_item:
#work_item {
position: relative;
width: auto;
display: inline-block;
}
Fiddle: http://jsfiddle.net/CRY3g/
div is a block element which occupy the whole width of the its parent regardless of the width of its content. There are many ways to make the div #work_item to wrap the content.
display inline-block;
#work_item {
position: relative;
width: auto;
display inline-block;
}
you can also float the div:
#work_item {
position: relative;
width: auto;
float: left;
}

Resources