[英]How to align a div to top left on flexed div
I want to make a image (inside a div) to the most left of the bottom div and I don't how to do this.我想在底部 div 的最左边制作一个图像(在 div 内),但我不知道如何做到这一点。 For example I have this image
例如我有这张图片
.container { display: flex; flex-direction: column; align-items: center; }.applicationimage { width: 60px; height: 60px; border-radius: 100%; }.settings { display: flex; width: 80%; height: 40rem; background-color: white; align-self: center; }
<main> <div class="container"> <div class="applicationinfo"> <img src="https://wallup.net/wp-content/uploads/2019/09/1667-beautiful-gray-cat-748x468.jpg" class="applicationimage"> </div> <div class="settings"> <span>hi</span> </div> </div> </main>
I'm new to html & css so I will appreciate your help making this image to the most left of his bottom div.我是 html 和 css 的新手,所以我将感谢您帮助将这张图片制作到他底部 div 的最左侧。
If you know the width of the div
, it's easy.如果你知道
div
的宽度,那就很容易了。 You can give the .applicationinfo
element align-self: flex-start;
你可以给
.applicationinfo
元素align-self: flex-start;
and margin-left: 10%;
和
margin-left: 10%;
( 10%
is calculated by this formula: (100% - widthOfDiv) / 2
) (
10%
由以下公式计算: (100% - widthOfDiv) / 2
)
body { background: black; }.container { display: flex; flex-direction: column; align-items: center; }.applicationinfo { align-self: flex-start; margin-left: 10%; }.applicationimage { width: 60px; height: 60px; border-radius: 100%; }.settings { display: flex; width: 80%; height: 40rem; background-color: white; align-self: center; }
<main> <div class="container"> <div class="applicationinfo"> <img src="https://wallup.net/wp-content/uploads/2019/09/1667-beautiful-gray-cat-748x468.jpg" class="applicationimage"> </div> <div class="settings"> <span>hi</span> </div> </div> </main>
remove the flex direction, here's it去掉弯曲方向,就是这样
display: flex;
justify-items: flex-end;
align-items: flex-end;}
You can do it by positioning applicationinfo
since you haven't styled it.您可以通过定位
applicationinfo
来做到这一点,因为您还没有设置它的样式。 you can add parent position: relative;
您可以添加父
position: relative;
then child to absolute;然后孩子绝对; then give child
top: 0; left: 0;
然后给孩子
top: 0; left: 0;
top: 0; left: 0;
.container { display: flex; height: 80vh; flex-direction: column; align-items: center; justify-content: center; align-items: center; position: relative; background: #222; border: 1px solid yellow; }.applicationinfo { width: 80%; top: 0; left: 0; border: 1px solid green; }.applicationimage { width: 60px; height: 60px; border-radius: 100%; border: 1px solid blue; }.settings { display: flex; width: 80%; height: 80%; background-color: white; align-self: center; }
<div class="container"> <div class="applicationinfo"> <img src="https://wallup.net/wp-content/uploads/2019/09/1667-beautiful-gray-cat-748x468.jpg" class="applicationimage"> </div> <div class="settings"> <span>hi</span> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.