英文:
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 -->
<!--===== HEADER =====-->
<header class="header">
<!--===== NAV-BAR =====-->
<a href=#home class="nav-bar first"><span class="nav-bar-title">Home</span></a>
<a href=#about class="nav-bar second"><span class="nav-bar-title">About</span></a>
<a href=#more class="nav-bar third"><span class="nav-bar-title">More</span></a>
</header>
<!-- 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 -->
<div id="breadcrumb">
<div class="item">Phone storage</div>
<div class="item">Download</div>
<div class="item active">Apps</div>
</div>
<!-- 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: '';
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 -->
<div id="breadcrumb">
<div class="item">Phone storage</div>
<div class="item">Download</div>
<div class="item active">Apps</div>
</div>
<!-- end snippet -->
答案2
得分: -1
<!-- 开始片段: js 隐藏: false 控制台: true Babel: false -->
<!-- 语言: lang-css -->
.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像素 实心 蓝色;
}
<!-- 语言: lang-html -->
<div class="arrow-up"></div>
<div class="arrow-down"></div>
<div class="arrow-left"></div>
<div class="arrow-right"></div>
<!-- 结束片段 -->
英文:
<!-- 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 -->
<div class="arrow-up"></div>
<div class="arrow-down"></div>
<div class="arrow-left"></div>
<div class="arrow-right"></div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论