- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在通过一些单选按钮构建一个小星 CSS 评级,并且它工作正常。我无法在选择 radio 之前填写星星,所以如果选择了星星 3,那么星星 1 和 2 也会被填入。这是我目前所拥有的:
#review-form input,
#review-form textarea {
background: none repeat scroll 0 0 #333333;
border: 0 none;
color: #fff;
margin: 0;
max-width: 100%;
padding: 7px 4px;
}
#review-form .radio {
display: inline-block;
}
#review-form input[type=radio] {
display: none;
}
#review-form input[type=radio] + label {
display: block;
}
#review-form input[type='radio'] + label:before {
display: inline-block;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
padding-right: 8px;
width: 23px;
}
#review-form input[type=radio] + label:before {
content: "\f006"; /* Radio Unchecked */
}
#review-form input[type=radio]:checked + label:before {
content: "\f005"; /* Radio Checked */
}
<link href="//netdna.bootstrapcdn.com/font-awesome/3.0/css/font-awesome.css" rel="stylesheet" />
<div class="form-group" id="review-form">
<label for="rating">RATING</label>
<span class="star-rating star-5">
<div class="radio">
<input type="radio" id="option1" name="star-radios" value="1">
<label for="option1"></label>
</div>
<div class="radio">
<input type="radio" id="option2" name="star-radios" value="2">
<label for="option2"></label>
</div>
<div class="radio">
<input type="radio" id="option3" name="star-radios" value="3">
<label for="option3"></label>
</div>
<div class="radio">
<input type="radio" id="option4" name="star-radios" value="4">
<label for="option4"></label>
</div>
<div class="radio">
<input type="radio" id="option5" name="star-radios" value="5">
<label for="option5"></label>
</div>
</span>
</div>
我想知道是否有可用的 CSS 选择器(或其他东西),我可以在其中更改选择单选按钮之前的星号。尽可能避免使用 JS。
最佳答案
只有 CSS,你可以使用 flexbox。
使用 flex-direction: row-reverse;
row-reverse: Behaves the same as row but the main-start and main-end points are permuted.
The ~ combinator separates two selectors and matches the second element only if it is preceded by the first, and both share a common parent.
#review-form .star-rating {
display: inline-flex;
flex-direction: row-reverse;
}
#review-form input[type=radio] + .label_star::before {
content: "\f006";
/* Radio Unchecked */
}
#review-form input[type=radio]:checked ~ .label_star::before {
content: "\f005";
/* Radio Checked */
}
#review-form .star-rating {
display: inline-flex;
flex-direction: row-reverse;
}
#review-form input,
#review-form textarea {
background: none repeat scroll 0 0 #333333;
border: 0 none;
color: #fff;
margin: 0;
max-width: 100%;
padding: 7px 4px;
}
#review-form .radio {
display: inline-block;
}
#review-form input[type=radio] {
display: none;
}
#review-form input[type=radio] + label {
display: block;
}
#review-form input[type='radio'] + .label_star:before {
display: inline-block;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
//padding-right: 8px;
width: 23px;
}
#review-form input[type=radio] + .label_star::before {
content: "\f006";
/* Radio Unchecked */
}
#review-form input[type=radio]:checked ~ .label_star::before {
content: "\f005";
/* Radio Checked */
}
<link href="//netdna.bootstrapcdn.com/font-awesome/3.0/css/font-awesome.css" rel="stylesheet" />
<div class="form-group" id="review-form">
<label id="rating" for="rating">RATING</label>
<span class="star-rating star-5">
<input type="radio" id="option5" name="star-radios" value="5">
<label class="label_star" id="option5_label" for="option5"></label>
<input type="radio" id="option4" name="star-radios" value="4">
<label class="label_star" id="option4_label" for="option4"></label>
<input type="radio" id="option3" name="star-radios" value="3">
<label class="label_star" id="option3_label" for="option3"></label>
<input type="radio" id="option2" name="star-radios" value="2">
<label class="label_star" id="option2_label" for="option2"></label>
<input type="radio" id="option1" name="star-radios" value="1">
<label class="label_star" id="option1_label" for="option1"></label>
</span>
</div>
如评论中所述,我不久前创建了一个小的评级组件,可能会有帮助。做了一些调整以满足要求,但它使用 JS。
该组件使用以下内容:
jQuery Dependant (not complex, could be removed).
//Summary: Star Rating Component, get and/or set a rating displaying icons.
(function() {
// Assign variables for jQuery Objects and classes as string.
var $rating = $(".rating"),
sRatingClass = "rated",
sIcon = "icon-star-full",
$icon = $("." + sIcon);
// Iterate over jQuery Rating objects.
$.each($rating, function() {
// Get the rating if set, you can set this with a REST service and get the current rating.
var iRating = $(this).data("rating");
// Filter the icons with a :nth-child pseudo-class and add the 'active' class.
$(this).find("."+ sIcon + ":nth-child(-n+" + iRating + ")").addClass(sRatingClass);
});
// Add click event listener to jQuery Icon Objects.
$icon.on("click", function() {
// Get the index of the icon being clicked.
var iIconIndex = $(this).index() + 1,
// Select the parent of the icon being clicked.
$iconParent = $(this).parent();
// Remove the 'active' class to all the icons before setting the new ones.
$iconParent.find("." + sIcon).removeClass(sRatingClass);
// Add the 'active' class to the icon clicked and its previous siblings.
$iconParent.find("." + sIcon + ":nth-child(-n+" + iIconIndex + ")").addClass(sRatingClass);
// Set the rating to the parent, this can be sent to the backend with a REST service.
$iconParent.attr("data-rating", iIconIndex);
});
})();
.svg-spritesheet { /* Hide the SVG Spritesheet to prevent some browsers to render an empty white space. */
display: none;
}
.icon { /* Default icon properties, using the currentColor variable to be able to change the icon's color with the CSS color property. */
display: inline-block;
width: 1em;
height: 1em;
stroke-width: 0;
stroke: currentColor;
fill: currentColor;
cursor: pointer;
}
.icon-star-full { /* The icon's fill color */
color: #C1C2C4;
}
.icon-star-full.rated { /* The icon's 'active' fill color */
color: #F6DB08;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<section class="rating" data-rating="4">
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
</section>
<section class="rating" data-rating="0">
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
</section>
<svg class="svg-spritesheet">
<symbol id="icon-star-full" viewBox="0 0 32 32">
<title>star-full</title>
<path d="M32 12.408l-11.056-1.607-4.944-10.018-4.944 10.018-11.056 1.607 8 7.798-1.889 11.011 9.889-5.199 9.889 5.199-1.889-11.011 8-7.798z"></path>
</symbol>
</svg>
使用 IcoMoon免费星形图标。
你可以加入一些动画来改善视觉效果,就像AnimateCss一样。
$.fn.extend({
animateCss: function (animationName) {
var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
this.addClass('animated ' + animationName).one(animationEnd, function() {
$(this).removeClass('animated ' + animationName);
});
}
});
//Summary: Star Rating Component, get and/or set a rating displaying icons.
(function() {
// Assign variables for jQuery Objects and classes as string.
var $rating = $(".rating"),
sRatingClass = "rated",
sIcon = "icon-star-full",
$icon = $("." + sIcon);
// Iterate over jQuery Rating objects.
$.each($rating, function() {
// Get the rating if set, you can set this with a REST service and get the current rating.
var iRating = $(this).data("rating");
// Filter the icons with a :nth-child pseudo-class and add the 'active' class.
$(this).find("." + sIcon + ":nth-child(-n+" + iRating + ")").addClass(sRatingClass);
});
// Add click event listener to jQuery Icon Objects.
$icon.on("click", function() {
// Animate icon
$(this).animateCss("bounceIn");
// Get the index of the icon being clicked.
var iIconIndex = $(this).index() + 1,
// Select the parent of the icon being clicked.
$iconParent = $(this).parent();
// Remove the 'active' class to all the icons before setting the new ones.
$iconParent.find("." + sIcon).removeClass(sRatingClass);
// Add the 'active' class to the icon clicked and its previous siblings.
$iconParent.find("." + sIcon + ":nth-child(-n+" + iIconIndex + ")").addClass(sRatingClass);
// Set the rating to the parent, this can be sent to the backend with a REST service.
$iconParent.attr("data-rating", iIconIndex);
});
})();
.svg-spritesheet { /* Hide the SVG Spritesheet to prevent some browsers to render an empty white space. */
display: none;
}
.icon { /* Default icon properties, using the currentColor variable to be able to change the icon's color with the CSS color property. */
display: inline-block;
width: 1em;
height: 1em;
stroke-width: 0;
stroke: currentColor;
fill: currentColor;
cursor: pointer;
}
.icon-star-full { /* The icon's fill color */
color: #C1C2C4;
font-size: 3em;
}
.icon-star-full.rated { /* The icon's 'active' fill color */
color: #F6DB08;
}
.animated {
-webkit-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both
}
.animated.bounceIn {
-webkit-animation-duration: .75s;
animation-duration: .75s
}
@keyframes bounceIn {
0%,100%,20%,40%,60%,80% {
-webkit-animation-timing-function: cubic-bezier(0.215,.61,.355,1);
animation-timing-function: cubic-bezier(0.215,.61,.355,1)
}
0% {
opacity: 0;
-webkit-transform: scale3d(.3,.3,.3);
transform: scale3d(.3,.3,.3)
}
20% {
-webkit-transform: scale3d(1.1,1.1,1.1);
transform: scale3d(1.1,1.1,1.1)
}
40% {
-webkit-transform: scale3d(.9,.9,.9);
transform: scale3d(.9,.9,.9)
}
60% {
opacity: 1;
-webkit-transform: scale3d(1.03,1.03,1.03);
transform: scale3d(1.03,1.03,1.03)
}
80% {
-webkit-transform: scale3d(.97,.97,.97);
transform: scale3d(.97,.97,.97)
}
100% {
opacity: 1;
-webkit-transform: scale3d(1,1,1);
transform: scale3d(1,1,1)
}
}
.bounceIn {
-webkit-animation-name: bounceIn;
animation-name: bounceIn
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<section class="rating" data-rating="4">
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
</section>
<section class="rating" data-rating="0">
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
<svg class="icon icon-star-full">
<use xlink:href="#icon-star-full"></use>
</svg>
</section>
<svg class="svg-spritesheet">
<symbol id="icon-star-full" viewBox="0 0 32 32">
<title>star-full</title>
<path d="M32 12.408l-11.056-1.607-4.944-10.018-4.944 10.018-11.056 1.607 8 7.798-1.889 11.011 9.889-5.199 9.889 5.199-1.889-11.011 8-7.798z"></path>
</symbol>
</svg>
关于html - 选中前一个单选按钮的 CSS 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40596901/
是否有某种方法可以使用 JPA 或 Hibernate Crtiteria API 来表示这种 SQL?或者我应该将其作为 native 执行吗? SELECT A.X FROM (SELECT X,
在查询中, select id,name,feature,marks from (....) 我想删除其 id 在另一个 select 语句中存在的那些。 从 (...) 中选择 id 我是 sql
我想响应用户在 select 元素中选择一个项目。然而这个 jQuery: $('#platypusDropDown').select(function () { alert('You sel
这个问题在这里已经有了答案: SQL select only rows with max value on a column [duplicate] (27 个回答) 关闭8年前。 我正在学习 SQL
This question already has answers here: “Notice: Undefined variable”, “Notice: Undefined index”, and
我在 php 脚本中调用 SQL。有时“DE”中没有值,如果是这种情况我想从“EN”中获取值 应该是这样的,但不是这样的 IF (EXISTS (SELECT epf_application_deta
这可能是一个奇怪的问题,但不知道如何研究它。执行以下查询时: SELECT Foo.col1, Foo.col2, Foo.col3 FROM Foo INNER JOIN Bar ON
如何在使用 Camera.DestinationType.FILE_URI. 时在 phonegap camera API 中同时选择或拾取多个图像我能够一次只选择一张图像。我可以使用 this 在
这是一个纯粹的学术问题。这两个陈述实际上是否相同? IF EXISTS (SELECT TOP 1 1 FROM Table1) SELECT 1 ELSE SELECT 0 相对 IF EXIS
我使用 JSoup 来解析 HTML 响应。我有多个 Div 标签。我必须根据 ID 选择 Div 标签。 我的伪代码是这样的 Document divTag = Jsoup.connect(link
我正在处理一个具有多个选择框的表单。当用户从 selectbox1 中选择一个选项时,我需要 selectbox2 active 的另一个值。同样,当他选择 selectbox2 的另一个值时,我需要
Acme Inc. Christa Woods Charlotte Freeman Jeffrey Walton Ella Hubbard Se
我有一个login.html其中form定义如下: First Initial Plus Last Name : 我的do_authorize如下: "; pri
$.get( 'http://www.ufilme.ro/api/load/maron_online/470', function(data
我有一个下拉列表“磅”、“克”、“千克”和“盎司”。我想要这样一种情况,当我选择 gram 来执行一个函数时,当我在输入字段中输入一个值时,当我选择 pounds 时,我想要另一个函数来执行时我在输入
我有一个 GLSL 着色器,它从输入纹理的 channel 之一(例如 R)读取,然后写入输出纹理中的同一 channel 。该 channel 必须由用户选择。 我现在能想到的就是使用一个 int
我想根据下拉列表中的选定值生成输入文本框。 Options 2 3 4 5 就在这个选择框之后,一些输入字段应该按照选定的数字出现。 最佳答案 我建议您使用响应式(Reac
我是 SQL 新手,我想问一下如何根据首选项和分组选择条目。 +----------+----------+------+ | ENTRY_ID | ROUTE_ID | TYPE | +------
我有以下表结构: CREATE TABLE [dbo].[UTS_USERCLIENT_MAPPING_USER_LIST] ( [MAPPING_ID] [int] IDENTITY(1,1
我在移除不必要的床单时遇到了问题。我查看了不同的论坛并将不同的解决方案混合在一起。 此宏删除工作表(第一张工作表除外)。 Sub wrong() Dim sht As Object Applicati
我是一名优秀的程序员,十分优秀!