简体   繁体   中英

Creating like and dislike buttons in html and css

I'm creating these two like and dislike buttons.

在此输入图像描述

I'm having an issue when I set the width of the buttons to 48% to make them fill up the containing div , then they are displayed like the following. 在此输入图像描述

How can I display the circular span at the end like above? after setting the width to 48% .

code for the buttons.

 <button class="social-like" >
     <span class="like"><i class="glyphicon glyphicon-thumbs-up"></i></span>
     <span class="count" >0</span>
 </button>
    &nbsp;
 <button class="social-dislike" >
     <span class="dislike" >0</span>
     <span class="like"><i class="glyphicon glyphicon-thumbs-down"></i></span>
</button>

my css

.social-like, .social-dislike {
    border: none;
    outline: none;
    font-size: 16px;
    /*width: 48%;*/
    background-color: #03A9F4;
    color: #fff;
}

.social-like {
    border-top-left-radius: 5px;
}

.social-dislike {
    border-top-right-radius: 5px;
}

.count, .like, .dislike {
    padding:10px;
}

.count, .dislike {
    background-color: #03A9F4;
    border-radius: 50%;
    font-size:12px;
}

.dislike {
    margin-left: -13px;
}

.count {
    margin-right: -10px;
}

And also how can I make the like and dislike buttons to have a clickable effect?

example on fiddle

text-align

.social-like {
  border-top-left-radius: 5px;
    text-align: right;
}

.social-dislike {
  border-top-right-radius: 5px;
    text-align: left;
}

jsfiddle

EDIT
You can choose any type of effect you like, this is the target css for it, change the color , font-size or margin ect...

.like:focus,
.like:active,
.dislike:focus,
.dislike:active {
    //effect goes here
}

jsfiddle

You can do this if you use an <a> tag instead of a <button> . It's not exactly what you asked for, but it might be an option if you cannot find a solution to this.

Here is a demo: https://jsfiddle.net/DTcHh/26213/

<a class="social-like" >
                    <span class="like"><i class="glyphicon glyphicon-thumbs-up"></i></span>
                    <span class="count" >15</span>
                </a>
                &nbsp;
                <a class="social-dislike" >
                    <span class="dislike" >10</span>
                    <span class="like"><i class="glyphicon glyphicon-thumbs-down"></i></span>
                </a>

I added some classes to your demo:

.social-like:hover, .social-dislike:hover {
  text-decoration:none;
  color:white;
}

.social-like:active, .social-dislike:active {
  background-color: #3299CD;
}

.social-like:active .count, .social-dislike:active .dislike {
  background-color: #3299CD;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM