【发布时间】:2016-04-02 21:51:56
【问题描述】:
这是我的问题。我希望拥有一个图标(搜索图标、日历图标等)的input-group-addon 通过特异性继承其输入字段的悬停、焦点和活动状态。我让它为悬停工作,但由于某种原因,特异性忽略了焦点状态。我认为这是我的代码中的一个冲突的 css 指令,但我在 CODEPEN 中隔离了这个问题,它也在那里。
总之,我希望输入组插件边框在我关注它(选项卡或单击)时与其输入字段无缝更改为黄色,就像我将鼠标悬停在它上面一样。
我的 HTML:
<div class="input-group controls">
<input type="text" class="form-control" placeholder="Search by Name" />
<span class="input-group-addon right search"></span>
</div>
我的 CSS(如果可能,请使用 Chrome。我没有在此处包含 corssbrowser 的内容以使其更易于阅读)此外,这最初是基于 SCSS 构建的:
.mar40 {
margin: 40px auto;
}
.form-control {
border-width: 2px;
border-color: #8f8f8f;
-webkit-box-shadow: none;
box-shadow: none;
color: #bbbbbb;
-webkit-border-radius: 34px;
-moz-border-radius: 34px;
-ms-border-radius: 34px;
border-radius: 34px;
background: #211E1E;
}
.form-control:focus,
.form-control:hover {
border-color: rgba(248, 151, 29, 0.77);
-webkit-box-shadow: none;
box-shadow: none;
outline: none;
transition: all 1s ease;
}
.form-control .input-group-addon {
background: #8f8f8f;
border-color: #555555;
border-width: 2px;
}
.controls .input-group-addon.right.search {
background: #30373e;
border: 2px solid #8f8f8f;
color: #bbbbbb;
border-left: none;
border-radius: 0px 20px 20px 0;
padding: 4px 10px;
min-width: 0;
}
.controls .input-group-addon.right.search:before {
content: "\f4a4";
font-family: 'Ionicons';
font-size: 16px;
}
.controls:focus .input-group-addon.right,
.controls:hover .input-group-addon.right,
.controls:active .input-group-addon.right {
border: 2px solid rgba(248, 151, 29, 0.77) !important;
border-left: none !important;
transition: all 1s ease;
}
.controls:focus .input-group-addon.right:before,
.controls:hover .input-group-addon.right:before,
.controls:active .input-group-addon.right:before {
color: rgba(248, 151, 29, 0.77);
transition: all 1s ease;
}
还有方便的花花公子CODEPEN
谢谢!
【问题讨论】:
-
:focus和:hover具有相同的特异性。我无法重现您的现场演示的问题。 -
嗯。真的吗?这很奇怪。你用的是铬。也许这是一个浏览器的事情。而且我总是虽然焦点和悬停也具有相同的特异性,但我想不出任何其他原因为什么它不会为我做这件事。顺便说一句,我添加了一张我正在做的事情的照片