Html 如何在同一行上放置多个链接?(HTML5)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19917922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 15:14:28  来源:igfitidea点击:

How do I put multiple links on the same line? (HTML5)

htmlhyperlink

提问by Matthew W.

I'm trying to put multiple links on the same line so I can have a whole bar of links, I've tried this:

我试图将多个链接放在同一行上,这样我就可以拥有一整条链接,我试过这个:

<a href="website_homepage.htm"><h2 style="font-family:tempus sans itc;">Home</h2></a> <a     href="website_hills.htm"><h2 style="font-family:tempus sans itc;">Hills Pupil Tailored Website</h2></a>

but when I test to see if it works, these two links are on seperate lines, does anyone know how I can get them on the same line?

但是当我测试它是否有效时,这两个链接位于不同的行上,有谁知道我如何将它们放在同一行上?

回答by Joshua

Simply add:

只需添加:

h2{
    display: inline;
}

To your CSS and the problem will be solved.

到你的CSS,问题就解决了。

回答by Jerska

That's because of h2displayproperty which is block.

那是因为h2display属性是block

Try with:

尝试:

h2 {
    display: inline-block;
}

or

或者

h2 {
    display: inline;
}

at the beginning of your file (enclosed by <style>tags) or in your stylesheet file.

在文件的开头(由<style>标签括起来)或在样式表文件中。

See Typical default display propertieshere

请参阅此处的典型默认显示属性

回答by user2757572

Alternatively replace "h2" with for example "span" and the links will be on the same line.

or you could put:

或者用例如“span”替换“h2”,链接将在同一行上。

或者你可以把:

<h2 style="font-family:tempus sans itc;"><a href="website_homepage.htm">Home</a> <a href="website_hills.htm">Hills Pupil Tailored Website</a></h2>

Putting all the links within one h2 tag instead of using one for each link.

将所有链接放在一个 h2 标签中,而不是为每个链接使用一个。