[英]How to Align a Link HTML/CSS
I have tried to do the following, as well as using the align only with the <a>
href and <img>
tags, yet I still cannot align the clickable image to the center of the page.我尝试执行以下操作,并仅使用<a>
href 和<img>
标签对齐,但我仍然无法将可点击图像与页面中心对齐。
<a href="next.html" align="middle"> <img src="tlbr.png" align="middle"> </a>
The float tag also does not work in any way I have tried, since, as far as I am aware, there is no way to float to center.浮动标签也无法以我尝试过的任何方式工作,因为据我所知,没有办法浮动到中心。
Any solution, directly in HTML or in the CSS, would be great.任何直接在 HTML 或 CSS 中的解决方案都会很棒。 Thanks.谢谢。
Add display: block; text-align: center;
添加display: block; text-align: center;
display: block; text-align: center;
to href link.到 href 链接。 And try.并尝试。
Add this code to your CSS:将此代码添加到您的 CSS:
a img{
display: block;
text-align: center;
}
First of all, you should set width and display for your a
element and them display the img
tang and using margin: 0 auto
to set the image in center:首先,您应该为a
元素设置宽度和显示,它们显示img
tang 并使用margin: 0 auto
将图像设置在中心:
<a href="#" align="middle" style="width: 100%; display: block; background: #ccc;"> <img src="http://caster.ir/public/images/logo.png" align="middle" style="display: block; margin: 0 auto;"> </a>
The <img>
tag align Attribute aligns the image vertically with respect to the line. <img>
标签的 align 属性使图像相对于线条垂直对齐。 The <a>
tag does not recognise the align attribute. <a>
标签无法识别 align 属性。
If you are trying to centre an image horizontally then you might want to try using the following:如果您尝试将图像水平居中,则可能需要尝试使用以下方法:
<a href="next.html">
<img id="myImg" src="tlbr.png" />
</a>
Then in your CSS stylesheet:然后在你的 CSS 样式表中:
#myImg {
margin-left: auto;
margin-right: auto;
}
Hope this helps.希望这可以帮助。
Or you could add a <p>
tag and then align it.或者你可以添加一个<p>
标签,然后对齐它。 For example:例如:
<a href="link.com">
<p align="center">Hello World!</p>
</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.