对齐水平导航栏中的多个单词链接的适当间距?

发布于 2024-11-14 02:37:27 字数 1813 浏览 1 评论 0原文

我正在构建一个基于文本的导航栏,在父 div 的宽度上均匀分布,但在将某些导航项分组在一起时遇到问题。每个单词(而不是每个列表项)分布在 div 的整个宽度上。有没有办法在 div 内均匀分布每个列表项,但保持较长的项目,例如“/绘画和混合媒体”适当间隔?我在第一个链接前面也有一个幻影空间,我找不到,所以它并不完全符合我希望的方式。

澄清一下: 发布的代码显示“/Painting & Mixed Media”的链接,每个单词之间有额外的空格。下面的示例,其中破折号代表导航菜单中的空格:

当前:.../Prints---/Illustration---/Painting---%---Mixed---Media---/About---/博客...

所需:.../Prints---/Illustration---/Painting-&-Mixed-Media---/About---/Blog...

这是 CSS:

.navbar{
    font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size:16px; 
    text-decoration: none;
    text-align:justify;
    width: 800px;
}

.navbar * {
  display: inline;
}

.navbar span {
  display: inline-block;
  position: relative;
  width: 100%;
  height: 0;
}

a.nav:link {color:#000; text-decoration: none;}
a.nav:visited {color:#000; text-decoration: none;}
a.nav:hover {color:#6CC; text-decoration: none;}
a.nav:active {color:#F90; text-decoration:none;} 

和 HTML:

<div class="navbar">
    <ul>
    <li><a href="index.html" class="nav">/home</a></li>
    <li><a href="design.html" class="nav">/design </a></li>
    <li><a href="prints.html" class="nav">/prints</a></li>
    <li><a href="illustration.html" class="nav">/illustration</a></li>
    <li><a href="painting.html" class="nav"> /painting &amp; mixed media</a></li>
    <li><a href="about.html" class="nav">/about</a></li>
    <li><a href="external_blog.html" class="nav">/blog</a></li>
    <li><a href="cv.html" class="nav">/cv</a></li>
    </ul>

  <span></span>
    </div>

I'm building a text-based navigation bar, evenly spaced across the width of a parent div, but I'm having a problem keeping certain navigation items grouped together. Each word, instead of each list item, distributes across the entire width of the div. Is there a way to distribute each list item evenly within the div, but keep longer items, like "/painting & Mixed media" properly spaced? I also have a phantom space in front of the first link I can't find, so it's not exactly justified the way I would hope.

To clarify:
The posted code displays the link to "/Painting & Mixed Media" with additional spacing between each word. Example below, where dashes represent spaces in the nav menu:

Currently: .../Prints---/Illustration---/Painting---%---Mixed---Media---/About---/Blog...

Desired: .../Prints---/Illustration---/Painting-&-Mixed-Media---/About---/Blog...

Here's the CSS:

.navbar{
    font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size:16px; 
    text-decoration: none;
    text-align:justify;
    width: 800px;
}

.navbar * {
  display: inline;
}

.navbar span {
  display: inline-block;
  position: relative;
  width: 100%;
  height: 0;
}

a.nav:link {color:#000; text-decoration: none;}
a.nav:visited {color:#000; text-decoration: none;}
a.nav:hover {color:#6CC; text-decoration: none;}
a.nav:active {color:#F90; text-decoration:none;} 

And the HTML:

<div class="navbar">
    <ul>
    <li><a href="index.html" class="nav">/home</a></li>
    <li><a href="design.html" class="nav">/design </a></li>
    <li><a href="prints.html" class="nav">/prints</a></li>
    <li><a href="illustration.html" class="nav">/illustration</a></li>
    <li><a href="painting.html" class="nav"> /painting & mixed media</a></li>
    <li><a href="about.html" class="nav">/about</a></li>
    <li><a href="external_blog.html" class="nav">/blog</a></li>
    <li><a href="cv.html" class="nav">/cv</a></li>
    </ul>

  <span></span>
    </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

宛菡 2024-11-21 02:37:27

演示小提琴

HTML:

<div class="navbar">
    <ul>
        <li><a href="index.html">/home</a></li>
        <li><a href="design.html">/design </a></li>
        <li><a href="prints.html">/prints</a></li>
        <li><a href="illustration.html">/illustration</a></li>
        <li><a href="painting.html">/painting & mixed media</a></li>
        <li><a href="about.html">/about</a></li>
        <li><a href="external_blog.html">/blog</a></li>
        <li><a href="cv.html">/cv</a></li>
    </ul>
    <span></span>
</div>

CSS:

.navbar {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: 16px; 
    text-align: justify;
    width: 800px;
}
.navbar * {
    display: inline;
}
.navbar a {
    display: inline-block;
    text-decoration: none;
}
.navbar span {
    display: inline-block;
    width: 100%;
}
.navbar a:link,
.navbar a:visited {color:#000;}
.navbar a:hover {color:#6CC;}
.navbar a:active {color:#F90;}

Demonstration fiddle

HTML:

<div class="navbar">
    <ul>
        <li><a href="index.html">/home</a></li>
        <li><a href="design.html">/design </a></li>
        <li><a href="prints.html">/prints</a></li>
        <li><a href="illustration.html">/illustration</a></li>
        <li><a href="painting.html">/painting & mixed media</a></li>
        <li><a href="about.html">/about</a></li>
        <li><a href="external_blog.html">/blog</a></li>
        <li><a href="cv.html">/cv</a></li>
    </ul>
    <span></span>
</div>

CSS:

.navbar {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: 16px; 
    text-align: justify;
    width: 800px;
}
.navbar * {
    display: inline;
}
.navbar a {
    display: inline-block;
    text-decoration: none;
}
.navbar span {
    display: inline-block;
    width: 100%;
}
.navbar a:link,
.navbar a:visited {color:#000;}
.navbar a:hover {color:#6CC;}
.navbar a:active {color:#F90;}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文