如何将链接置于HTML中 [英] How to center links in HTML

查看:94
本文介绍了如何将链接置于HTML中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我一直在尝试:

 < a href =http // www.google.com>< p style =text-align:center>搜寻< / a> 

但问题是当我尝试将其他链接放在它后面时:

 < a href =http // www.google.com>< p style =text-align:center>搜索< / a>< a href =与我们联系>< p style =text-align:center>联系我们< / a>< / p> 

它将它们放在不同的行上。我相信这是因为< p> 函数而发生的......但我只知道HTML,我知道你可以在CSS中完成,但我想知道它是否可以只需使用HTML就可以完成。



感谢您的帮助! 解决方案

你的代码有一些错误 - 第一:你没有关闭你 p -tag:

 < a href =http // www.google.com>< p style =text-align:center>搜寻< / p>< / a> 

next: p 代表'段落'并且是一个块元素(因此导致换行)。你想使用的是 span ,这只是一个格式化的内联元素:

 < a href =http // www.google.com>< span style =text-align:center>搜寻< / span>< / a> 

但是如果您只是想要为链接添加样式,为什么不设置样式直接链接:

 < a href =http // www.google.comstyle =text-align :中心>搜索和LT; / A> 

最后,这至少是正确的html,但仍然不完全是你想要的,因为 text-align:center 将文本置于该元素中,所以您必须为包含这个链接(这张html没有发布,所以我不能纠正你,但我希望你明白) - 为了表明这一点,我将使用一个简单的 div

 < div style =text-align:center> 
< a href =http // www.google.com>搜寻< / a>
<! - 更多链接在这里 - >
< / div>

编辑:一些更多的附加到您的问题:




  • p 不是'函数',但是你是对的,这导致了问题因为它是一个块元素)

  • 你试图使用的是 css - 它只是内联而不是放置在一个单独的文件中,但是你没有't'只是HTML'在这里


I am really new to HTML and was wondering how you center multiple links with html?

I have been trying :

  <a href="http//www.google.com"><p style="text-align:center">Search</a>

But the problem is when I try to put other links behind it for example:

 <a href="http//www.google.com"><p style="text-align:center">Search</a><a href="Contact Us"><p style="text-align:center">Contact Us</a></p>

It just places them on separate lines. I believe this is happening because of the <p> function...but I only know HTML, I know you can do it in CSS but I was wondering if it can be done using just HTML.

Thanks for any help!

解决方案

there are some mistakes in your code - the first: you havn't closed you p-tag:

<a href="http//www.google.com"><p style="text-align:center">Search</p></a>

next: p stands for 'paragraph' and is a block-element (so it's causing a line-break). what you wanted to use there is a span, wich is just an inline-element for formatting:

<a href="http//www.google.com"><span style="text-align:center">Search</span></a>

but if you just want to add a style to your link, why don't you set the style for that link directly:

<a href="http//www.google.com" style="text-align:center">Search</a>

in the end, this would at least be correct html, but still not exactly what you want, because text-align:center centers the text in that element, so you would have to set that for the element that contains this links (this piece of html isn't posted, so i can't correct you, but i hope you understand) - to show this, i'll use a simple div:

<div style="text-align:center">    
  <a href="http//www.google.com">Search</a>
  <!-- more links here -->
</div>

EDIT: some more additions to your question:

  • p is not a 'function', but you're right, this is causing the problem (because it's a block-element)
  • what you're trying to use is css - it's just inline instead of being placed in a seperate file, but you aren't doing 'just HTML' here

这篇关于如何将链接置于HTML中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆