【问题标题】:How make triangle div with css [duplicate]如何用css制作三角形div [重复]
【发布时间】:2016-06-16 15:40:04
【问题描述】:

如何使用 css 实现下图中的效果 父 div 与 div 与三角形 egde 如下图所示。如果我可以用 JS 实现这一点,我也愿意接受任何好主意

【问题讨论】:

    标签: html css breadcrumbs


    【解决方案1】:

    * {
      margin: 0;
    }
    a {
      color: #333;
      text-decoration: none;
    }
    nav {
      background: #eee;
      overflow: hidden;
    }
    nav li {
      display: inline-block;
      vertical-align: top;
      position: relative;
    }
    nav li:after {
      content: " ";
      position: absolute;
      right: 0;
      top: 0;
      bottom: 0;
      width: 40px;
      transform: rotate(45deg);
      background: #999;
    }
    nav a {
      display: block;
      padding: 14px 20px;
      position: relative;
      z-index: 1;
    }
    nav li a:before {
      content: " ";
      position: absolute;
      right: 3px;
      top: 0;
      bottom: 0;
      width: 40px;
      transform: rotate(45deg);
      background: #eee;
      z-index: -1;
    }
    <nav>
      <ul>
        <li><a href="">Jewelry and watches</a>
        </li>
        <li><a href="">watches</a>
        </li>
        <li><a href="">Jewelry</a>
        </li>
        <li><a href="">Wrist watches</a>
        </li>
      </ul>
    </nav>

    或者您甚至可以通过使用一个 psudo 元素并使用边框属性来简化它

    * {
      margin: 0;
    }
    a {
      color: #333;
      text-decoration: none;
    }
    nav {
      background: #eee;
      overflow: hidden;
      box-shadow: 0px 0px 3px 2px rgba(0,0,0,0.25);
      margin: 15px;
    }
    nav li {
      display: inline-block;
      vertical-align: top;
      position: relative;
    }
    nav li:after {
        content: " ";
        position: absolute;
        right: 0px;
        top: -1px;
        bottom: 0;
        width: 30px;
        transform: rotate(45deg);
        background: transparent;
        height: 30px;
        border-right: 1px solid #999;
        border-top: 1px solid #999;
    }
    nav a {
      display: block;
      padding: 5px 20px;
      position: relative;
      z-index: 1;
    }
    <nav>
      <ul>
        <li><a href="">Jewelry and watches</a>
        </li>
        <li><a href="">watches</a>
        </li>
        <li><a href="">Jewelry</a>
        </li>
        <li><a href="">Wrist watches</a>
        </li>
      </ul>
    </nav>

    【讨论】:

    【解决方案2】:

    试试这个

    HTML

    <ul class="breadcrumb">
        <li><a href="#">Home</a></li>
        <li><a href="#">Vehicles</a></li>
        <li><a href="#">Vans</a></li>
        <li><a href="#">Camper Vans</a></li>
        <li><a href="#">1989 VW Westfalia Vanagon</a></li>
    </ul>
    

    CSS

    .breadcrumb { 
        list-style: none; 
        overflow: hidden; 
        font: 18px Helvetica, Arial, Sans-Serif;
    }
    .breadcrumb li { 
        float: left; 
    }
    .breadcrumb li a {
        color: white;
        text-decoration: none; 
        padding: 10px 0 10px 65px;
        background: brown;                   /* fallback color */
        background: hsla(34,85%,35%,1); 
        position: relative; 
        display: block;
        float: left;
    }
    .breadcrumb li a:after { 
        content: " "; 
        display: block; 
        width: 0; 
        height: 0;
        border-top: 50px solid transparent;           /* Go big on the size, and let overflow hide */
        border-bottom: 50px solid transparent;
        border-left: 30px solid hsla(34,85%,35%,1);
        position: absolute;
        top: 50%;
        margin-top: -50px; 
        left: 100%;
        z-index: 2; 
    }
    .breadcrumb li a:before { 
        content: " "; 
        display: block; 
        width: 0; 
        height: 0;
        border-top: 50px solid transparent;       
        border-bottom: 50px solid transparent;
        border-left: 30px solid white;
        position: absolute;
        top: 50%;
        margin-top: -50px; 
        margin-left: 1px;
        left: 100%;
        z-index: 1; 
    }
    .breadcrumb li:first-child a {
        padding-left: 10px;
    }
    .breadcrumb li:nth-child(2) a       { background:        hsla(34,85%,45%,1); }
    .breadcrumb li:nth-child(2) a:after { border-left-color: hsla(34,85%,45%,1); }
    .breadcrumb li:nth-child(3) a       { background:        hsla(34,85%,55%,1); }
    .breadcrumb li:nth-child(3) a:after { border-left-color: hsla(34,85%,55%,1); }
    .breadcrumb li:nth-child(4) a       { background:        hsla(34,85%,65%,1); }
    .breadcrumb li:nth-child(4) a:after { border-left-color: hsla(34,85%,65%,1); }
    .breadcrumb li:nth-child(5) a       { background:        hsla(34,85%,75%,1); }
    .breadcrumb li:nth-child(5) a:after { border-left-color: hsla(34,85%,75%,1); }
    .breadcrumb li:last-child a {
        background: transparent !important;
        color: black;
        pointer-events: none;
        cursor: default;
    }
    .breadcrumb li a:hover { background: hsla(34,85%,25%,1); }
    .breadcrumb li a:hover:after { border-left-color: hsla(34,85%,25%,1) !important; }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      • 2013-01-04
      • 1970-01-01
      • 2012-06-21
      • 1970-01-01
      • 2012-08-28
      相关资源
      最近更新 更多