在引导程序中响应创建功能区标题

时间:2015-06-15 11:36:42

标签: css twitter-bootstrap css3 twitter-bootstrap-3 css-shapes

我如何在bootstrap中创建一个功能区标题,我需要响应,最好的方法是如果这个标题分为两部分,我的意思是左右,功能区必须如下所示:

enter image description here

我的代码是:



 .ribbon {
   font-size: 16px !important;
   /* This ribbon is based on a 16px font side and a 24px vertical rhythm. I've used em's to position each element for scalability. If you want to use a different font size you may have to play with the position of the ribbon elements */
   width: 75%;
   position: relative;
   background-color: #fafafa;
   background-image: -moz-linear-gradient(top, #ffffff, #f2f2f2);
   background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#f2f2f2));
   background-image: -webkit-linear-gradient(top, #ffffff, #f2f2f2);
   background-image: -o-linear-gradient(top, #ffffff, #f2f2f2);
   background-image: linear-gradient(to bottom, #ffffff, #f2f2f2);
   background-repeat: repeat-x;
   filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#fff2f2f2', GradientType=0);
   border: 1px solid #d4d4d4;
   color: #fff;
   text-align: center;
   padding: 1em 2em;
   /* Adjust to suit */
   margin: 2em auto 3em;
   /* Based on 24px vertical rhythm. 48px bottom margin - normally 24 but the ribbon 'graphics' take up 24px themselves so we double it. */
 }
 .ribbon:before,
 .ribbon:after {
   content: "";
   position: absolute;
   display: block;
   bottom: -1em;
   border: 1.5em solid #f2f2f2;
   /*side ribbons*/
   z-index: -1;
 }
 .ribbon:before {
   left: -2em;
   border-right-width: 1.5em;
   border-left-color: transparent;
 }
 .ribbon:after {
   right: -2em;
   border-left-width: 1.5em;
   border-right-color: transparent;
 }
 .ribbon .ribbon-content:before,
 .ribbon .ribbon-content:after {
   content: "";
   position: absolute;
   display: block;
   border-style: solid;
   border-color: #e2e2e2 transparent transparent transparent;
   bottom: -1em;
 }
 .ribbon .ribbon-content:before {
   left: 0;
   border-width: 1em 0 0 1em;
 }
 .ribbon .ribbon-content:after {
   right: 0;
   border-width: 1em 1em 0 0;
 }

<div class="navbar ribbon">
  <div class="navbar-inner ribbon-content">
    <div class="container">
      <ul class="nav">
        <li class="active"><a href="#">Home</a>
        </li>
        <li><a href="#">Projects</a>
        </li>
        <li><a href="#">Services</a>
        </li>
        <li><a href="#">Downloads</a>
        </li>
        <li><a href="#">About</a>
        </li>
        <li><a href="#">Contact</a>
        </li>
      </ul>
    </div>
  </div>
</div>
<!-- /.navbar -->
&#13;
&#13;
&#13;

谢谢

2 个答案:

答案 0 :(得分:3)

我使用伪元素和css三角形快速完成了这个。也许它可以激励你

body {
  background-color: white;
}
header {
  position: relative;
  background-color: blue;
  color: white;
  text-align: center;
  width: 95%;
  height: 40px;
}
header::before,
header::after {
  content: '';
  display: block;
  position: absolute;
}
header::before {
  height: 40px;
  width: 50px;
  right: -30px;
  top: 4px;
  background-color: darkblue;
  z-index: -1;
}
header::after {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 20px 20px 20px 0;
  border-color: transparent white transparent transparent;
  right: -30px;
  top: 4px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
  <div class="col-xs-12 header">
    <header>
      <h1>Header</h1>
    </header>
  </div>
</div>

答案 1 :(得分:1)

为了实现这一目标,您需要使用一些元素(包括伪)来创建一些形状:

.wrapper {
  margin: 0 auto;
  height: 400px;
  width: 400px;
  background: lightgray;
  position: relative;
  /*needed*/
}
.banner {
  position: absolute;
  top: 5px;
  left: 0;
  width: 105%;
  height: 20%;
  background: cornflowerblue;
}
.banner:before {
  content: "";
  position: absolute;
  height: 100%;
  right: 0;
  width: 5%;
  top: 0;
  transform: skewY(-20deg);
  transform-origin: top right;
  background: blue;
  z-index: -1;
}
.banner:after {
  content: "";
  position: absolute;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  height: 90%;
  width: 100%;
  border: 2px dashed black;
  border-left: none;
  border-right: none;
  top: 5%;
  left: 0;
}
.banner span {
  position: absolute;
  top: 10%;
  left: 100%;
  height: 50%;
  width: 10%;
  background: tomato;
  z-index: -2;
}
.banner span:before {
  content: "";
  position: absolute;
  top: 100%;
  left: -150%;
  height: 100%;
  width: 300%;
  background: red;
  transform: skewX(45deg);
  z-index: -2;
}
.banner span:after {
  content: "";
  position: absolute;
  top: 0;
  left: -150%;
  height: 100%;
  width: 300%;
  background: red;
  transform: skewX(-45deg);
  z-index: -2;
}
<div class="wrapper">
  <div class="banner">
    <span></span>
  </div>
</div>