在输入类型=“无线电”中,如何更改DE样式并将标签置于居中?
我想设计一个调查类型组件,在该组件中,用户可以从1到5中选择一个选项,我正在使用无线电输入类型,我想给它一种自定义样式:
我希望输入显示为正方形(由于默认情况下它们是圆圈) 我希望标签在输入无线电广场内。
import React from 'react'
import './PreguntaCerradaEncuesta.css'
function PreguntaCerradaEncuesta({preguntaCerrada}) {
return (
<div className='contenedorPreguntaCerradaEncuesta'>
<div className='textoPreguntaCerradaEncuesta'> {preguntaCerrada} </div>
<div>
<label for="contactChoice1">
<input type="radio" id="cal1"
name="Calificacion" value='1' checked/> 1
</label>
<input type="radio" id="cal2"
name="Calificacion" value='2' checked/>
<label for="contactChoice1"> 2 </label>
<input type="radio" id="cal3"
name="Calificacion" value='3' checked/>
<label for="contactChoice1"> 3 </label>
<input type="radio" id="cal4"
name="Calificacion" value='4' checked/>
<label for="contactChoice1"> 4 </label>
<input type="radio" id="cal5"
name="Calificacion" value='5' checked/>
<label for="contactChoice1"> 5 </label>
</div>
</div>
)
}
export default PreguntaCerradaEncuesta
preguntacerradaencuesta.css
.contenedorPreguntaCerradaEncuesta{
display: flex;
flex-direction: column;
justify-content: flex-start ;
width: 60%;
height: 100%;
gap: 10px;
}
.textoPreguntaCerradaEncuesta{
font-size: 20px;
}
.contenedorPreguntaCerradaEncuesta label {
display: inline-block;
margin-right: 15px;
line-height: 32px;
}
.contenedorPreguntaCerradaEncuesta input {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border-radius: 100%;
width: 50px;
height: 50px;
background-color: #E5E5E5;
transition: 0.2s all linear;
position: relative;
}
.contenedorPreguntaCerradaEncuesta input:checked {
background-color: #1624DA;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须手动定位它。例如,
由于您的输入的大小为50px x 50px。找到其中的中心不应该太难了。
代码:
You would have to position it manually. For example,
Since your input is of size 50px x 50px. Finding the center of that shouldn't be too hard.
Code: https://codesandbox.io/s/condescending-leftpad-fennw5?file=/src/App.js:788-1007