Html 用css创建边框箭头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23428286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:41:17  来源:igfitidea点击:

Create border arrow with css

htmlcss

提问by Johan Nordli

So I got a sketch of a designer I worked with and was wondering how I create the border arrows in the picture below

所以我得到了一个与我合作的设计师的草图,并想知道我是如何创建下图中的边框箭头的

borderarrow

边界箭头

I tried to put out this font-awesome icon by using the :afterselector, it got pretty ugly: http://fortawesome.github.io/Font-Awesome/icon/angle-right/

我试图通过使用:after选择器来推出这个字体很棒的图标 ,它变得非常丑陋:http: //fortawesome.github.io/Font-Awesome/icon/angle-right/

So instead, I tried to put an arrow on an arrow through this arrow generator: http://apps.eky.hk/css-triangle-generator/

所以相反,我试图通过这个箭头生成器在箭头上放一个箭头:http: //apps.eky.hk/css-triangle-generator/

It also became very ugly. So now I wonder if there is anyone who has a good idea on how to solve this?

它也变得非常丑陋。所以现在我想知道是否有人对如何解决这个问题有好主意?

How my html look like so far:

到目前为止我的 html 是什么样子的:

<div class="bx-pager bx-default-pager">

  <div class="bx-pager-item">
    <a class="bx-pager-link active" data-slide-index="0" href=""> 1. DIN EXPERT </a>
  </div>

  <div class="bx-pager-item">
    <a class="bx-pager-link" data-slide-index="1" href=""> 2. V?RA TJ?NSTER </a>
  </div>

  <div class="bx-pager-item">
    <a class="bx-pager-link" data-slide-index="2" href=""> 3. CASE </a>
  </div>

  <div class="bx-pager-item">
    <a class="bx-pager-link" data-slide-index="3" href=""> 4. KONTAKT </a>
  </div>
</div>

回答by Daan

You can create triangles with CSS borders by:

您可以通过以下方式创建带有 CSS 边框的三角形:

border-top: 20px solid transparent; 
border-bottom: 20px solid transparent; /* 40px height (20+20) */
border-left: 20px solid green

I've created the same thing as you see above here:

我已经创建了与您在上面看到的相同的内容:

#container {
  width:150px;
  height:40px;
  background-color:green;
  position:relative;
}
    
.arrow-right {
  width: 0; 
  height: 0; 
  border-top: 20px solid transparent; 
  border-bottom: 20px solid transparent; /* 40px height (20+20) */
  border-left: 20px solid green;
  position:absolute;
  right:-20px;
}
<div id="container">
  <div class="arrow-right"></div>
</div>

回答by Mr_Green

Atlast!! :)

最后!!:)

div.main {
    margin-right:30px;
}
ol > li {        
    display: table-cell;
    height: 30px;        
    position: relative;
    padding: 0px;
    margin: 0px;
    text-align: center;
    border: 1px solid #d68a3a;
}
ol > li > div {         
    position:relative;        
    line-height: 30px; /* equal to the list item's height */
    height:100%;
    width: 100%;         
}
ol>li:hover {
    background-color: #d68a3a;
    cursor: pointer;
    color: white;
}
ol {
    display: table;
    width: 100%;
    padding: 0px;
    margin: 0px;
    position: relative;
}
ol > li > div:after, ol > li > div:before {
    content:"";
    display:inline-block;        
    border-width: 16px;
    border-style: solid;
    width: 0px;
    height: 0px;
    left: 100%;
    top: -1px;        
    position: absolute;        
    z-index: 1;
}
ol > li > div:after, ol > li:hover > div:before {
    border-color: transparent transparent transparent #d68a3a;
}
ol > li > div:before {
    border-width: 14px;
    display: block;
    border-color: transparent transparent transparent #ffffff;
    z-index: 2;
    top:1px;
}

Working Fiddle

工作小提琴

回答by Jignesh Thummar

You have to make little bit changes to your html structure

您必须对 html 结构进行一些更改

  1. Put active class at bx-pager-item element level
  2. Put 1 extra element after anchor tag .
  1. 将活动类置于 bx-pager-item 元素级别
  2. 在锚标记之后放置 1 个额外元素。

Please refer below code snippet.

请参考下面的代码片段。

Working fiddle link: Fiddle

工作小提琴链接:小提琴

.container {
  max-width: 700px;
  margin: auto;
}

.bx-pager {
  display: flex;
  align-items: center;
  height: 34px;
  border-left: 1px solid #d68a3a;
}
.bx-pager .bx-pager-item {
  display: flex;
  align-items: center;
  height: 100%;
  flex: 0 25%;
  border-top: 1px solid #d68a3a;
  border-bottom: 1px solid #d68a3a;
}
.bx-pager .bx-pager-item .bx-pager-link {
  text-decoration: none;
  color: #222;
  font-size: 13px;
  flex: 1;
  padding-left: 16px;
  text-align: center;
}
.bx-pager .bx-pager-item .arrow {
  border: solid #d68a3a;
  display: inline-block;
  padding: 9px;
  border-width: 0 1px 1px 0;
  transform: translateY(15.5px) rotate(-45deg) skew(-15deg, -15deg) translateX(18px);
  background-color: #FFF;
}
.bx-pager .bx-pager-item.active {
  background-color: #d68a3a;
}
.bx-pager .bx-pager-item.active .bx-pager-link {
  color: white;
}
.bx-pager .bx-pager-item.active .arrow {
  background-color: #d68a3a;
}
<body>

  <div class="container">


    <div class="bx-pager bx-default-pager">

      <div class="bx-pager-item active">
        <a class="bx-pager-link " data-slide-index="0" href=""> 1. DIN EXPERT </a>
        <div class="arrow">

        </div>
      </div>

      <div class="bx-pager-item">
        <a class="bx-pager-link" data-slide-index="1" href=""> 2. V?RA TJ?NSTER </a>
        <div class="arrow">

        </div>
      </div>

      <div class="bx-pager-item">
        <a class="bx-pager-link" data-slide-index="2" href=""> 3. CASE </a>
        <div class="arrow">

        </div>
      </div>

      <div class="bx-pager-item">
        <a class="bx-pager-link" data-slide-index="3" href=""> 4. KONTAKT </a>
        <div class="arrow">

        </div>
      </div>
    </div>
  </div>
</body>

回答by Shehroz Asmat

Please Change according to your specification.

请根据您的规格进行更改。

<style>
.menu {
    position: relative;
    background: #88b7d5;

    width:150px;
    height:60px;
}
.menu:after, .menu:before {
    left: 100%;
    top: 50%;
    border: solid transparent;
    content: " ";
    height: 0px;
    width: 0px;
    position: absolute;
    pointer-events: none;
}

.menu:after {
    border-color: rgba(136, 183, 213, 0);
    border-left-color: #88b7d5;
    border-width: 30px;
    margin-top: -30px;
}
</style>

<div class="menu">
</div>