php - One CSS class overlapping another CSS class (image attached) -



php - One CSS class overlapping another CSS class (image attached) -

i creating e-commerce website. while showing discount box, image of item shifted left (image below). want discount box (blue color) on top of item class. can help me this?

css file

div.item { margin-top:0px; padding-top:20px; text-align:center; width:160px; float:left; border:1px solid red; } div.discount { width:30px; height:30px; border:1px solid blue; float:right; margin-right:30px; margin-top:10px; }

html file

<div class="item"> <img src="items/1/s/a.jpg"/> <div class="discount"> 50% discount </div> </div>

my illustration -- bluish box not overlapping image. instead displaces image.

i want this: in discount box overlaps image/css class

you utilize z-index , absolute positioning on top div. like:

div.discount { width:30px; position: absolute; z-index: 10; top: 8px; right: 8px; height:30px; border:1px solid blue; }

you utilize percentages instead of px in top , right create little more flexible.

edit: have add together position: relative div.item (absolute position applies based on closest containing element position applied).

z-index not strictly necessary long thing want on top appears before thing on bottom in code. set in there in case things moved around later.

php html css

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -