Ad

Overlapping Stackable, Clickable Shapes With CSS And/ Or JavaScript?

- 1 answer

This is going to be difficult for me to describe, so please bear with me.

I have a requirement to build an "upvote" control for a website. The number of "upvotes" is configurable in the system settings. The controls are supposed to look like green chevrons pointing up. If there are three, if you click on the top one, you have effectively "voted" with a weight of 3. If you subsequently click on the bottom chevron, you are effectively changing your vote weight to 1. There's also hover, click, and active styling associated with the vote chevrons.

The wireframes show these chevrons pretty closely stacked, to the point where the upper point of the bottom chevron is higher than the bottom point of the top chevron in my 3-vote example.

This sorta precludes me using images, as overlap would be a difficult experience to manage, I think. So I'm hoping there is a relatively straightforward way to "build" these shapes using CSS and/ or JavaScript and treat them as standard divs.

Am I in trouble? Or is there a relatively straightforward way to do this that is compatible with all modern browsers (IE 9+)?

Ad

Answer

This will give you the front end side started. At least a direction on where to go from there. With some JS and back-end programming you'll be able to make those font awesome icons register the value of 1, 2, or 3

HTML

<div class="container">
    <div class="rating">
        <div class="upvote">
            <div><i class="fa fa-chevron-up"></i></div>
            <div><i class="fa fa-chevron-up"></i></div>
            <div><i class="fa fa-chevron-up"></i></div>
        </div>
        <span class="divider"></span>
        <div class="downvote">
            <div><i class="fa fa-chevron-down"></i></div>
            <div><i class="fa fa-chevron-down"></i></div>
            <div><i class="fa fa-chevron-down"></i></div>
        </div>
    </div>
</div>

CSS

.rating{
    margin-top:30px;
}
.rating > div {
  position: relative;
  width: 1.1em;
  margin:-10px auto;
}

.rating .fa{
    font-size:32px;
    line-height: 0;
}
.rating .divider{
    width:40px;
    display:block;
    border-bottom: 3px solid black;
    height:5px;
    text-align:center;
    margin: 15px 458px 25px;

}
.upvote > div .fa-chevron-up:hover,
.upvote > div:hover ~ div .fa-chevron-up {
   color: green;
}

.downvote > div .fa-chevron-down:hover,
.downvote > div:hover ~ div .fa-chevron-down {
   color: red;
}

p.s. As you may already know, CSS doesn't traverse, therefore you'll need some help assigning hover attributes to the downvote section. If no one else has this answer by tomorrow, I'll build it for you.

Here's the DEMO

Ad
source: stackoverflow.com
Ad