简体   繁体   English

CSS:图例与字段集在同一行

[英]CSS: legend in the same row as fieldset

I've a stars rating system and I want to put some legend on it (so it is not only the stars icons). 我有一个星级评定系统,我想在上面加上一些图例(所以它不仅是星星图标)。

As I'm using Bootstrap4, I was thinking on using a row, and 2 cols to align them horizontally, however, my legend keeps getting some pixels above my stars. 当我使用Bootstrap4时,我正在考虑使用一行,并使用2个色点将它们水平对齐,但是,我的图例一直在星星上方得到一些像素。

I've also tried using margin-top: 10px on the legend, without the desired result. 我也尝试在图例上使用margin-top: 10px ,但没有理想的结果。

 @import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css); fieldset, label { margin: 0; padding: 0; } body { margin: 20px; } h1 { font-size: 1.5em; margin: 10px; } /****** Style Star Rating Widget *****/ .rating { border: none; float: left; } .rating > input { display: none; } .rating > label:before { margin: 5px; font-size: 1.25em; font-family: FontAwesome; display: inline-block; content: "\\f005"; } .rating > .half:before { content: "\\f089"; position: absolute; } .rating > label { color: #ddd; float: right; } /***** CSS Magic to Highlight Stars on Hover *****/ .rating > input:checked ~ label, /* show gold star when clicked */ .rating:not(:checked) > label:hover, /* hover current star */ .rating:not(:checked) > label:hover ~ label { color: #FFD700; } /* hover previous stars in list */ .rating > input:checked + label:hover, /* hover current star when changing rating */ .rating > input:checked ~ label:hover, .rating > label:hover ~ input:checked ~ label, /* lighten current selection */ .rating > input:checked ~ label:hover ~ label { color: #FFED85; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="row"> <div class="col-md-12 col-lg-12"> <fieldset class="rating hidden text-center"> <legend>Califícanos: </legend> <input type="radio" id="star5" name="rating" value="5"/><label class="full" for="star5" title="Awesome - 5 stars"></label> <input type="radio" id="star4half" name="rating" value="4.5"/><label class="half" for="star4half" title="Pretty good - 4.5 stars"></label> <input type="radio" id="star4" name="rating" value="4"/><label class="full" for="star4" title="Pretty good - 4 stars"></label> <input type="radio" id="star3half" name="rating" value="3.5"/><label class="half" for="star3half" title="Meh - 3.5 stars"></label> <input type="radio" id="star3" name="rating" value="3"/><label class="full" for="star3" title="Meh - 3 stars"></label> <input type="radio" id="star2half" name="rating" value="2.5"/><label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label> <input type="radio" id="star2" name="rating" value="2"/><label class="full" for="star2" title="Kinda bad - 2 stars"></label> <input type="radio" id="star1half" name="rating" value="1.5"/><label class="half" for="star1half" title="Meh - 1.5 stars"></label> <input type="radio" id="star1" name="rating" value="1"/><label class="full" for="star1" title="Sucks big time - 1 star"></label> <input type="radio" id="starhalf" name="rating" value="0.5"/><label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label> </fieldset> </div> </div> 

https://codepen.io/anon/pen/GevVYZ https://codepen.io/anon/pen/GevVYZ

在此处输入图片说明

I've also tried using span tag: 我也尝试使用span标签:

 @import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css); fieldset, label { margin: 0; padding: 0; } body { margin: 20px; } h1 { font-size: 1.5em; margin: 10px; } /****** Style Star Rating Widget *****/ .rating { border: none; float: left; } .rating > input { display: none; } .rating > label:before { margin: 5px; font-size: 1.25em; font-family: FontAwesome; display: inline-block; content: "\\f005"; } .rating > .half:before { content: "\\f089"; position: absolute; } .rating > label { color: #ddd; float: right; } /***** CSS Magic to Highlight Stars on Hover *****/ .rating > input:checked ~ label, /* show gold star when clicked */ .rating:not(:checked) > label:hover, /* hover current star */ .rating:not(:checked) > label:hover ~ label { color: #FFD700; } /* hover previous stars in list */ .rating > input:checked + label:hover, /* hover current star when changing rating */ .rating > input:checked ~ label:hover, .rating > label:hover ~ input:checked ~ label, /* lighten current selection */ .rating > input:checked ~ label:hover ~ label { color: #FFED85; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="row"> <div class="col-md-6 col-lg-6"> <span class="calificanos-text hidden">Califícanos: </span> </div> <div class="col-md-6 col-lg-6"> <fieldset class="rating hidden text-center"> <input type="radio" id="star5" name="rating" value="5"/><label class="full" for="star5" title="Awesome - 5 stars"></label> <input type="radio" id="star4half" name="rating" value="4.5"/><label class="half" for="star4half" title="Pretty good - 4.5 stars"></label> <input type="radio" id="star4" name="rating" value="4"/><label class="full" for="star4" title="Pretty good - 4 stars"></label> <input type="radio" id="star3half" name="rating" value="3.5"/><label class="half" for="star3half" title="Meh - 3.5 stars"></label> <input type="radio" id="star3" name="rating" value="3"/><label class="full" for="star3" title="Meh - 3 stars"></label> <input type="radio" id="star2half" name="rating" value="2.5"/><label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label> <input type="radio" id="star2" name="rating" value="2"/><label class="full" for="star2" title="Kinda bad - 2 stars"></label> <input type="radio" id="star1half" name="rating" value="1.5"/><label class="half" for="star1half" title="Meh - 1.5 stars"></label> <input type="radio" id="star1" name="rating" value="1"/><label class="full" for="star1" title="Sucks big time - 1 star"></label> <input type="radio" id="starhalf" name="rating" value="0.5"/><label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label> </fieldset> </div> </div> 

https://codepen.io/anon/pen/rRGBvB https://codepen.io/anon/pen/rRGBvB

This is what I see in my html (localhost): 这是我在html(localhost)中看到的:

What I see locally: 我在本地看到的是:

在此处输入图片说明

I wrapped them all in the div col6 and set them to display flex and then i removed the margin 5px in .rating > label:before 我将它们全部包装在div col6中,并设置为显示flex,然后在.rating> label:before中删除了5px的边距。

  @import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css); /* NEW */ .col-md-6.col-lg-6 { display: flex; } .rating > label:before { font-size: 1.25em; font-family: FontAwesome; display: inline-block; content: "\\f005"; } /* END */ fieldset, label { margin: 0; padding: 0; } body { margin: 20px; } h1 { font-size: 1.5em; margin: 10px; } /****** Style Star Rating Widget *****/ .rating { border: none; float: left; } .rating > input { display: none; } .rating > .half:before { content: "\\f089"; position: absolute; } .rating > label { color: #ddd; float: right; } /***** CSS Magic to Highlight Stars on Hover *****/ .rating > input:checked ~ label, /* show gold star when clicked */ .rating:not(:checked) > label:hover, /* hover current star */ .rating:not(:checked) > label:hover ~ label { color: #FFD700; } /* hover previous stars in list */ .rating > input:checked + label:hover, /* hover current star when changing rating */ .rating > input:checked ~ label:hover, .rating > label:hover ~ input:checked ~ label, /* lighten current selection */ .rating > input:checked ~ label:hover ~ label { color: #FFED85; } 
  <div class="row"> <div class="col-md-6 col-lg-6"> <span class="calificanos-text hidden">Califícanos: </span> <fieldset class="rating hidden text-center"> <input type="radio" id="star5" name="rating" value="5"/><label class="full" for="star5" title="Awesome - 5 stars"></label> <input type="radio" id="star4half" name="rating" value="4.5"/><label class="half" for="star4half" title="Pretty good - 4.5 stars"></label> <input type="radio" id="star4" name="rating" value="4"/><label class="full" for="star4" title="Pretty good - 4 stars"></label> <input type="radio" id="star3half" name="rating" value="3.5"/><label class="half" for="star3half" title="Meh - 3.5 stars"></label> <input type="radio" id="star3" name="rating" value="3"/><label class="full" for="star3" title="Meh - 3 stars"></label> <input type="radio" id="star2half" name="rating" value="2.5"/><label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label> <input type="radio" id="star2" name="rating" value="2"/><label class="full" for="star2" title="Kinda bad - 2 stars"></label> <input type="radio" id="star1half" name="rating" value="1.5"/><label class="half" for="star1half" title="Meh - 1.5 stars"></label> <input type="radio" id="star1" name="rating" value="1"/><label class="full" for="star1" title="Sucks big time - 1 star"></label> <input type="radio" id="starhalf" name="rating" value="0.5"/><label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label> </fieldset> </div> </div> 

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

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