简体   繁体   中英

override default css style

In "my" template I override the style of radio buttons and labels like this:

[type="radio"]:not(:checked),
[type="radio"]:checked {
  position: absolute;
  left: -9999px;
  visibility: hidden;
}

[type="radio"]:not(:checked) + label,
[type="radio"]:checked + label {
  position: relative;
  padding-left: 35px;
  cursor: pointer;
  display: inline-block;
  height: 25px;
  line-height: 25px;
  font-size: 1rem;
  transition: .28s ease;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}

[type="radio"] + label:before,
[type="radio"] + label:after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  margin: 4px;
  width: 16px;
  height: 16px;
  z-index: 0;
  transition: .28s ease;
}

/* Unchecked styles */
[type="radio"]:not(:checked) + label:before {
  border-radius: 50%;
  border: 2px solid #5a5a5a;
}

[type="radio"]:not(:checked) + label:after {
  border-radius: 50%;
  border: 2px solid #5a5a5a;
  z-index: -1;
  -webkit-transform: scale(0);
          transform: scale(0);
}

/* Checked styles */
[type="radio"]:checked + label:before {
  border-radius: 50%;
  border: 2px solid transparent;
}

[type="radio"]:checked + label:after {
  border-radius: 50%;
  border: 2px solid #8bc34a;
  background-color: #8bc34a;
  z-index: 0;
  -webkit-transform: scale(1.02);
          transform: scale(1.02);
}

/* Radio With gap */
[type="radio"].with-gap:checked + label:before {
  border-radius: 50%;
  border: 2px solid #8bc34a;
}

[type="radio"].with-gap:checked + label:after {
  border-radius: 50%;
  border: 2px solid #8bc34a;
  background-color: #8bc34a;
  z-index: 0;
  -webkit-transform: scale(0.5);
          transform: scale(0.5);
}

/* Disabled Radio With gap */
[type="radio"].with-gap:disabled:checked + label:before {
  border: 2px solid rgba(0, 0, 0, 0.26);
}

[type="radio"].with-gap:disabled:checked + label:after {
  border: none;
  background-color: rgba(0, 0, 0, 0.26);
}

/* Disabled style */
[type="radio"]:disabled:not(:checked) + label:before,
[type="radio"]:disabled:checked + label:before {
  background-color: transparent;
  border-color: rgba(0, 0, 0, 0.26);
}

[type="radio"]:disabled + label {
  color: rgba(0, 0, 0, 0.26);
}

[type="radio"]:disabled:not(:checked) + label:before {
  border-color: rgba(0, 0, 0, 0.26);
}

[type="radio"]:disabled:checked + label:after {
  background-color: rgba(0, 0, 0, 0.26);
  border-color: #BDBDBD;
}

Now I want to apply a complete other style to radio buttons and labels in a div and I've tried this:

.cc-selector-2 input[type="radio"] {
    position: absolute;
    z-index: 999;
    display: none !important; /* hide the radio button */
}

.cc-selector-2 input:active +.drinkcard-cc, .cc-selector input:active +.drinkcard-cc { opacity: .9; }
.cc-selector-2 input:checked +.drinkcard-cc, .cc-selector input:checked +.drinkcard-cc { 
    -webkit-filter: none;
       -moz-filter: none;
            filter: none;
}

<div class="cc-selector-2">
                @Html.RadioButtonFor(model => model.Age, "Age", new { id = "age1", @value = "shakegender", @name = "radio" })
                <label class="drinkcard-cc m" id="age1" for="age1"></label>
            </div>

I can't figur it out why it's not overriding and tried many things like linking to the id (#age1) of my radio button but nothing works.

Thank you.

Do you have the two different styles within 2 different CSS files? If so, ensure that the additional styling style sheet is below the first in your <head> tag.

<head>

<link rel="stylesheet" type="text/css" href="css/NewDefaultRadio.css"  /> 
<link rel="stylesheet" type="text/css" href="css/AddiotionalRadioStyles.css"  /> 

</head>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM