我无法将图像对齐到右侧。

huangapple go评论70阅读模式
英文:

I can't align an image to the right

问题

我尝试了所有方法,但无法将图像对齐到右侧。
我在互联网上进行了全面搜索,并且为此问题努力了几天。我使用了 text-align: right;margin: right; 等多种方法。我期望它能够右对齐,但实际上它没有,并且导致图像变大和变小。你能帮我吗?

英文:

I tried everything but could not align the image to the right.

I tried to search all around the internet, and worked on this problem for several days. I used text-align: right; and margin: right; and many more. I expected that it would align to the right, but instead it didn't and resulted in it getting bigger and smaller. Can you help me?

答案1

得分: 0

我猜最简单的方法是使用 flexbox。

<body>
    <div style="display: flex; justify-content: end;">
        <img src="..." alt="...">
    </div>
</body>

你必须确保父级 div 元素的宽度为 100%。你可以使用浏览器的检查工具来确认。

(Firefox:cmd/strg + shift + c,
Safari/Chrome:cmd/strg + shift + i,
或者右键点击并选择底部的 'inspect')。

英文:

I guess the easiest way is to use flexbox.

&lt;body&gt;
&lt;div style=&quot;display: flex; justify-content: end;&quot;&gt;
    &lt;img src=&quot;...&quot; alt=&quot;...&quot;&gt;
&lt;/div&gt;
&lt;/body&gt;

And you have to make sure the parent div-element has a width of 100%. You can check that by using the inspector of your browser.

(Firefox: cmd/strg + shift + c,
Safari/Chrome: cmd/strg + shift + i,
or just use right-click and choose 'inspect' on the bottom)

huangapple
  • 本文由 发表于 2023年4月13日 17:34:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003905.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定