如何让这张照片居中? [英] How do I get this picture centered?

查看:97
本文介绍了如何让这张照片居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这个网站和HTML的新手,很抱歉,如果我搞砸了



 <   img     align   =  center  src   =  https://yt3.ggpht.com/-7xOKskOmwVY/AAAAAAAAAAAI/AAAAAAAAAAA/7s2wU-RMkac/s100- ck-no-rj-c0xffffff / photo.jpg    /  >  



我希望该图片位于网站的中心。当我向左或向中心对齐时,它向右移动,当我向右对齐时,它向左移动。它下面有文字,所以我猜它可能只是对它下面的文字感到奇怪?无论如何,请帮忙。



我尝试过:



我已经尝试弄乱图片在网站上的位置,但它没有什么区别。

解决方案

你可以使用CSS来做到这一点。 />


在样式表中:

 center  {
display block;
margin 0 auto;
}



然后,使用以下属性为您的图像提供 center 类:

 class =center





如果你不想使用单独的样式表,您可以使用 img 元素上的样式属性来设置样式(使用separ虽然吃了样式表更清洁:

 style =display:block;保证金:0自动



或者您可以使用将图像包装在 p 标记中align =center

 <   p     align   =   center >  
< img align = center src = https://yt3.ggpht.com/-7xOKskOmwVY/AAAAAAAAAAI/AAAAAAAAAAA/7s2wU-RMkac/s100-ck-no -rj-c0xffffff / photo.jpg / >
< / p >


I'm new to this site and HTML so sorry if I get this messed up

<img align="center"src="https://yt3.ggpht.com/-7xOKskOmwVY/AAAAAAAAAAI/AAAAAAAAAAA/7s2wU-RMkac/s100-c-k-no-rj-c0xffffff/photo.jpg" />


I want that image to be in the center of the website. When I align left or center it just goes to the right, and when I align it to the right, it goes to the left. There's text beneath it so I'm guessing maybe it just wraps weird with the text under it? Anyways, some help please.

What I have tried:

I've tried messing with where the picture is on the website but it just doesn't make a difference.

解决方案

You can use CSS to do this.

In your stylesheet:

.center {
    display: block;
    margin: 0 auto;
}


Then, give your image the center class using the following attribute:

class="center"



If you don't want to use a separate stylesheet, you can use the style attribute on the img element to set the styling (using a separate stylesheet is cleaner, though):

style="display: block; margin: 0 auto"


Or you can wrap the image in a p tag with align="center":

<p align="center">
    <img align="center"src="https://yt3.ggpht.com/-7xOKskOmwVY/AAAAAAAAAAI/AAAAAAAAAAA/7s2wU-RMkac/s100-c-k-no-rj-c0xffffff/photo.jpg" />
</p>


这篇关于如何让这张照片居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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