gpt4 book ai didi

html - 无法增加面包屑(ol 列表)的宽度以填充父项

转载 作者:行者123 更新时间:2023-11-28 15:38:38 26 4
gpt4 key购买 nike

我正在尝试在我的 Bootstrap 驱动的网站上构建一个简单的面包屑导航系统。

我使用 red-team-design CSS3 面包屑作为灵感。

到目前为止我得到的是:

screenshot

我想做的是确保最后一个事件面包屑的宽度始终填充父 ol 元素。所以最终产品应该是这个样子:

screenshot of wanted result

我试过弄乱边距和填充以及其他一些东西,但似乎没有任何效果。

HTML:

<ol class="breadcrumb">
<li><a href="home.html"><i class="fa fa-home"></i><span> </span></a></li>
<li><a><span>Travel </span></a></li>
<li class="current"><a><span>Destination </span></a></li>
</ol>

(注意 - 我决定使用 .current 类而不是 Bootstrap .active 类)

这是 CSS:

ul {
margin:0;
padding:0;
list-style:none;
}

.breadcrumb {
overflow:hidden;
width:100%;
}

.breadcrumb > li + li:before {
content:none;
}

.breadcrumb li {
float:left;
margin:0 .5em 0 1em;
}

.breadcrumb a {
background:#ddd;
padding:.7em 1em;
float:left;
text-decoration:none;
color:#444;
text-shadow:0 1px 0 rgba(255,255,255,.5);
position:relative;
}

.breadcrumb a:hover {
background:#efc9ab;
}

.breadcrumb a::before, .breadcrumb a::after {
content:'';
position:absolute;
top:0;
bottom:0;
width:1em;
background:#ddd;
transform:skew(-10deg);
}

.breadcrumb a::before {
left:-.5em;
border-radius:5px 0 0 5px;
}

.breadcrumb a:hover::before {
background:#efc9ab;
}

.breadcrumb a::after {
right:-.5em;
border-radius:0 5px 5px 0;
}

.breadcrumb a:hover::after {
background:#efc9ab;
}

.breadcrumb .current {
padding-right:500px;
}

.breadcrumb .current, .breadcrumb .current:hover {
font-weight:bold;
}

.breadcrumb .current::after, .breadcrumb .current::before {
content:normal;
}

最佳答案

这可以使用 flex 解决(综合guide)。我有

  1. ol 设置为 display: flex; 以启用 flexbox 布局;
  2. 从列表项中删除了 float 指令;
  3. .current 项中删除了 padding-right
  4. 在元素内制作 anchor display: block; and fill width;
  5. 使 .current 项可以随着 flex-grow: 1 增长;最大宽度:100%;
  6. 创建了一个小演示,包括在下面。

ol {
margin: 0;
padding: 0;
list-style: none;
}

.breadcrumb {
display: flex;
}

.breadcrumb li {
margin: 0 .5em 0 1em;
max-width: 100%;
}

.breadcrumb a {
position: relative;
display: block;
box-sizing: border-box;
width: 100%;
background: #ddd;
padding: .7em 1em;
float: left;
text-decoration: none;
color: #444;
text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
}

.breadcrumb a:hover {
background: #efc9ab;
}

.breadcrumb a::before,
.breadcrumb a::after {
content: '';
position: absolute;
top: 0;
bottom: 0;
width: 1em;
background: #ddd;
transform: skew(-10deg);
}

.breadcrumb a::before {
left: -.5em;
border-radius: 5px 0 0 5px;
}

.breadcrumb a:hover::before {
background: #efc9ab;
}

.breadcrumb a::after {
right: -.5em;
border-radius: 0 5px 5px 0;
}

.breadcrumb a:hover::after {
background: #efc9ab;
}

.breadcrumb .current,
.breadcrumb .current:hover {
flex-grow: 1;
font-weight: bold;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-home"></i></a></li>
<li><a href="#">Travel</a></li>
<li class="current"><a href="#">Destination</a></li>
</ol>

关于html - 无法增加面包屑(ol 列表)的宽度以填充父项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43823857/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com