html - 将鼠标悬停在元素上时删除边框

标签 html css

我希望在将鼠标悬停在每个元素上时删除红色边框。

jsFiddle可以看出我附在这里。它只对左侧的第一个 div 有效,对右侧的其余 div 也有效。

我这样做的原因是因为我希望它具有灵 active ,以便我可以在不影响 CSS 部分的情况下在 HTML 上添加或删除。

.wrapper {
  height: 100px;
  display: flex;
  background-color: lightblue;
}
.item {
  background-color: lightgreen;
  flex: 0 0 15%;
}
.item-left + .item-right {
  margin-left: auto;
}
.item-left{
	border-left:1px solid red;
}
.item-left:first-of-type{
	border:none;
}
.item-left:last-of-type{
	border-right:1px solid red;
}
.item-right{
	border-left:1px solid red;
}
.item:hover{
	/* box-shadow: x y blur spread color; */
	box-shadow:0px 0px 0px -1px rgba(0, 0, 0, 0.2), 0px 0px 10px 0px rgba(0, 0, 0, 0.19);
	z-index:1;
}
.item:hover + .item.item-left, .item.item-right {
    border:none;
}
<div id="bottom" class="bottom">
  <div class="wrapper">
    <a class="item item-left">
      <div class="item-label">Left</div>
    </a>
    <a class="item item-left">
      <div class="item-label">Left</div>
    </a>
    <a class="item item-left">
      <div class="item-label">Left</div>
    </a>
    <a class="item item-right">
      <div class="item-label">Right</div>
    </a>
    <a class="item item-right">
      <div class="item-label">Right</div>
    </a>
    <a class="item item-right">
      <div class="item-label">Right</div>
    </a>
  </div>
</div>

感谢您的帮助!

最佳答案

在你的 CSS 中使用它

.item:hover{
  border:none;
}

.wrapper {
  height: 100px;
  display: flex;
  background-color: lightblue;
}
.item {
  background-color: lightgreen;
  flex: 0 0 15%;
}
.item-left + .item-right {
  margin-left: auto;
}
.item-left{
	border-left:1px solid red;
}
.item-left:first-of-type{
	border:none;
}
/*.item-left:last-of-type{
	border-right:1px solid red;
}*/

.last-left{
	border-right:1px solid red;
}

.item-right{
	border-left:1px solid red;
}
.item:hover{
	/* box-shadow: x y blur spread color; */
	box-shadow:0px 0px 0px -1px rgba(0, 0, 0, 0.2), 0px 0px 10px 0px rgba(0, 0, 0, 0.19);
	z-index:1;
}
.item:hover + .item.item-left, .item.item-right, .item:hover {
    border:none;
}
<div id="bottom" class="bottom">
  <div class="wrapper">
    <a class="item item-left">
      <div class="item-label">Left</div>
    </a>
    <a class="item item-left">
      <div class="item-label">Left</div>
    </a>
    <a class="item item-left last-left">
      <div class="item-label">Left</div>
    </a>
    <a class="item item-right">
      <div class="item-label">Right</div>
    </a>
    <a class="item item-right">
      <div class="item-label">Right</div>
    </a>
    <a class="item item-right">
      <div class="item-label">Right</div>
    </a>
  </div>
</div>

关于html - 将鼠标悬停在元素上时删除边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56783690/

相关文章:

html - IE9 中的选择框自定义

javascript - 使用 Javascript 更改 PHP 中元素的样式

html - :target not working on previous element

vba - 通过 VBA 填写网络表单

javascript - JQuery UI 工具提示 - 调用 ajax 后不透明度被破坏。

html - 面对 IE8 和 Firefox 复选框文本的对齐问题

html - IE11风格的背景颜色

javascript - 将元素值与当前日期进行比较

html - 为我的内容添加 CSS 边框、阴影和圆 Angular 的最简单方法

html - 一个列表,简单的向左浮动,不同的单元格大小