英文:
Cannot align images in tailwind css
问题
我尝试将图像设置到右侧,但我无法做到。
这是代码:
<div class="hidden lg:block lg:bg-red-400 flex">
<img class="h-10 justify-center" src="..." alt="">
</div>
英文:
I am trying to set image to the right side. But I am unable to do so.
Here's the code:
<div class="hidden lg:block lg:bg-red-400 flex">
<img class="h-10 justify-center" src="..." alt="">
</div>
答案1
得分: 2
以下是翻译好的部分:
- 通过在 flex 父元素上使用
justify-end
类来应用justify-content: flex-end
。 - 通过在
<img>
元素上使用ml-auto
类来应用margin-left: auto
。
英文:
You could:
- Apply
justify-content: flex-end
via thejustify-end
class on the flex parent. - Apply
margin-left: auto
via theml-auto
class on the<img>
element.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<script src="https://cdn.tailwindcss.com"></script>
<div class="bg-red-400 flex justify-end">
<img class="h-10 justify-center" src="https://picsum.photos/40/40" alt="">
</div>
<div class="bg-red-400 flex">
<img class="h-10 justify-center ml-auto" src="https://picsum.photos/40/40" alt="">
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论