簡體   English   中英

在粘性 div 內垂直對齊圖像

[英]Vertically align image inside a sticky div

我知道這是一個以前已經回答過的問題,但由於某種原因,我什么都做不了。 我在一個 div 中有一個粘性的圖像。 圖像當前水平居中對齊,但我無法讓它垂直居中對齊。 圖像粘在 div 的頂部。

這是我的 HTML 代碼:

<section>
    <div class="stickyImg img-1">
        <img src="MainImgCrop.jpeg" class="stickyImg">
    </div>
</section>

這是我的 CSS 代碼:

section {
    display: flex;
    flex-direction: row;
}

section div.stickyImg {
    height: 92vh;
    background-color: purple;
    background-size: cover;
    background-position: center;
    position: sticky;
    position: -webkit-sticky;
    top: 8vh;
    width: 50vw;
    margin: 0;
}

.stickyImg {
    width: 90%;
    height: auto;
    display: block;
    margin-right: auto;
    margin-left: auto;
    margin: auto;
    vertical-align: middle;
    top: 50%;
}

任何幫助將不勝感激,謝謝!

 section { display: flex; flex-direction: row; } section div.stickyImg { height: 92vh; background-color: purple; background-size: cover; background-position: center; position: sticky; position: -webkit-sticky; top: 8vh; width: 50vw; margin: 0; display:flex; flex-direction:column; justify-content:center; align-items:center; }.stickyImg { width: 90%; height: auto; display: block; margin-right: auto; margin-left: auto; margin: auto; vertical-align: middle; top: 50%; }
 <section> <div class="stickyImg img-1"> <img src="MainImgCrop.jpeg" class="stickyImg"> </div> </section>

對齊內部的圖像和文本<div>水平和垂直</div><div id="text_translate"><p>我想水平和垂直對齊 div 內的圖像和文本。 我的代碼:</p><pre> &lt;div style="white-space:nowrap" (click)="sidenav.toggle()"&gt; &lt;img alt='image' style="margin-top: 1vw;display: inline;" width="25" height="35" src="../assets/menu-white-18dp.svg"&gt; &lt;span style="display:inline; white-space:nowrap;" &gt; KRON&lt;/span&gt; &lt;/div&gt;</pre><p> 目前它看起來像這樣: <a href="https://i.stack.imgur.com/VP0Ld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VP0Ld.png" alt="在此處輸入圖像描述"></a></p><p> 我希望“KRON”與圖像對齊。 我做錯了什么?</p></div>

[英]Align image and text inside <div> horizontally and vertically

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM