html - 响应式倾斜标签

标签 html css twitter-bootstrap-3

我正在尝试创建类似于下图所示的倾斜标签: enter image description here

但我面临以下问题:

  • 标签没有占据整个容器的宽度
  • 选项卡在其他视口(viewport)(平板电脑和移动设备)上分成不同的行。

这是我到目前为止使用的代码,

.slant-tabs {
  border: solid 2px black;
}

.slant-tabs li {
  float: left;
  background: #cccccc;
  padding-bottom: 0px
}

.slant-tabs li:not(:first-child) a:before {
  content: '';
  position: absolute;
  border: 20px solid #cccccc;
  border-left-color: transparent;
  border-top-color: transparent;
  right: 100%;
  top: 0;
}

.slant-tabs li:not(:last-child) {
  margin-right: 45px;
}

.slant-tabs li:not(:last-child) a:after {
  content: '';
  position: absolute;
  border: 20px solid #cccccc;
  border-right-color: transparent;
  border-bottom-color: transparent;
  left: 100%;
  top: 0;
}

.slant-tabs li a {
  text-decoration: none;
  line-height: 40px;
  padding: 0 8px !important;
}

.slant-tabs li a:hover {
  background-color: #cccccc;
}

.slant-tabs li.active a {
  background-color: #cccccc;
  color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="slant-tabs">
    <ul class="nav">
      <li class="active">
        <a href="#description" data-toggle="tab">
          <span>Description</span>
        </a>
      </li>
      <li>
        <a href="#specification" data-toggle="tab">
          <span>Specification</span>

        </a>
      </li>
      <li>
        <a href="#avail" data-toggle="tab">
          <span>Availacoes</span>
        </a>
      </li>
    </ul>

    <div class="tab-content clearfix">
      <div class="tab-pane active" id="description">
        <h3>Content's background color is the same for the tab</h3>
      </div>
      <div class="tab-pane" id="specification">
        <h3>We use the class nav-pills instead of nav-tabs which automatically creates a background color for the tab
        </h3>
      </div>
      <div class="tab-pane" id="avail">
        <h3>We applied clearfix to the tab-content to rid of the gap between the tab and the content</h3>
      </div>
    </div>
  </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

请我解决以上问题

最佳答案

Flex 确实是可行的方法(display:table/table-cell for older browsers)

对于斜 Angular ,您可以使用边框或线性背景渐变。

.slant-tabs {
  border: solid 2px black;
}

.nav {
  display: flex;
  overflow: hidden;
}

.slant-tabs li {
  flex: 1;
  position: relative;
  float: left;
  background: #cccccc;
  padding-bottom: 0px
}

a:before,
a:after {
  height: 45px;
  width: 45px;
  z-index: 0;
}

.slant-tabs li a:before {
  content: '';
  position: absolute;
  right: 100%;
  top: 0;
  background: linear-gradient(-45deg, #ccc calc(50% - 2px), transparent calc(50% - 2px));
}

.slant-tabs li:not(:last-child) {
  margin-right: 45px;
}

.slant-tabs li a:after {
  content: '';
  position: absolute;
  left: 100%;
  top: 0;
  background: linear-gradient( 135deg, #ccc calc(50% - 2px), transparent calc(50% - 2px));
  z-index: 1
}

.slant-tabs li a {
  text-decoration: none;
  line-height: 40px;
  padding: 0 8px !important;
}

.slant-tabs li a:hover {
  background-color: #cccccc;
  color: gray!important
}

.slant-tabs li a:hover:before {
  background: linear-gradient( -45deg, #f2f2f2 calc(50% - 2px), transparent calc(50% - 2px));
}

.slant-tabs li a:hover:after {
  background: linear-gradient( 135deg, #f2f2f2 calc(50% - 2px), transparent calc(50% - 2px));
}

.slant-tabs li.active a {
  background-color: #cccccc;
  color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="slant-tabs">
    <ul class="nav">
      <li class="active">
        <a href="#description" data-toggle="tab">
          <span>Description</span>
        </a>
      </li>
      <li>
        <a href="#specification" data-toggle="tab">
          <span>Specification</span>

        </a>
      </li>
      <li>
        <a href="#avail" data-toggle="tab">
          <span>Availacoes</span>
        </a>
      </li>
    </ul>

    <div class="tab-content clearfix">
      <div class="tab-pane active" id="description">
        <h3>Content's background color is the same for the tab</h3>
      </div>
      <div class="tab-pane" id="specification">
        <h3>We use the class nav-pills instead of nav-tabs which automatically creates a background color for the tab
        </h3>
      </div>
      <div class="tab-pane" id="avail">
        <h3>We applied clearfix to the tab-content to rid of the gap between the tab and the content</h3>
      </div>
    </div>
  </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

关于html - 响应式倾斜标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43307061/

相关文章:

html - 悬停时出现的文本,在转换完成后消失

css - 如何将 mixin 添加到 Stylus 中的 sprintf 函数?

javascript - 如何让div在轮播上滚动 Bootstrap

css - Bootstrap 3 导航栏对齐问题

javascript - Freemarker 中的多语言自动转义

javascript - 如果满足条件,使用 JQuery 添加指向元素的链接

javascript - HTML 和 CSS : same height two div in div

html - 如何使分离器远离天然药丸

javascript - 如何防止 Quill 在顶部边距为 10px 的标题前插入空白段落 (`<p><br></p>` )?

html - CSS如何翻译其中包含全部内容的DIV