首页 > 解决方案 > 使用 aria-label 面包屑时如何将 p 标签放在新行上?

问题描述

我有一个导航元素,并试图在该面包屑导航栏下方而不是在它旁边显示文本。我试图display: inline-block在 CSS 中向我的导航栏属性添加一行,但我仍然得到相同的结果。

当我<br>在导航栏后面有 2 或 3 个标签时,它可以工作,但我不想在每个页面上都这样做。我想使用 CSS。

这是片段:

.first {
  display: inline-block;
}

nav.breadcrumb {
  padding-top: 0.8em;
  padding-bottom: 0.8em;
  padding-left: 0.5em;
  padding-right: 0.5em;
  border: 1px solid hsl(0, 0%, 90%);
  border-radius: 4px;
  background: hsl(300, 14%, 97%);
  font-size: 14px;
  float: left;
  max-width: 45%;
}

nav.breadcrumb ol {
  margin: 0;
  padding-left: 0;
  list-style: none;
  left: 0px;
}

nav.breadcrumb li {
  display: inline;
}

nav.breadcrumb li+li::before {
  display: inline-block;
  margin: 0 0.25em;
  transform: rotate(15deg);
  border-right: 0.1em solid currentColor;
  height: 0.8em;
  content: '';
}

nav.breadcrumb [aria-current="page"] {
  color: #000;
  font-weight: 700;
  text-decoration: none;
  max-width: 45%;
}
<nav aria-label="Breadcrumb" class="breadcrumb">
  <ol>
    <li><a href="/">Home</a></li>
    <li><a href="/reamers">Reamers</a></li>
    <li>Jarno Reamers</li>
  </ol>
</nav>

<p class="first">Contact Us for <a href="https://gammons.com/reamers">reamers</a> or to ask about other offerings not listed below.</p>

这是小提琴的结果。

标签: htmlcssnavbar

解决方案


关于nav.breadcrumb添加样式display: inline-block;和删除float: left

display: inline-block;从中删除.first

nav.breadcrumb {
    padding-top: 0.8em;
    padding-bottom: 0.8em;
    padding-left: 0.5em;
    padding-right: 0.5em;
    border: 1px solid hsl(0, 0%, 90%);
    border-radius: 4px;
    background: hsl(300, 14%, 97%);
    font-size: 14px;
    max-width: 45%;
    display: inline-block;
}

nav.breadcrumb ol {
    margin: 0;
    padding-left: 0;
    list-style: none;
    left: 0px;
}

nav.breadcrumb li {
    display: inline;
}

nav.breadcrumb li+li::before {
    display: inline-block;
    margin: 0 0.25em;
    transform: rotate(15deg);
    border-right: 0.1em solid currentColor;
    height: 0.8em;
    content: '';
}

nav.breadcrumb [aria-current="page"] {
    color: #000;
    font-weight: 700;
    text-decoration: none;
    max-width: 45%;
}
<nav aria-label="Breadcrumb" class="breadcrumb">
    <ol>
        <li><a href="/">Home</a></li>
        <li><a href="/reamers">Reamers</a></li>
        <li>Jarno Reamers</li>
    </ol>
</nav>

<p class="first">Contact Us for <a href="https://gammons.com/reamers">reamers</a> or to ask about other offerings not listed below.</p>


推荐阅读