簡體   English   中英

居中對齊<p>在 div 內垂直和水平

[英]Centrer align <p> vertically and horizontally inside a div

我正在嘗試在<div>內垂直和水平居中對齊<p> <div> 我正在創建一個加載 div,以便在上傳大文件時使用。

這是我的 CSS 樣式:

#divProcessing {
     position:absolute; /* or fixed */
     background-color:rgba(0,0,0,0.6); /* to your preference */
     width:100%;
     height:100%;
     top:0; left:0; bottom:0; right:0; /* not always necessary */
     text-align:center; 
     vertical-align:middle;
};

* {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
};

這是 HTML:

<div id="divProcessing">
    <p>Cargando c&oacute;digos, por favor espere . . . <img src="~/Content/images/ripple.gif"></p>
</div>

我試過text-align:center; vertical-align:middle; 但它仍然顯示在頁面頂部。

關於如何修復它的任何想法?

JSFiddle: https ://jsfiddle.net/VansFannel/nkb1zupr/

我已經嘗試過這些答案: https : //stackoverflow.com/a/19599207/68571、https : //stackoverflow.com/a/20267769/68571https://stackoverflow.com/a/15121442/68571沒有成功。

試試這個。

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style>
    .loading {
        position:absolute; /* or fixed */
        background-color:rgba(0,0,0,0.6); /* to your preference */
        width:100%;
        height:100%;
        top:0; left:0; bottom:0; right:0; /* not always necessary */
        text-align:center; 
        display: table;
    }

    .loading p {
        color:#fff;
        font-size:25px;
        text-align:center;
        display: table-cell;
        vertical-align: middle;
    }
</style>
</head>

<body>
<div class="loading" id="divProcessing">
    <p>Cargando c&oacute;digos, por favor espere . . . <img src="~/Content/images/ripple.gif"></p>
</div>
</body>
</html>

https://jsfiddle.net/nkb1zupr/9/

試試這個。 你必須為你的 div 指定一個高度。 我現在把它設置為 10em。

HTML

<div id="divProcessing">
    <p>Cargando c&oacute;digos, por favor espere . . . <img src="~/Content/images/ripple.gif"></p>
</div>

CSS

#divProcessing {
     position: relative;
     background-color:rgba(0,0,0,0.6); /* to your preference */
       height: 10em; /* specify a height */
}

#divProcessing p {
   margin: 0;
   position: absolute;               
   top: 50%;                         
   transform: translate(0, -50%);
   margin-left: 33%; 
   margin-right: 33%;
}

添加

#divProcessing p{position:relative; top:50%; text-align:center; margin-top:-15px}

編輯位置您的代碼

#divProcessing {
     **position:fixed;** /* or fixed */
     background-color:rgba(0,0,0,0.6); /* to your preference */
     width:100%;
     height:100%;
     padding-top:50%;
     margin-top:-50px;
     top:0; left:0; bottom:0; right:0; /* not always necessary */
     text-align:center; 
     vertical-align:middle;
};

https://jsfiddle.net/v9L9cb81/1/

嘗試將一個類放入 div 並在 css 文件中編輯其中包含的每個元素。 在你的 html 中嘗試這樣:

<div class="loading" id="divProcessing">
    <p>Cargando c&oacute;digos, por favor espere . . . <img src="~/Content/images/ripple.gif"></p>
</div>

在您的 .css 中,您將編輯您的 < p > 樣式:

.loading {
    position:absolute; /* or fixed */
    background-color:rgba(0,0,0,0.6); /* to your preference */
    width:100%;
    height:100%;
    top:0; left:0; bottom:0; right:0; /* not always necessary */
    text-align:center; 
    vertical-align:middle;
}

.loading p {
    color:#fff;
    font-size:25px;
    text-align:center;
    /*You can also try with margin giving a right margin if you prefer*/
}

對齊內部的圖像和文本<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