简体   繁体   English

必要时定位绝对全宽

[英]position absolute full width if necessary

I have a div with "position: absolute" and a title inside.我有一个带有“位置:绝对”的 div 和一个标题。 If the title is long, a break line is automatically applied even though the div width may increase.如果标题很长,即使 div 宽度可能会增加,也会自动应用断线。

I set the property max-width: 100% so that the text is added to the line only when we reach 100%.我设置了属性 max-width: 100% 以便只有当我们达到 100% 时才会将文本添加到行中。 Unfortunately, the text breaks at random.不幸的是,文本随机中断。

Here are the properties of the absolute div:以下是绝对 div 的属性:

position: absolute;
z-index: 1;
top: 50%;
left: 50%;
transform: translate3d(-50%, -50%, 1px);

The current rendering当前渲染

Do you have a solution ?你有解决方案吗 ? Sorry for my english, i am working to improve it对不起我的英语,我正在努力改进它

Set the display: flex for your div.为您的 div 设置display: flex By the way position: absolute doesn't work with what I have suggested.顺便说一下position: absolute不符合我的建议。 Or you can try making your text in the div float and your div should have overflow: hidden .或者您可以尝试使 div 中的文本浮动,并且您的 div 应该有overflow: hidden

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

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