简体   繁体   English

使用变换旋转和更改文本来调整宽度div

[英]Adapt width div with transform rotate and change text

I have a problem with a specific style. 我有一个特定风格的问题。 I have a string "Historic" in a div with CSS transform rotate, positioned on a specific part of sibling div. 我在div中使用CSS变换旋转字符串“Historic”,位于兄弟div的特定部分。 If I change the string by "Historique" (for i18n), the div move. 如果我通过“Historique”(对于i18n)更改字符串,则div移动。

I wish the div keep at the same place when string has changed. 我希望div在字符串改变时保持在同一个地方。 Thank you for answers. 谢谢你的回答。

 #main { margin: 50px; position: relative; width: 300px; background: #eee; border: thin solid #bbb; } #tag { position: absolute; left: -36px; padding: 5px; font-size: 9px; transform: rotate(-90deg); background: red; color: white; bottom: 15px; text-transform: uppercase; max-height: 20px; } .content { display: flex; position: relative; padding: 20px; } 
 <div id="main"> <div id="tag">Historic</div> <div class="content">a</div> <div class="content">b</div> <div class="content">c</div> </div> 

I got it working by changing the tag class to read like this. 我通过将标记类更改为这样来读取它。 Note the transform-origin option. 请注意transform-origin选项。

transform-origin: left top 0;
position: absolute;
left: -21px;
padding: 5px;
font-size: 9px;
transform: rotate(-90deg);
background: red;
color: white;
bottom: -20px;
text-transform: uppercase;
max-height: 20px;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM