Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making A Close Image Appear On Top Right Corner Of A DIV

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

like image 809
Hirvesh Avatar asked Feb 23 '11 08:02

Hirvesh


People also ask

How do I put an image in the top right corner of a div?

Try using float: right; and a new div for the top so that the image will stay on top.

How do I put an image on a right div?

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.

How do I put an image in the right corner in HTML?

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.

How do I position one image on top of another?

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.


2 Answers

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>
like image 78
stecb Avatar answered Nov 15 '22 22:11

stecb


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

like image 40
Scoobler Avatar answered Nov 15 '22 22:11

Scoobler