簡體   English   中英

文字在菱形內垂直對齊

[英]Text align horizontally inside diamond vertically

我已經通過使用以下代碼成功創建了Diamond

CSS:

  .diamond { height: 75px; width: 75px; border-radius:15px; transform: rotate(45deg); float: left; margin-left: 18%; font-size:50px; color: white; font-family:Adequate-ExtraLight; } 
  <div class="diamond" style="background-color:#ff4d4d">48</div> 

上面的代碼產生的輸出具有傾斜的文本,但是我想水平放置文本。 我嘗試過但失敗了。 任何人都可以告訴我如何實現這一目標。

 .diamond { height: 75px; width: 75px; border-radius:15px; transform: rotate(45deg); float: left; margin-left: 18%; font-size:50px; color: white; font-family:Adequate-ExtraLight; } .content{ transform: rotate(-45deg); } 
  <div class="diamond" style="background-color:#ff4d4d"> <div class="content"> 48 </div> </div> 

或者您可以使div的絕對位置使之發生,也可以通過CSS中的z索引來完成

 .diamond { position: absolute; height: 75px; width: 75px; border-radius:15px; transform: rotate(45deg); float: left; margin-left: 18%; font-size:50px; color: white; font-family:Adequate-ExtraLight; } .content{ position: absolute; height: 75px; width: 75px; border-radius:15px; float: left; margin-left: 20%; font-size:50px; color: white; font-family:Adequate-ExtraLight; } 
 <div> <div class="diamond" style="background-color:#ff4d4d"> </div> <div class="content"> 48 </div> </div> 

<div class="diamond" style="background-color:#ff4d4d">
  <div class="text-inside-diamond">48</div>
</div>

.text-inside-diamond {
  transform: rotate(-45deg);
  margin-left: 10%;
}

內部類的左邊距只是將div類的div居中對齊。

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