【问题标题】:Styling a Form.Check (checkbox) control in react bootstrap在反应引导程序中设置 Form.Check(复选框)控件的样式
【发布时间】:2020-02-08 23:37:48
【问题描述】:

我是 react 和 bootstrap 的初学者。我想知道 - 如何设置 Form.Check(复选框)的样式,以便可以用更好的样式覆盖默认外观。 (比如开关或任何其他外观)。

这是我尝试过的(我使用了 css 样式,但没有按预期工作):

MyForm.js

import React from 'react';
import { Row, Form, Col, Button, Container } from 'react-bootstrap';

class MyCustomClass extends React.Component {
  constructor(props) {
    super(props);

    render()
    {
      return (
        <div>
          <br />
          <h3>Page Title</h3>
          <Form>
            <Form.Group >
              <Form.Check
                type="Checkbox"
                label="Click me"              
              />
            </Form.Group>
          </Form>
        </div>
      )
    }
  }
}

MyForm.css

.form-inline {
    width: 100%;
  }

  .form-group {
    width: 90%;
  }

  .input-group {
    width: 90% !important;
  }

  .form-control {
    width: 67% !important;
  }

  //This makes no difference
  .form-control [type=checkbox] {
    width: 120px;
    height: 40px;
    background: #333;
    margin: 20px 60px;

    border-radius: 50px;
    position: relative;
  }

【问题讨论】:

    标签: javascript css reactjs react-bootstrap


    【解决方案1】:

    尝试将 CSS 样式更改为 .form-control [type=checkbox] 为 .form-check。这适用于我使用 &lt;Form.Check/&gt;

    【讨论】:

      【解决方案2】:

      这是我的 php 代码的转储,可以看看。

      /**
       * Checkbox Two
       */
      .checkboxOne {
          width: 120px;
          height: 40px;
          background: #333;
          margin: 20px 60px;
      
          border-radius: 50px;
          position: relative;
      }
      }
      
      /**
       * Create the line for the circle to move across
       */
      .checkboxOne:before {
          content: '';
          position: absolute;
          top: 19px;
          left: 14px;
          height: 2px;
          width: 90px;
          background: #111;
      }
      
      /**
       * Create the circle to click
       */
      .checkboxOne label {
          display: block;
          width: 22px;
          height: 22px;
          border-radius: 50%;
      
          transition: all .5s ease;
          cursor: pointer;
          position: absolute;
          top: 9px;
          z-index: 1;
          left: 12px;
          background: #ddd;
      }
      
      /**
       * Create the click event for the checkbox
       */
      .checkboxOne input[type=checkbox]:checked + label {
          left: 84px;
          background: #26ca28;
      }
      <section>
        <h3>Switch</h3>
          <div class='checkboxOne'>
              <input type='checkbox' value='1' id='checkboxOneInput' name='' />
              <label for='checkboxOneInput'></label>
          </div>
      </section>

      【讨论】:

        猜你喜欢
        • 2015-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-23
        • 2019-10-31
        • 2020-08-05
        • 2021-09-15
        相关资源
        最近更新 更多