I wanted to know how to make a small cross (close) image appear on the top right inside of a div. Using CSS and XHTML. Thanks
Try using float: right; and a new div for the top so that the image will stay on top.
Using Text-align property Another way to align image to the left, centre or right of the page is to use the text-align property. The html code uses the <div> tag and inline CSS style. The following are examples of how to align an image to the left, centre and right. Image will follow the left alignment of text block.
HTML 5 uses CSS property instead of this attribute. Attribute Values: left: It sets the alignment of the image to the left. right: It sets the alignment of the image to the right.
Add CSS. Add a relative div placed in the flow of the page. Set the background image as relative so as the div knows how big it must be. Set the overlay as absolute, which will be relative to the upper-left edge of the first image.
You could do it this way: jsfiddle.net/7JEAZ/1317
Code snippet:
#panel{
width:100px;
height:100px;
background:red;
}
#close{
display:block;
float:right;
width:30px;
height:29px;
background:url(https://web.archive.org/web/20110126035650/http://digitalsbykobke.com/images/close.png) no-repeat center center;
}
<div id="panel"><a id="close" href="#"></a></div>
In-case its any help, here is another example with the close button over the top right corner of the DIV, the code is an example showing it with two different sized div's and the jQuery to close the parent div of the image clicked. There is also a link to reshow the div.
CSS:
#content{
border: solid black;
width: 70%;
}
#info{
border: solid red;
width: 50%;
}
.close-image{
display: block;
float:right;
position:relative;
top:-10px;
right: -10px;
height: 20px;
}
HTML:
<a href="#" id="toggle-content">Show / Hide content</a>
<br/><br/>
<div id="content">
<img class="close-image" src="http://residentialsearch.savills.co.uk/Content/Images/icon_close.png" />
<b><u>Content:</u></b><br/>
This is the info inside the div!
</div>
<br/><br/>
<div id="info">
<img class="close-image" src="http://residentialsearch.savills.co.uk/Content/Images/icon_close.png" />
<b><u>Info:</u></b><br/>
Click the close button to hide this info!
</div>
jQuery:
$(".close-image").click(function() {
$(this).parent().hide();
});
$("#toggle-content").click(function() {
$("#content").slideToggle();
});
An example: click here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With