简体   繁体   English

如何将 div 对齐到 flexed div 的左上角

[英]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>

<div align="left">不工作</div><div id="text_translate"><p>当我使用它时,将 div 放在顶部和中心</p><p> HTML </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-html lang-html prettyprint-override"> <div align="center"> <div style="max-width:800px"> <div> <div> <div style="CLEAR: none; BORDER-RIGHT: black 1px solid; BORDER-LEFT: black 1px solid" class="Header" align="center"> <div class="Banner"> <div style="max-width:100%"> <div> <div> <div align="top" align="left"> <a class="BannerText" href="https://web.archive.org/web/20060528010436/http://www.roblox.com:80/Default.aspx">ROBLOX.com</a></div> <div align="center" style="max-width:300px"> <a href="https://web.archive.org/web/20060528010436/http://www.roblox.com/Default.aspx" blankurl="/Thumbs/Blank.ashx?x=311&amp;y=45" imageurl="/images/logo_pure_alpha.png" style="display:inline-block;BEHAVIOR:url(/web/20060528010436im_/http://www.roblox.com/UI/Image.htc);cursor:hand;"></a> </div> <div align="right"><span class="BannerText"> <a class="BannerText" href="https://web.archive.org/web/20060528010436/http://www.roblox.com:80/Login/New.aspx">Sign Up</a></span></div> </div> </div> </div> </div> </div> </div></pre></div></div><p></p><p> CSS</p><pre> .Header { font-size: 14px; }.Banner { PADDING: 8px; }.BannerText { font-weight: bold; color: white; } a.BannerText:link, a.BannerText:visited, a.BannerText:active { text-decoration: none; COLOR: white; } a.BannerText:hover { text-decoration: underline; COLOR: white; }</pre><p> 我尝试对其进行编辑和谷歌搜索,但一无所获。 这是我在 wayback 机器<a href="https://web.archive.org/web/20060528010436/http://www.roblox.com:80/" rel="nofollow noreferrer">https://web.archive.org/web/20060528010436/http://www.roblox.com:80/</a>上找到的旧 HTML 代码我发现旧的 header 很有趣,想用它我的项目。 即使我将其更新为 HTML5 代码,我也不知道使用表格而不是 header 标签是否会损害站点优化/seo</p></div> - <div align="top" align="left"> not working

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在flex div的中间垂直对齐内容 - Align contents vertically in middle of flexed div 如何在div父级中首先将div对齐,然后再使其顶部对齐? - How to align div first left then top in div parent? <div align="left">不工作</div><div id="text_translate"><p>当我使用它时,将 div 放在顶部和中心</p><p> HTML </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-html lang-html prettyprint-override"> <div align="center"> <div style="max-width:800px"> <div> <div> <div style="CLEAR: none; BORDER-RIGHT: black 1px solid; BORDER-LEFT: black 1px solid" class="Header" align="center"> <div class="Banner"> <div style="max-width:100%"> <div> <div> <div align="top" align="left"> <a class="BannerText" href="https://web.archive.org/web/20060528010436/http://www.roblox.com:80/Default.aspx">ROBLOX.com</a></div> <div align="center" style="max-width:300px"> <a href="https://web.archive.org/web/20060528010436/http://www.roblox.com/Default.aspx" blankurl="/Thumbs/Blank.ashx?x=311&amp;y=45" imageurl="/images/logo_pure_alpha.png" style="display:inline-block;BEHAVIOR:url(/web/20060528010436im_/http://www.roblox.com/UI/Image.htc);cursor:hand;"></a> </div> <div align="right"><span class="BannerText"> <a class="BannerText" href="https://web.archive.org/web/20060528010436/http://www.roblox.com:80/Login/New.aspx">Sign Up</a></span></div> </div> </div> </div> </div> </div> </div></pre></div></div><p></p><p> CSS</p><pre> .Header { font-size: 14px; }.Banner { PADDING: 8px; }.BannerText { font-weight: bold; color: white; } a.BannerText:link, a.BannerText:visited, a.BannerText:active { text-decoration: none; COLOR: white; } a.BannerText:hover { text-decoration: underline; COLOR: white; }</pre><p> 我尝试对其进行编辑和谷歌搜索,但一无所获。 这是我在 wayback 机器<a href="https://web.archive.org/web/20060528010436/http://www.roblox.com:80/" rel="nofollow noreferrer">https://web.archive.org/web/20060528010436/http://www.roblox.com:80/</a>上找到的旧 HTML 代码我发现旧的 header 很有趣,想用它我的项目。 即使我将其更新为 HTML5 代码,我也不知道使用表格而不是 header 标签是否会损害站点优化/seo</p></div> - <div align="top" align="left"> not working 如何对齐div左上角的文本? - How do I align text in top left corner of div? 将div左上方的一组图像与CSS对齐 - Align a set of images at top left of a div with css 将div / span对齐到表格单元格的左上角 - Align div/span to top left of table cell 如何将一个 div 向左对齐,另一个 div 向中心对齐? - How to align a div to the left and another div to the center? 如何在div内部垂直对齐div? - How to vertically top align div inside of div? 如何使div中心与div左对齐? - How to make div center align with the div left align? div在居中div的左侧对齐 - div align on the left of centered div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM