覆盖默认的CSS样式

时间:2016-02-18 12:04:01

标签: html css

在“我的”模板中,我会覆盖单选按钮和标签的样式,如下所示:

[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;
}

现在我想将一个完整的其他样式应用于div中的单选按钮和标签,我试过这个:

.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>

我无法弄清楚为什么它没有覆盖并尝试了很多东西,例如链接到我的单选按钮的id(#age1),但没有任何作用。

谢谢。

1 个答案:

答案 0 :(得分:0)

在2个不同的CSS文件中,您有两种不同的风格吗?如果是这样,请确保其他样式样式表位于<head>代码中的第一个下方。

<head>

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

</head>