CSS 锚标记元素之间不需要的间距
我有这个样式表:
*{
padding: 0px;
margin: 0px;
}
a{
background:yellow;
}
和这个网页:
<a href="/blog/">Home</a>
<a href="/about/">About</a>
<a href="/contact/">Contact</a>
结果:
如何使这些锚标记“触摸” “彼此之间,消除中间不需要的空间?
谢谢 卢卡
I have this stylesheet:
*{
padding: 0px;
margin: 0px;
}
a{
background:yellow;
}
and this webpage:
<a href="/blog/">Home</a>
<a href="/about/">About</a>
<a href="/contact/">Contact</a>
Results in:
How do I make those anchor tag to "touch" each other,removing that unwanted space in-between?
thanks
Luca
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您需要删除标签之间的空格(在本例中为换行符)。有些浏览器将其呈现为空格。
You need to remove the whitespace (in this case the newline) between your tags. Some browsers render it as a space.
您可以使用此技巧来消除空格:
HTML:
CSS:
Live demo: http: //jsfiddle.net/qucy/
You can use this trick to get rid of the space:
HTML:
CSS:
Live demo: http://jsfiddle.net/quucy/
我想我可能会找到一个很酷的方法来解决它:-)。我首先使用
来填充空的
<因此
,如果您想保留新行锚点结构并且不希望它们之间有空格...只需在行尾打开一个块注释并在 new
< 之前的新行上结束它锚 >
像这样:
和演示:http://jsfiddle.net/Lukis/reZG2/1/
I think I might find a pretty cool way to solve it :-). I started with the fact of using
<!-- comments -->
to fill empty< span >
s etc.So if you want to keep your anchor-on-a-new-line structure and do not want the spaces between them... simply open a block comment on the end of the line and end it on the new line just before new
< anchor >
Like this:
and DEMO: http://jsfiddle.net/Lukis/reZG2/1/
链接之间的空格可能是由代码中的换行符产生的,但这实际上取决于您在哪个浏览器中获得此行为(有些浏览器会忽略这些字符,有些则不会)。
尝试将所有三个标签放在一行中,并且它们之间没有空格。
The space between the links might be produced by newline characters you have in your code but it really depends in which browser you get this behavior (some browser ignore these characters some do not).
Try putting all three tags in a single line and without spaces between them.
将它们放入 ul/li 结构怎么样?
How about puting them in ul/li structure?
上面所有的答案都展示了一些消除不需要的空白的巧妙方法,但我没有看到我已经使用了近十年的方法;因此,对于那些仍在与空白作斗争的人来说,这是另一个简单的解决方案,可以解决您的老问题 - 使用 float!
HTML:
CSS:
jsfiddle:
http://jsfiddle.net/fjj7dsyx/2/
All the above answers show some neat ways of getting rid of that unwanted whitespace but I don't see the one I've been using for almost a decade; so here's another simple solution to your very old problem for people who still wrestle with that whitespace -- use float!
HTML:
CSS:
jsfiddle:
http://jsfiddle.net/fjj7dsyx/2/
您可以使用弹性盒:
或者如果您使用 Bootstrap:
You can use flexbox:
Or if you use Bootstrap: