gpt4 book ai didi

html - 仅倾斜前后的一侧以获得扁平箭头

转载 作者:行者123 更新时间:2023-12-02 00:25:08 25 4
gpt4 key购买 nike

我创建了一些虚拟面包屑导航步骤。第一个面包屑步骤需要在左侧有一个正常的扁平边框,这已经完成了。在悬停时,我需要为每个面包屑项显示黑色边框。

但唯一的问题是在悬停时,对于第一个面包屑步骤,我没有像预期的那样在左侧看到平坦的边框。

这是悬停时的预期结果:

enter image description here

这是我的代码:

body {
padding: 0;
margin: 0;
}

.breadcrumbs {
background-color: white;
width: 100%;
padding: 0 1rem;
font-size: 0;
margin: 1rem;
}

.breadcrumbs .breadcrumb-step {
display: inline-block;
width: 12.33%;
height: 5rem;
text-decoration: none;
color: black;
}

.step-title {
display: none;
}

.breadcrumb-step:before {
content: '';
display: block;
transform: skew(30deg);
border: 1px solid lightgrey;
border-bottom: none;
height: 50%;
width: 100%;
}

.breadcrumb-step:after {
content: '';
display: block;
transform: skew(-30deg);
border: 1px solid lightgrey;
border-top: none;
height: 50%;
width: 100%;
}

.breadcrumb-step:hover:before {
border-color: black;
}

.breadcrumb-step:hover:after {
border-color: black;
}

.breadcrumb-step:nth-child(1):before {
transform: none;
border-right: none;
}
.breadcrumb-step:nth-child(1):after {
transform: none;
border-right: none;
}

.breadcrumb-step:nth-child(1):hover:before {
transform: skew(30deg);
border-right: 1px solid black;
}

.breadcrumb-step:nth-child(1):hover:after {
transform: skew(-30deg);
border-right: 1px solid black;
}
/*
.breadcrumb-step:nth-child(1) {
border: 1px solid lightgrey;
}

.breadcrumb-step:nth-child(1):before {
transform: none;
border: none;
}

.breadcrumb-step:nth-child(1):after {
transform: none;
border: none;
}
*/
<div class="breadcrumbs">
<a class="breadcrumb-step" href="#"><span class="step-title">Home</span></a>
<a class="breadcrumb-step" href="#"><span class="step-title">About</span></a>
<a class="breadcrumb-step" href="#"><span class="step-title">Contact Us</span></a>
</div>

最佳答案

您可以调整 transform-origin 然后隐藏倾斜元素的溢出部分并在悬停时更改第一个子元素的左边框:

body {
margin: 0;
}

.breadcrumbs {
background-color: white;
width: 100%;
padding: 0 1rem;
font-size: 0;
margin: 1rem;
}

.breadcrumbs .breadcrumb-step {
display: inline-block;
width: 12.33%;
height: 5rem;
text-decoration: none;
color: black;
}
/*added this*/
.breadcrumbs .breadcrumb-step:first-child {
width: 15.33%;
overflow:hidden;
border-left:1px solid lightgrey;
}
/**/

.step-title {
display: none;
}

.breadcrumb-step:before,
.breadcrumb-step:after {
content: '';
display: block;
height: 50%;
box-sizing:border-box;
width: 100%;
border: 1px solid lightgrey;

}
.breadcrumb-step:before {
transform: skew(30deg);
transform-origin:right bottom; /*added this*/
border-bottom: none;
}

.breadcrumb-step:after {
transform: skew(-30deg);
transform-origin:right top; /*added this*/
border-top: none;
}

/*added this*/
.breadcrumb-step:hover:before,
.breadcrumb-step:hover:after,
.breadcrumbs .breadcrumb-step:first-child:hover{
border-color: black;
}
<div class="breadcrumbs">
<a class="breadcrumb-step" href="#"><span class="step-title">Home</span></a>
<a class="breadcrumb-step" href="#"><span class="step-title">About</span></a>
<a class="breadcrumb-step" href="#"><span class="step-title">Contact Us</span></a>
</div>

关于html - 仅倾斜前后的一侧以获得扁平箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54008105/

25 4 0
文章推荐: python - 搜索插入位置
文章推荐: graphql - 如何在前端代码中使用 GraphQL 枚举(例如在