gpt4 book ai didi

css - 文本这么长时如何设置宽度?

转载 作者:行者123 更新时间:2023-11-27 23:57:15 28 4
gpt4 key购买 nike

我做这个是为了使用 slider ,但是当文本很长或者在 2 行中调整页面文本大小时,但我只需要一行并显示所有文本。我需要它在 IE 9 和 Firefox 中工作。

你可以在codepen中看到元素

* {
padding: 0;
margin: 0;
}

.container {
position: relative;
width: 100%;
height: 250px;
float: left;
overflow: hidden;
}

.train {
/*width: 100px;*/
display: block;
position: absolute;
top: 32%;
right: -100%;
width: 50%;
height: 80px;
animation: train 20s linear infinite;
-webkit-animation: train 8s linear infinite;
text-align: right;
}

#one {
background: yellow;
animation-delay: 0s;
}

#two {
background: blue;
animation-delay: 2s;
}

#three {
background: green;
animation-delay: 4s;
}

#four {
background: red;
animation-delay: 6s;
}

@keyframes train {
to {
right: 100%;
}
}

@-webkit-keyframes train {
to {
right: 100%;
}
}
<div class="container">
<ul>
<li class="train" id="one">
test 1 test 1 test 1 test 1 test 1 test 1 test 1 test 1 test 1 test 1 test 1 test 1 test 1 test 1 finish
</li>
<li class="train" id="two">
test 2 test2 test 2 test2 test 2 test2 test 2 test2 test 2 test2 v test 2 test2 test 2 test2 test 2 test2 test 2 test2 v test 2 test2 test 2 test2 test 2 test2 test 2 test2 test 2 test2 v test 2 test2 test 2 test2 test 2 test2 finish
</li>
<li class="train" id="three">
test 3 test3 finish
</li>
<li class="train" id="four">
test 4 test 4 test 4 finish
</li>
</ul>

</div>

最佳答案

如果您的文本不适合容器,它将被移到另一行。你可以添加

> white-space: nowrap;

或者将以下样式添加到具有 .train 类的元素:

> display: block;
> overflow: hidden;
> text-overflow: ellipsis;

这些样式会剪切文本并在末尾添加虚线。

关于css - 文本这么长时如何设置宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56198079/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com