在输入类型=“无线电”中,如何更改DE样式并将标签置于居中?

发布于 2025-01-28 00:01:06 字数 2091 浏览 2 评论 0 原文

我想设计一个调查类型组件,在该组件中,用户可以从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;
  }

I want to design a survey type component, in which the user can choose an option from 1 to 5, I am using the radio input type, and I want to give it a custom style:

I want the inputs to be displayed as squares (since by default they appear as circles)
and I want the label to be inside the input radio square.

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罗罗贝儿 2025-02-04 00:01:06

您必须手动定位它。例如,

      <span
        style={{
          position: "relative",
          left: "-32px",
          top: "-22px",
          fontSize: "15px"
        }}
      >
        2
      </span>

由于您的输入的大小为50px x 50px。找到其中的中心不应该太难了。

代码:

You would have to position it manually. For example,

      <span
        style={{
          position: "relative",
          left: "-32px",
          top: "-22px",
          fontSize: "15px"
        }}
      >
        2
      </span>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文