html - 在 html/css 中创建选项卡,以便边框在事件选项卡下方消失

标签 html css

我正在尝试创建标签,其中沿着内容有一个顶部边框,然后事件标签以这样一种方式重叠,即它与内容之间没有边框。

我尝试过使用负边距进行游戏,但它不起作用。我想在不使用 position:absolute 的情况下执行此操作

http://jsfiddle.net/Py8BW/3/ (我使用的是绿色和红色,但它们在最终结果中的颜色相同。)

<div class = "tab">inactive</div>
<div class = "tab tab_active">active</div>

<div class = "content"> 
</div>

.

.tab{
  width:70px  ;
     display:inline-block;
    background:green;
    height:50px;  
    // margin-bottom:-2px; /* makes both tabs look active */
}

.tab_active{
     margin-bottom:-2px; /* does nothing */
}

.content{
    border-top:2px solid black;
    width:200px ;
    background:red;
    height:200px;
}

最佳答案

另一个解决方案是添加 border-bottom在相同的颜色和margin-bottom上课.tab_active .

.tab_active{
    margin-bottom: -2px;
    border-bottom: 2px solid red;
}

.tab {
  width: 70px;
  display: inline-block;
  background: red;
  height: 50px;
  /* margin-bottom: -2px; makes both tabs look active */
}

.tab.active {
  margin-bottom: -2px;
  border-bottom: 2px solid red;
}

.content {
  border-top: 2px solid black;
  width: 200px;
  background: red;
  height: 200px;
}
<div class="tab">inactive</div>
<div class="tab active">active</div>
<div class="content"></div>

关于html - 在 html/css 中创建选项卡,以便边框在事件选项卡下方消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24823825/

相关文章:

jquery - 当使用 jquery .hover() 移动相对定位的 float div 时,如何解决 IE6/IE7 边距消失的问题?

javascript - 如何使用 css 降低 <span> 内容区域的高度?

javascript - 通过Ajax加载Div时,有时点击不起作用

html - 增加 Bootstrap 导航栏搜索表单宽度

css - 如何在哈巴狗的表格列上添加鼠标悬停?

css - 如何将无序列表堆叠成 2 个单独的行

javascript - 如何使用 Chrome.Storage?

php - Heroku 上带有 PHP 操作的 HTML5 表单

css - Skeleton CSS - 隐藏手机内容

html - 宝丽来照片/专栏在 Firefox 中无法正确显示