javascript - 当 SCSS 中并排有多个 div 时,Outline 不会完全包裹 div

标签 javascript html css sass

我有四个 div(选项卡),我正在尝试向选项卡添加轮廓,但轮廓并没有包裹整个 div。我认为选项卡上的边框导致了它。向 div 添加轮廓的正确方法是什么? 代码如下:

HTML:

<div class="main-style">Random</div>
<div class="styling active1">Btn 1</div>
<div class="styling active2">Btn 2</div>
<div class="styling active3">Btn 3</div>

CSS:

.main-style,.styling {
  background-color: blue;
  color: white;
  line-height: 36px;
  float: left;
  padding: 0 20px;
  display: inline-block;
  &:hover{
    cursor: pointer;
  }
}

.styling {
    border-width: 0px 0px 0px 1px;
    border-style: solid;
 }

.over {
  outline: 3px solid orange;
}

JS:

$('.active1').addClass('over'); // the outline doesn't wrap the whole button.
//$('.active3').addClass('over'); the outline wraps the whole button

这是 JS fiddle

最佳答案

它被下一个标签隐藏了。将 position: relativez-index: 1 添加到 .over 选项卡,使其显示在下一个选项卡上方:

$('.active1').addClass('over'); // the outline doesn't wrap the whole button.
.main-style,
.styling {
  background-color: blue;
  color: white;
  line-height: 36px;
  float: left;
  padding: 0 20px;
  display: inline-block;
  &:hover {
    cursor: pointer;
  }
}

.styling {
  border-width: 0px 0px 0px 1px;
}

.styling:not(:first-child) {
  margin-left: 3px;
}

.over {
  position: relative;
  z-index: 1;
  outline: 3px solid orange;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="main-style">Random</div>
<div class="styling active1">Btn 1</div>
<div class="styling active2">Btn 2</div>
<div class="styling active3">Btn 3</div>

关于javascript - 当 SCSS 中并排有多个 div 时,Outline 不会完全包裹 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51527707/

相关文章:

javascript - 为什么 Plunker 使用 AngularJS 时会出现 404 错误?

jquery - 在不使用 <form> 的情况下通过页面刷新发布值?

css - 在 CSS 中对 RGB 颜色值使用十六进制而不是十进制有什么好的理由吗?

html - 在 div 之间添加链接时的 css 垂直空白

html - 有没有CSS生成器

JavaScript 这是未定义的。这应该是全局对象

javascript - 确定子 div 是否有内容

Javascript选择标签内的内容

HTML 表格列宽实践

javascript - img onload 函数有时未定义