对齐水平导航栏中的多个单词链接的适当间距?
我正在构建一个基于文本的导航栏,在父 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 & 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
演示小提琴
HTML:
CSS:
Demonstration fiddle
HTML:
CSS: