简体   繁体   English

在html和css中创建喜欢和不喜欢的按钮

[英]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. 当我将按钮的宽度设置为48%以使它们填满包含div ,我遇到了问题,然后它们显示如下。 在此输入图像描述

How can I display the circular span at the end like above? 如何在上面显示圆形span after setting the width to 48% . 将宽度设置为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 我的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 的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... 你可以选择你喜欢的任何类型的效果,这是它的目标css,更改colorfont-sizemargin ...

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

jsfiddle 的jsfiddle

You can do this if you use an <a> tag instead of a <button> . 如果使用<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/ 这是一个演示: 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果对同一评论单击不喜欢,则删除喜欢按钮的活动状态,如果单击喜欢,则删除不喜欢按钮的活动状态 - Remove like buttons active state if clicked dislike for the same comment and remove dislike buttons active state if clicked like 创建CSS滑块按钮,使其外观类似于bbc.co.uk - creating CSS slider buttons to look like bbc.co.uk AngularJs 中喜欢/不喜欢的功能 - Like/dislike functionality in AngularJs HTML / CSS:获取链接样式类似于按钮的链接 - HTML/CSS: Getting links styled like buttons to stack 相当于使用HTML5 / CSS3的计数器的按钮(而不是javascript?) - Equivalent of like buttons with counters using HTML5/CSS3 (and not javascript?) 我正在创建一个喜欢和不喜欢的按钮,但它会切换页面上所有帖子的喜欢计数,而不是被喜欢的帖子 - I am creating a like and dislike button, but it toggles the like count for ALL posts on the page, instead of the post being liked 带有本地存储的喜欢和不喜欢按钮 - Like and dislike button with local storage 使用jQuery和CSS,HTML创建像行号一样的文本编辑器 - Creating Text Editor like Line Numbers using jQuery and CSS, HTML 使用HTML和CSS创建复杂的Excel之类的网格结构 - Creating a complex excel like grid structure with HTML and CSS 在 CSS/HTML 中创建类似“缩放”的动态画廊视图 - Creating a 'Zoom' like dynamic gallery view in CSS/HTML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM