Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stack two arrow images (upvote/downvote) on top of eachother using CSS?

Tags:

css

alt textalt text

uparrow.gif and downarrow.gif

So, it would look like so:
alt text
alt text

How can I create 3 divs and style them with CSS so those arrows are positions with the top arrow above the bottom arrow?

<div class="vote">  
<div class="uparrow" />  
<div class="downarrow" />  
</div>

Should I create a "vote" div with restricted width? Would I float: top and float: bottom the two arrow divs with the background set as my two images? I plan on having content directly to the right of the vote arrows so it needs to be restricted and tight.

like image 458
Mithrax Avatar asked Dec 28 '25 11:12

Mithrax


2 Answers

Don't use divs for an image - there's already a perfectly good img tag!

<div class="vote">
    <img alt="^" title="vote up"   src="/images/up.arrow.png" />
    <img alt="v" title="vote down" src="/images/down.arrow.png" />
</div>

And then simply:

.vote
{
    width: 15px;
    float: left; clear: left;
}

.vote img
{
    display: block;
    float: none; clear: both;
}

You may want to add some margin to the .vote to separate it from the content it will be next to.

like image 186
Peter Boughton Avatar answered Dec 31 '25 07:12

Peter Boughton


By default, <div> elements are block-level meaning they are one-per-line and will expand horizontally to fill their container.

Adding the click handling is another problem. You could include the <a> and <img> elements in the uparrow and downarrow elements or you do it in CSS as you suggested (the less compatible way). Another option is registering DOM events with Javascript.

HTML:

<div class="vote">  
<div class="uparrow" />  
<div class="downarrow" />  
</div>

CSS:

div.vote {
  width: 50px;
  float: left;
}

div.uparrow {
  background-image: url(...);
}

div.downarrow {
  background-image: url(...);
}
like image 24
Andy Avatar answered Dec 31 '25 06:12

Andy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!