如何使用HTML和CSS重新创建此导航栏?

huangapple go评论68阅读模式
英文:

How can I recreate this navigation bar using HTML and CSS?

问题

<!-- 开始代码片段: js 显示: false 控制台: true Babel: false -->

<!-- 语言: lang-css -->

    .header {
      width: 100%;
      position: fixed;
      top: 0;
      left: 0;
      z-index: 2;
      opacity: 1;
      display: flex;
      flex-direction: row;
    }

    .nav-bar {
      background-color: var(--nav-color );
      box-sizing: border-box;
      text-align: center;
      height: 43px;
      margin: 8px;
      overflow: hidden;
      border: 1.5px solid #000000;
    }
    .first {
      position: relative;
      z-index: 4;
      width: 106px;
      border-radius: 15px;
    }
    .second {
      width: 100px;
      position: relative;
      left: -29px;
      z-index: 3;
      border-radius: 0 15px 15px 0;
    }
    .third {
      width: 100px;
      position: relative;
      left: -60px;
      z-index: 2;
      border-radius: 0 15px 15px 0;
    }

<!-- 语言: lang-html -->

    <!--===== 头部 =====-->
      <header class="header">
        <!--===== 导航栏 =====-->
        <a href=#home class="nav-bar first"><span class="nav-bar-title">主页</span></a>
        <a href=#about class="nav-bar second"><span class="nav-bar-title">关于</span></a>
        <a href=#more class="nav-bar third"><span class="nav-bar-title">更多</span></a>
    </header>

<!-- 结束代码片段 -->

[Realme文件管理器中的导航栏](https://i.stack.imgur.com/k26Jr.jpg)

我想要得到三角形状的右边缘,请告诉我如何重新创建它。

如果有类似外观的导航栏模板,请分享。

这个片段包含了我版本的HTML和CSS代码。
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.header {
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2;
  opacity: 1;
  display: flex;
  flex-direction: row;
}

.nav-bar {
  background-color: var(--nav-color );
  box-sizing: border-box;
  text-align: center;
  height: 43px;
  margin: 8px;
  overflow: hidden;
  border: 1.5px solid #000000;
}
.first {
  position: relative;
  z-index: 4;
  width: 106px;
  border-radius: 15px;
}
.second {
  width: 100px;
  position: relative;
  left: -29px;
  z-index: 3;
  border-radius: 0 15px 15px 0;
}
.third {
  width: 100px;
  position: relative;
  left: -60px;
  z-index: 2;
  border-radius: 0 15px 15px 0;
}

<!-- language: lang-html -->

&lt;!--===== HEADER =====--&gt;
  &lt;header class=&quot;header&quot;&gt;
    &lt;!--===== NAV-BAR =====--&gt;
    &lt;a href=#home class=&quot;nav-bar first&quot;&gt;&lt;span class=&quot;nav-bar-title&quot;&gt;Home&lt;/span&gt;&lt;/a&gt;
    &lt;a href=#about class=&quot;nav-bar second&quot;&gt;&lt;span class=&quot;nav-bar-title&quot;&gt;About&lt;/span&gt;&lt;/a&gt;
    &lt;a href=#more class=&quot;nav-bar third&quot;&gt;&lt;span class=&quot;nav-bar-title&quot;&gt;More&lt;/span&gt;&lt;/a&gt;
&lt;/header&gt;

<!-- end snippet -->

navigation bar in Realme file manager

I want to get triangular shaped right edges, tell me how can I recreat it.

Share if there is any template for similar looking navigation bar.

The snippet contains the HTML and CSS code of my version,

答案1

得分: 1

也许你可以利用一些 conic-gradient()

#breadcrumb {
  display: flex;
  background: #f6ede4;
}

.item {
  padding: 1em 3em 1em 2em;
  background-image:
    conic-gradient(
      from 210deg at calc(100% - 1em) 50%,
      #f6ede4 120deg,
      transparent 120deg
    ),
    conic-gradient(
      from 210deg at 100% 50%,
      #ffffff 120deg,
      transparent 120deg
    );
}

...或者在伪元素上使用 mask

#breadcrumb {
  display: flex;
  background: #f6ede4;
}

.item {
  position: relative;
  padding: 1em 2em;
}

.item::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: calc(100% + 1em);
  background-image:
    conic-gradient(
      from 210deg at calc(100% - 1em) 50%,
      #f6ede4 120deg,
      transparent 120deg
    ),
    conic-gradient(
      from 210deg at 100% 50%,
      #ffffff 120deg,
      transparent 120deg
    );
  -webkit-mask: conic-gradient(
    from 180deg at calc(100% - 2em) 50%,
    transparent 180deg,
    #000 180deg
  );
  mask: conic-gradient(
    from 180deg at calc(100% - 2em) 50%,
    transparent 180deg,
    #000 180deg
  );
}
英文:

Perhaps you can make use of some conic-gradient():

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-css -->

#breadcrumb {
  display: flex;
  background: #f6ede4;
}

.item {
  padding: 1em 3em 1em 2em;
  background-image:
    conic-gradient(
      from 210deg at calc(100% - 1em) 50%,
      #f6ede4 120deg,
      transparent 120deg
    ),
    conic-gradient(
      from 210deg at 100% 50%,
      #ffffff 120deg,
      transparent 120deg
    );
}

<!-- language: lang-html -->

&lt;div id=&quot;breadcrumb&quot;&gt;
  &lt;div class=&quot;item&quot;&gt;Phone storage&lt;/div&gt;
  &lt;div class=&quot;item&quot;&gt;Download&lt;/div&gt;
  &lt;div class=&quot;item active&quot;&gt;Apps&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

...or some mask on a pseudo-element:

<!-- begin snippet: js hide: false -->

<!-- language: lang-css -->

#breadcrumb {
  display: flex;
  background: #f6ede4;
}

.item {
  position: relative;
  padding: 1em 2em;
}

.item::after {
  content: &#39;&#39;;
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: calc(100% + 1em);
  background-image:
    conic-gradient(
      from 210deg at calc(100% - 1em) 50%,
      #f6ede4 120deg,
      transparent 120deg
    ),
    conic-gradient(
      from 210deg at 100% 50%,
      #ffffff 120deg,
      transparent 120deg
    );
  -webkit-mask: conic-gradient(
    from 180deg at calc(100% - 2em) 50%,
    transparent 180deg,
    #000 180deg
  );
  mask: conic-gradient(
    from 180deg at calc(100% - 2em) 50%,
    transparent 180deg,
    #000 180deg
  );
}

<!-- language: lang-html -->

&lt;div id=&quot;breadcrumb&quot;&gt;
  &lt;div class=&quot;item&quot;&gt;Phone storage&lt;/div&gt;
  &lt;div class=&quot;item&quot;&gt;Download&lt;/div&gt;
  &lt;div class=&quot;item active&quot;&gt;Apps&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

答案2

得分: -1

&lt;!-- 开始片段: js 隐藏: false 控制台: true Babel: false --&gt;

&lt;!-- 语言: lang-css --&gt;

    .arrow-up {
      宽度: 0;
      高度: 0;
      边框左: 5像素 实心 透明;
      边框右: 5像素 实心 透明;
      边框底部: 5像素 实心 黑色;
    }

    .arrow-down {
      宽度: 0;
      高度: 0;
      边框左: 20像素 实心 透明;
      边框右: 20像素 实心 透明;
      边框顶部: 20像素 实心 #f00;
    }

    .arrow-right {
      宽度: 0;
      高度: 0;
      边框顶部: 60像素 实心 透明;
      边框底部: 60像素 实心 透明;
      边框左: 60像素 实心 绿色;
    }

    .arrow-left {
      宽度: 0;
      高度: 0;
      边框顶部: 10像素 实心 透明;
      边框底部: 10像素 实心 透明;
      边框右: 10像素 实心 蓝色;
    }

&lt;!-- 语言: lang-html --&gt;

    &lt;div class=&quot;arrow-up&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;arrow-down&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;arrow-left&quot;&gt;&lt;/div&gt;
    &lt;div class=&quot;arrow-right&quot;&gt;&lt;/div&gt;

&lt;!-- 结束片段 --&gt;
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.arrow-up {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid black;
}

.arrow-down {
  width: 0;
  height: 0;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 20px solid #f00;
}

.arrow-right {
  width: 0;
  height: 0;
  border-top: 60px solid transparent;
  border-bottom: 60px solid transparent;
  border-left: 60px solid green;
}

.arrow-left {
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 10px solid blue;
}

<!-- language: lang-html -->

&lt;div class=&quot;arrow-up&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;arrow-down&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;arrow-left&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;arrow-right&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年4月13日 16:32:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003325.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定