html - 覆盖默认的 css 样式

标签 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),但没有任何效果。

谢谢。

最佳答案

您是否在 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>

关于html - 覆盖默认的 css 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35480994/

相关文章:

php - 简单的联系表格不起作用

css - 使用 CSS 悬停时动画触发的动画

ios - 如何在 Safari Web 检查器中切换元素状态?

css - 在 Firefox 中删除范围输入中的虚线

javascript - 如何使用 CSS/Javascript 从存储的文本中删除一行文本或一定数量的单词/字符?

html - Bootstrap 4 网格 - .col-断点与 .col-number

html - 如何制作 HTML 导航栏

html - 使一个 div 可点击但有另一个 div 出现在它上面

html - 边框框未按预期工作

asp.net - 在 html 和 css 中隐藏水平滚动条?