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

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

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

问题

  1. <!-- 开始代码片段: js 显示: false 控制台: true Babel: false -->
  2. <!-- 语言: lang-css -->
  3. .header {
  4. width: 100%;
  5. position: fixed;
  6. top: 0;
  7. left: 0;
  8. z-index: 2;
  9. opacity: 1;
  10. display: flex;
  11. flex-direction: row;
  12. }
  13. .nav-bar {
  14. background-color: var(--nav-color );
  15. box-sizing: border-box;
  16. text-align: center;
  17. height: 43px;
  18. margin: 8px;
  19. overflow: hidden;
  20. border: 1.5px solid #000000;
  21. }
  22. .first {
  23. position: relative;
  24. z-index: 4;
  25. width: 106px;
  26. border-radius: 15px;
  27. }
  28. .second {
  29. width: 100px;
  30. position: relative;
  31. left: -29px;
  32. z-index: 3;
  33. border-radius: 0 15px 15px 0;
  34. }
  35. .third {
  36. width: 100px;
  37. position: relative;
  38. left: -60px;
  39. z-index: 2;
  40. border-radius: 0 15px 15px 0;
  41. }
  42. <!-- 语言: lang-html -->
  43. <!--===== 头部 =====-->
  44. <header class="header">
  45. <!--===== 导航栏 =====-->
  46. <a href=#home class="nav-bar first"><span class="nav-bar-title">主页</span></a>
  47. <a href=#about class="nav-bar second"><span class="nav-bar-title">关于</span></a>
  48. <a href=#more class="nav-bar third"><span class="nav-bar-title">更多</span></a>
  49. </header>
  50. <!-- 结束代码片段 -->
  51. [Realme文件管理器中的导航栏](https://i.stack.imgur.com/k26Jr.jpg)
  52. 我想要得到三角形状的右边缘,请告诉我如何重新创建它。
  53. 如果有类似外观的导航栏模板,请分享。
  54. 这个片段包含了我版本的HTMLCSS代码。
英文:

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

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

  1. .header {
  2. width: 100%;
  3. position: fixed;
  4. top: 0;
  5. left: 0;
  6. z-index: 2;
  7. opacity: 1;
  8. display: flex;
  9. flex-direction: row;
  10. }
  11. .nav-bar {
  12. background-color: var(--nav-color );
  13. box-sizing: border-box;
  14. text-align: center;
  15. height: 43px;
  16. margin: 8px;
  17. overflow: hidden;
  18. border: 1.5px solid #000000;
  19. }
  20. .first {
  21. position: relative;
  22. z-index: 4;
  23. width: 106px;
  24. border-radius: 15px;
  25. }
  26. .second {
  27. width: 100px;
  28. position: relative;
  29. left: -29px;
  30. z-index: 3;
  31. border-radius: 0 15px 15px 0;
  32. }
  33. .third {
  34. width: 100px;
  35. position: relative;
  36. left: -60px;
  37. z-index: 2;
  38. border-radius: 0 15px 15px 0;
  39. }

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

  1. &lt;!--===== HEADER =====--&gt;
  2. &lt;header class=&quot;header&quot;&gt;
  3. &lt;!--===== NAV-BAR =====--&gt;
  4. &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;
  5. &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;
  6. &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;
  7. &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()

  1. #breadcrumb {
  2. display: flex;
  3. background: #f6ede4;
  4. }
  5. .item {
  6. padding: 1em 3em 1em 2em;
  7. background-image:
  8. conic-gradient(
  9. from 210deg at calc(100% - 1em) 50%,
  10. #f6ede4 120deg,
  11. transparent 120deg
  12. ),
  13. conic-gradient(
  14. from 210deg at 100% 50%,
  15. #ffffff 120deg,
  16. transparent 120deg
  17. );
  18. }

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

  1. #breadcrumb {
  2. display: flex;
  3. background: #f6ede4;
  4. }
  5. .item {
  6. position: relative;
  7. padding: 1em 2em;
  8. }
  9. .item::after {
  10. content: '';
  11. position: absolute;
  12. top: 0;
  13. left: 0;
  14. height: 100%;
  15. width: calc(100% + 1em);
  16. background-image:
  17. conic-gradient(
  18. from 210deg at calc(100% - 1em) 50%,
  19. #f6ede4 120deg,
  20. transparent 120deg
  21. ),
  22. conic-gradient(
  23. from 210deg at 100% 50%,
  24. #ffffff 120deg,
  25. transparent 120deg
  26. );
  27. -webkit-mask: conic-gradient(
  28. from 180deg at calc(100% - 2em) 50%,
  29. transparent 180deg,
  30. #000 180deg
  31. );
  32. mask: conic-gradient(
  33. from 180deg at calc(100% - 2em) 50%,
  34. transparent 180deg,
  35. #000 180deg
  36. );
  37. }
英文:

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

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

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

  1. #breadcrumb {
  2. display: flex;
  3. background: #f6ede4;
  4. }
  5. .item {
  6. padding: 1em 3em 1em 2em;
  7. background-image:
  8. conic-gradient(
  9. from 210deg at calc(100% - 1em) 50%,
  10. #f6ede4 120deg,
  11. transparent 120deg
  12. ),
  13. conic-gradient(
  14. from 210deg at 100% 50%,
  15. #ffffff 120deg,
  16. transparent 120deg
  17. );
  18. }

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

  1. &lt;div id=&quot;breadcrumb&quot;&gt;
  2. &lt;div class=&quot;item&quot;&gt;Phone storage&lt;/div&gt;
  3. &lt;div class=&quot;item&quot;&gt;Download&lt;/div&gt;
  4. &lt;div class=&quot;item active&quot;&gt;Apps&lt;/div&gt;
  5. &lt;/div&gt;

<!-- end snippet -->

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

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

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

  1. #breadcrumb {
  2. display: flex;
  3. background: #f6ede4;
  4. }
  5. .item {
  6. position: relative;
  7. padding: 1em 2em;
  8. }
  9. .item::after {
  10. content: &#39;&#39;;
  11. position: absolute;
  12. top: 0;
  13. left: 0;
  14. height: 100%;
  15. width: calc(100% + 1em);
  16. background-image:
  17. conic-gradient(
  18. from 210deg at calc(100% - 1em) 50%,
  19. #f6ede4 120deg,
  20. transparent 120deg
  21. ),
  22. conic-gradient(
  23. from 210deg at 100% 50%,
  24. #ffffff 120deg,
  25. transparent 120deg
  26. );
  27. -webkit-mask: conic-gradient(
  28. from 180deg at calc(100% - 2em) 50%,
  29. transparent 180deg,
  30. #000 180deg
  31. );
  32. mask: conic-gradient(
  33. from 180deg at calc(100% - 2em) 50%,
  34. transparent 180deg,
  35. #000 180deg
  36. );
  37. }

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

  1. &lt;div id=&quot;breadcrumb&quot;&gt;
  2. &lt;div class=&quot;item&quot;&gt;Phone storage&lt;/div&gt;
  3. &lt;div class=&quot;item&quot;&gt;Download&lt;/div&gt;
  4. &lt;div class=&quot;item active&quot;&gt;Apps&lt;/div&gt;
  5. &lt;/div&gt;

<!-- end snippet -->

答案2

得分: -1

  1. &lt;!-- 开始片段: js 隐藏: false 控制台: true Babel: false --&gt;
  2. &lt;!-- 语言: lang-css --&gt;
  3. .arrow-up {
  4. 宽度: 0;
  5. 高度: 0;
  6. 边框左: 5像素 实心 透明;
  7. 边框右: 5像素 实心 透明;
  8. 边框底部: 5像素 实心 黑色;
  9. }
  10. .arrow-down {
  11. 宽度: 0;
  12. 高度: 0;
  13. 边框左: 20像素 实心 透明;
  14. 边框右: 20像素 实心 透明;
  15. 边框顶部: 20像素 实心 #f00;
  16. }
  17. .arrow-right {
  18. 宽度: 0;
  19. 高度: 0;
  20. 边框顶部: 60像素 实心 透明;
  21. 边框底部: 60像素 实心 透明;
  22. 边框左: 60像素 实心 绿色;
  23. }
  24. .arrow-left {
  25. 宽度: 0;
  26. 高度: 0;
  27. 边框顶部: 10像素 实心 透明;
  28. 边框底部: 10像素 实心 透明;
  29. 边框右: 10像素 实心 蓝色;
  30. }
  31. &lt;!-- 语言: lang-html --&gt;
  32. &lt;div class=&quot;arrow-up&quot;&gt;&lt;/div&gt;
  33. &lt;div class=&quot;arrow-down&quot;&gt;&lt;/div&gt;
  34. &lt;div class=&quot;arrow-left&quot;&gt;&lt;/div&gt;
  35. &lt;div class=&quot;arrow-right&quot;&gt;&lt;/div&gt;
  36. &lt;!-- 结束片段 --&gt;
英文:

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

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

  1. .arrow-up {
  2. width: 0;
  3. height: 0;
  4. border-left: 5px solid transparent;
  5. border-right: 5px solid transparent;
  6. border-bottom: 5px solid black;
  7. }
  8. .arrow-down {
  9. width: 0;
  10. height: 0;
  11. border-left: 20px solid transparent;
  12. border-right: 20px solid transparent;
  13. border-top: 20px solid #f00;
  14. }
  15. .arrow-right {
  16. width: 0;
  17. height: 0;
  18. border-top: 60px solid transparent;
  19. border-bottom: 60px solid transparent;
  20. border-left: 60px solid green;
  21. }
  22. .arrow-left {
  23. width: 0;
  24. height: 0;
  25. border-top: 10px solid transparent;
  26. border-bottom: 10px solid transparent;
  27. border-right: 10px solid blue;
  28. }

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

  1. &lt;div class=&quot;arrow-up&quot;&gt;&lt;/div&gt;
  2. &lt;div class=&quot;arrow-down&quot;&gt;&lt;/div&gt;
  3. &lt;div class=&quot;arrow-left&quot;&gt;&lt;/div&gt;
  4. &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:

确定