图像链接之间的 CSS 无缘无故出现间隙
在过去的几个小时里,我一直在尝试对这个水平导航进行排序,但没有任何效果。我尝试过reset.css样式表,*{padding: 0; margin: 0) 等,我的图像链接之间仍然有间隙。
您会看到,导航由内联显示的无序列表的图像链接组成,但每个图像之间(左、右、上、下)都有间隙,我不明白为什么。在所有浏览器中都是一样的。
这是该页面的链接,因此来源:Beansheaf 临时
链接到 css: < a href="http://pentathlongb-yorkshire.co.uk/tomsmith/Beansheaf/styles/fund2.css" rel="noreferrer">http://pentathlongb-yorkshire.co.uk/tomsmith/Beansheaf/styles/ fund2.css
网站的其余部分显然还没有完成,我现在担心的只是导航。
I've been trying to get this horizontal navigation sorted for the past few hours now and nothing is working. I've tried reset.css stylesheets, *{padding: 0; margin: 0) etc. and I still have gaps inbetween my image links.
You see, the navigation is made up of an unordered list of image links displayed inline, but there are gaps in between each image, left, right, top and bottom and I can't see why. It's the same in all browsers.
Here is a link to the page, and so source: Beansheaf Temporary
Link to css: http://pentathlongb-yorkshire.co.uk/tomsmith/Beansheaf/styles/fund2.css
The rest of the site is obviously still not done, it's just the navigation I'm worried about right now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
为了避免浮动导航
li
,您至少有两个选项来删除内联元素之间的空格。请注意,结束
标记在后续行中关闭(最后一行除外),这是有效的并保持可读性(至少对我来说)。
另一个选项稍微混乱一些
,只使用 html 注释
来注释掉原本会折叠成单个空格的空格。
我确实希望有某种方式来指定(例如):
To avoid floating the navigation
li
s, you've got -at least- two options to remove the spaces between inline elements.Note that the closing
</li>
tag is closed on the subsequent line (except for the last one), which is valid and maintains readability (for me, at least).The other option is slightly messier
And just uses html comments
<!-- ... -->
to comment-out the spaces that would otherwise be collapsed into a single space.I do wish there was some way of specifying (for example):
另一种避免浮动的方法是将容器上的字体大小设置为 0,然后为 LI 重新设置它,如下所示:
Another approach, avoiding floats, is to set the font-size on the container to 0, and then re-set it back up for the LIs, like this:
图像链接下方的间隙是由于默认情况下图像与基本文本行对齐所致,您只需声明
魔法即可解决它!
the gap below images links is due to the image being aligned with base text line by default, you can solve it simply declaring
magic!
尝试删除
li
元素之间的所有空格和换行符。由于您是内联显示它们,因此 HTML 中的空格将充当内联文本中的空格,并导致渲染时留下间隙。
Try removing all spaces and line-breaks between the
li
elements.Because you are displaying them inline, spaces in the HTML will act as if they were a space in inline text and cause a gap to be left when rendering.
添加
到您的 CSS。
Add
to your CSS.
这是因为 HTML 文档中的新行将被解释为打印内容中的空格。由于所有“li”元素都位于新行上,因此它会在每个元素之间添加一个空格。确保将它们显示为块元素并将它们浮动到左侧,以便它们均匀地运行在一起。
It is because a new line in an HTML document will be interpreted as a space in the printed content. Since all of your 'li' elements are on new lines, it is adding a space between each of them. Make sure you display them as block elements and float them to the left so they run evenly together.
您可以浮动列表元素,那么空格就不会干扰:
You can float the list elements, then the white space doesn't interfer:
我使用 li 标签上的 line-height 属性来解决这个问题。
I use the line-height attribute on the li tag to fix this.
最佳解决方案来自 http://www.cssplay.co.uk/menus/ centered.html。并引用:
Best solution to this comes from http://www.cssplay.co.uk/menus/centered.html. And quoting:
如果您使用 xslt 来显示这些元素,您应该进行以下操作:
if you are using xslt to show these element, you should make the following: