javascript - 将复选框定位在容器的右侧并垂直对齐
问题描述
我希望复选框的位置如下图所示:
请注意,复选框应放置在相同的垂直对齐位置。
.feedback {
background: rgb(242 237 241 / 90%);
position: absolute;
width: 90%;
height: 60%;
left: 5%;
top: 23%;
display: flex;
justify-content: center;
align-items: stretch;
box-shadow: 0px 2px 4px 4px #000000;
}
.feedback__form {
margin: auto;
padding: 20px;
}
.feedback__form h1 {
font-weight: 700;
margin-bottom: 15px;
}
button:active, :focus {
outline: none !important;
}
.btn {
background-position: center;
border: 0;
border-radius: 3px;
cursor: pointer;
font-family: "Inter", san-serif;
font-weight: 500;
min-width: 120px;
padding: 12px 10px;
margin-bottom: 5px;
white-space: nowrap;
transition: all 0.5s;
}
.btn--primary {
background-color: #7BC4CA;
color: #FFF;
box-shadow: 0px 3px 6px 0px rgba(123, 196, 202, 0.7);
}
.btn--primary:hover {
background: #70bfc6 radial-gradient(circle, transparent 1%, #70bfc6 1%) center/15000%;
}
.btn--primary:active {
background-color: #8dccd1;
background-size: 100%;
transition: background 0s;
}
.btn--secondary {
background-color: #E4E4E4;
color: #000;
box-shadow: 0px 3px 6px 0px rgba(228, 228, 228, 0.7);
}
.btn--secondary:hover {
background: gainsboro radial-gradient(circle, transparent 1%, gainsboro 1%) center/15000%;
}
.btn--secondary:active {
background-color: #f1f1f1;
background-size: 100%;
transition: background 0s;
}
.burmanRadio {
margin-bottom: 10px;
}
.burmanRadio__input {
display: none;
}
.burmanRadio__input:checked ~ .burmanRadio__label::after {
opacity: 1;
transform: scale(1);
}
.burmanRadio__label {
cursor: pointer;
line-height: 30px;
position: relative;
margin-right: 35px;
}
.burmanRadio__label::before, .burmanRadio__label::after {
border-radius: 50%;
position: absolute;
top: -1.5px;
right: -35px;
transition: all 0.3s ease-out;
z-index: 2;
}
.burmanRadio__label::before {
content: "";
border: 1.5px solid #E4E4E4;
width: 40px;
height: 40px;
}
.burmanRadio__label::after {
content: "";
background: #7ccc25;
border: 1.5px solid #7BC4CA;
color: #FFF;
font-family: "Material-Design-Iconic-Font";
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
width: 40px;
height: 40px;
transform: scale(0);
}
.burmanRadio__label:hover::before {
border-color: #7BC4CA;
}
<main class="feedback">
<article class="feedback__form">
<h1 class="feedback__question">We wish to know what put you off!</h1>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-1" name="burmanRadio" checked>
<label for="radio-1" class="burmanRadio__label">Solution was not clear/correct</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-2" name="burmanRadio">
<label for="radio-2" class="burmanRadio__label">Solution was not available</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-3" name="burmanRadio">
<label for="radio-3" class="burmanRadio__label">Price is too high</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-4" name="burmanRadio">
<label for="radio-4" class="burmanRadio__label">Not needed anymore</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-5" name="burmanRadio">
<label for="radio-5" class="burmanRadio__label">Other reasons</label>
</div>
</article>
</main>
解决方案
更改.burmanRadio__label
为具有 displayinline-block
而不是 default inline
,使其具有固定宽度250px
并设置text-align
为根据布局right
调整top
,和properties right
,您就完成了。也删除并使用,在大多数情况下会更好。width
height
height: 60%
min-height: 60%
.feedback {
background: rgb(242 237 241 / 90%);
position: absolute;
width: 90%;
min-height: 60%;
left: 5%;
top: 23%;
display: flex;
justify-content: center;
align-items: stretch;
box-shadow: 0px 2px 4px 4px #000000;
}
.feedback__form {
margin: auto;
padding: 20px;
}
.feedback__form h1 {
font-weight: 700;
margin-bottom: 15px;
}
.burmanRadio {
margin-bottom: 10px;
}
.burmanRadio__input {
display: none;
}
.burmanRadio__input:checked~.burmanRadio__label::after {
opacity: 1;
transform: scale(1);
}
.burmanRadio__label {
cursor: pointer;
line-height: 30px;
position: relative;
text-align: right;
margin-right: 35px;
display: inline-block;
width: 250px;
}
.burmanRadio__label::before,
.burmanRadio__label::after {
border-radius: 50%;
position: absolute;
top: 0px;
right: -45px;
transition: all 0.3s ease-out;
z-index: 2;
}
.burmanRadio__label::before {
content: "";
border: 1.5px solid #E4E4E4;
width: 30px;
height: 30px;
}
.burmanRadio__label::after {
content: "";
background: #7ccc25;
border: 1.5px solid #7BC4CA;
color: #FFF;
font-family: "Material-Design-Iconic-Font";
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
width: 30px;
height: 30px;
transform: scale(0);
}
.burmanRadio__label:hover::before {
border-color: #7BC4CA;
}
<main class="feedback">
<article class="feedback__form">
<h1 class="feedback__question">We wish to know what put you off!</h1>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-1" name="burmanRadio" checked>
<label for="radio-1" class="burmanRadio__label">Solution was not clear/correct</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-2" name="burmanRadio">
<label for="radio-2" class="burmanRadio__label">Solution was not available</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-3" name="burmanRadio">
<label for="radio-3" class="burmanRadio__label">Price is too high</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-4" name="burmanRadio">
<label for="radio-4" class="burmanRadio__label">Not needed anymore</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-5" name="burmanRadio">
<label for="radio-5" class="burmanRadio__label">Other reasons</label>
</div>
</article>
</main>
使用 flexbox 和 grid 会更好。
编辑:如果您需要将所有选项与图像上的右侧对齐,那么您可以将其包装到一个 div 中并正确对齐。
.feedback {
background: rgb(242 237 241 / 90%);
position: absolute;
width: 90%;
min-height: 60%;
left: 5%;
top: 23%;
display: flex;
justify-content: center;
align-items: stretch;
box-shadow: 0px 2px 4px 4px #000000;
}
.feedback__form {
padding: 20px;
width: 100%;
text-align: center;
}
.feedback__form h1 {
font-weight: 700;
margin-bottom: 15px;
}
button:active,
:focus {
outline: none !important;
}
.btn {
background-position: center;
border: 0;
border-radius: 3px;
cursor: pointer;
font-family: "Inter", san-serif;
font-weight: 500;
min-width: 120px;
padding: 12px 10px;
margin-bottom: 5px;
white-space: nowrap;
transition: all 0.5s;
}
.options {
text-align: right;
}
.burmanRadio {
margin-bottom: 10px;
}
.burmanRadio__input {
display: none;
}
.burmanRadio__input:checked~.burmanRadio__label::after {
opacity: 1;
transform: scale(1);
}
.burmanRadio__label {
cursor: pointer;
line-height: 30px;
position: relative;
text-align: right;
margin-right: 35px;
display: inline-block;
width: 250px;
}
.burmanRadio__label::before,
.burmanRadio__label::after {
border-radius: 50%;
position: absolute;
top: 0px;
right: -45px;
transition: all 0.3s ease-out;
z-index: 2;
}
.burmanRadio__label::before {
content: "";
border: 1.5px solid #E4E4E4;
width: 30px;
height: 30px;
}
.burmanRadio__label::after {
content: "";
background: #7ccc25;
border: 1.5px solid #7BC4CA;
color: #FFF;
font-family: "Material-Design-Iconic-Font";
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
width: 30px;
height: 30px;
transform: scale(0);
}
.burmanRadio__label:hover::before {
border-color: #7BC4CA;
}
<main class="feedback">
<article class="feedback__form">
<h1 class="feedback__question">We wish to know what put you off!</h1>
<div class="options">
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-1" name="burmanRadio" checked>
<label for="radio-1" class="burmanRadio__label">Solution was not clear/correct</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-2" name="burmanRadio">
<label for="radio-2" class="burmanRadio__label">Solution was not available</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-3" name="burmanRadio">
<label for="radio-3" class="burmanRadio__label">Price is too high</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-4" name="burmanRadio">
<label for="radio-4" class="burmanRadio__label">Not needed anymore</label>
</div>
<div class="burmanRadio">
<input type="radio" class="burmanRadio__input" id="radio-5" name="burmanRadio">
<label for="radio-5" class="burmanRadio__label">Other reasons</label>
</div>
</div>
</article>
</main>
在下次索要代码之前自己尝试一下。
推荐阅读
- c# - 在 p/invoke 打开的对话框上单击按钮
- bash - Bash脚本-如何在目录中的所有txt文件中逐个查找子字符串并为所有积极发现写一条消息
- redis - redis EVAL 真的是原子的并且是安全的吗?
- sql-server - 为什么我收到错误“无法删除数据库'test',因为它正在用于复制。错误:3724”?
- azure - 带有 Spring 配置文件的 Azure 连接字符串
- prolog - 按索引在列表中进行多次替换
- angular - Angular/Firestore 对文档中对象数组的值求和
- java - 识别文件中的某个字符并将其隐藏不被执行
- java - 有没有办法在 JAVA 中使用 Azure Cognitive Face API 比较同一个人的两个图像
- python - 如何使用随机生成游戏的不同字符串答案