-1

I have a checkbox that has an attribute value. I want to give a custom check like the image below. So when value="true" then the checkbox appears. I've coded like this but cannot work, can anyone help me?

enter image description here

.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>
frankfurt
  • 107
  • 1
  • 2
  • 17

1 Answers1

0

I Create a custom checkbox same as you want to hope it will helpful for you. i updated your code Here is a working demo

<!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>
Neeraj
  • 732
  • 6
  • 14