【问题标题】:How to style checkbox with attribute value="true"? [duplicate]如何使用属性 value="true" 设置复选框的样式? [复制]
【发布时间】:2021-10-21 17:34:15
【问题描述】:

我有一个具有value 属性的复选框。我想进行如下图所示的自定义检查。因此,当 value="true" 出现复选框时。我已经这样编码但无法工作,有人可以帮助我吗?

.faktur-checkbox[value="true"] ~ .custom-control-label::after{
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3e%3cpath fill='%23fff' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26l2.974 2.99L8 2.193z'/%3e%3c/svg%3e") !important;
    background: no-repeat 65%/65% 65%;
    top: 0;
}

.faktur-checkbox[value="true"] ~ .custom-control-label{
  color:red;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css" integrity="sha512-GQGU0fMMi238uA+a/bdWJfpUGKUkBdgfFdgBm72SUQ6BeyWjoY/ton0tEjH+OSH9iP4Dfh+7HM0I9f5eR0L/4w==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<div class="faktur-container checkbox-container">
     <input type="checkbox" class="custom-control-input faktur-checkbox" value="true" name="faktur">
     <label id="faktur-label" class="custom-control-label checkbox-label" for="faktur">Test</label>
</div>

【问题讨论】:

    标签: html css


    【解决方案1】:

    我创建了一个与您一样的自定义复选框,希望它对您有所帮助。 我更新了你的代码这是一个工作演示

    <!DOCTYPE html>
    <html>
    <head>
     
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css" integrity="sha512-GQGU0fMMi238uA+a/bdWJfpUGKUkBdgfFdgBm72SUQ6BeyWjoY/ton0tEjH+OSH9iP4Dfh+7HM0I9f5eR0L/4w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <style>
    /* This css is for normalizing styles. You can skip this. */
    *, *:before, *:after {
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }
    
    
    
    
    .new {
      padding: 50px;
    }
    
    .form-group {
      display: block;
      margin-bottom: 15px;
    }
    
    .form-group input {
      padding: 0;
      height: initial;
      width: initial;
      margin-bottom: 0;
      display: none;
      cursor: pointer;
    }
    
    .form-group label {
      position: relative;
      cursor: pointer;
    }
    
    .form-group label:before {
      content:'';
      -webkit-appearance: none;
      background-color: #df1717c9;
        border: 2px solid #bf0030;
      box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
      padding: 10px;
      display: inline-block;
      position: relative;
      vertical-align: middle;
      cursor: pointer;
      margin-right: 5px;
    }
    
    .form-group input:checked + label:after {
      content: '';
      display: block;
      position: absolute;
      top: 2px;
      left: 9px;
      width: 6px;
      height: 17px;
      border: solid #f5f9f9;
      border-width: 0 2px 2px 0;
      transform: rotate(45deg);
    }
    </style>
    </head>
    <body>
    
    <div class="new">
    <div class="form-group">
         <input type="checkbox" class="custom-control-input faktur-checkbox" value="true" id="faktur" name="faktur">
         <label for="faktur" id="faktur-label" class="custom-control-label checkbox-label">Test</label>
    </div>
    </div>
    
    </body>
    </html>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-15
      • 2013-06-09
      • 1970-01-01
      • 2015-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多