英文:
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.
<body>
<div style="display: flex; justify-content: end;">
<img src="..." alt="...">
</div>
</body>
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论