【发布时间】:2021-06-20 07:38:31
【问题描述】:
我正在尝试创建一个评分表单 - 我正在努力让“提交”按钮与我的 CSS 星号“很好地”对齐。
理想情况下,我希望我的页面看起来像这样:
------------------------------------------------------------
| * * * * * Submit |
| |
|-----------------------------------------------------------
| |
| BOTTOM PART |
| |
------------------------------------------------------------
表单及其组件(即按钮和星星)的行为类似于一个内聚单元,并且可以作为一个组沿 X 和 Y 轴移动。
这是我迄今为止想出的:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<style>
.rate {
display: inline-block;
position: relative;
height: 20px;
line-height: 20px;
font-size: 20px;
}
.rate label {
position: absolute;
top: 0;
left: 0;
height: 100%;
cursor: pointer;
}
.rate label:last-child {
position: static;
}
.rate label:nth-child(1) {
z-index: 5;
}
.rate label:nth-child(2) {
z-index: 4;
}
.rate label:nth-child(3) {
z-index: 3;
}
.rate label:nth-child(4) {
z-index: 2;
}
.rate label:nth-child(5) {
z-index: 1;
}
.rate label input {
position: absolute;
top: 0;
left: 0;
opacity: 0;
}
.rate label .icon {
float: left;
color: transparent;
}
.rate label:last-child .icon {
color: #CACACA;
}
.rate:not(:hover) label input:checked ~ .icon,
.rate:hover label:hover input ~ .icon {
color: #ffd900;
}
.rate label input:focus:not(:checked) ~ .icon:last-child {
color: #000;
text-shadow: 0 0 5px #ffd900;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<form class="rate">
<label title="Poor">
<input type="radio" name="stars" value="1"/>
<span class="icon">★</span>
</label>
<label title="Below average">
<input type="radio" name="stars" value="2"/>
<span class="icon">★</span>
<span class="icon">★</span>
</label>
<label title="Average">
<input type="radio" name="stars" value="3"/>
<span class="icon">★</span>
<span class="icon">★</span>
<span class="icon">★</span>
</label>
<label title="Above average">
<input type="radio" name="stars" value="4"/>
<span class="icon">★</span>
<span class="icon">★</span>
<span class="icon">★</span>
<span class="icon">★</span>
</label>
<label title="Excellent">
<input type="radio" name="stars" value="5"/>
<span class="icon">★</span>
<span class="icon">★</span>
<span class="icon">★</span>
<span class="icon">★</span>
<span class="icon">★</span>
</label>
<!-- button class="btn-info btn btn-sm pull-right">Submit</button>-->
</form>
</div>
<div class="row">
Bottom part
</div>
</div>
</body>
</html>
如何修复标记/CSS 以便:
- 按钮正确定位在表单中星星的右侧
- 启动和按钮可以作为一个单元沿 X、Y 轴“移动” - 通过设置边距等。
【问题讨论】:
标签: html css twitter-bootstrap bootstrap-4