我正在使用这个圣诞灯 CSS 代码: https://codepen.io/tobyj/pen/QjvEex
该代码通过使用单个 <li></li>
来工作。显示一盏“灯”。
有什么办法可以让 <li></li>
的数量达到显示“填充” <div>
的宽度也许是上课。
我希望我的意思很清楚,但基本上目前我的屏幕尺寸显示的灯光数量很好,但在较小的屏幕上测试相同数量时,它只是传播得太远并在以下位置创建滚动条浏览器底部。
.lightrope {
text-align: left;
white-space: nowrap;
overflow: hidden;
position: absolute;
z-index: 1;
margin: -23px 0 0 0;
padding: 0;
padding-left: 0px;
pointer-events: none;
}
.lightrope li {
position: relative;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
list-style: none;
margin: 0;
padding: 0;
display: block;
width: 12px;
height: 16px;
border-radius: 40%;
margin: 20px;
display: inline-block;
background: #00f7a5;
box-shadow: 0px 4.6666666667px 24px 3px #00f7a5;
-webkit-animation-name: flash-1;
animation-name: flash-1;
-webkit-animation-duration: 1.5s;
animation-duration: 1.5s;
}
.lightrope li:nth-child(2n+1) {
background: cyan;
box-shadow: 0px 4.6666666667px 24px 3px rgba(0, 255, 255, 0.5);
-webkit-animation-name: flash-2;
animation-name: flash-2;
-webkit-animation-duration: 0.4s;
animation-duration: 0.4s;
}
.lightrope li:nth-child(4n+2) {
background: #f70094;
box-shadow: 0px 4.6666666667px 24px 3px #f70094;
-webkit-animation-name: flash-3;
animation-name: flash-3;
-webkit-animation-duration: 1.1s;
animation-duration: 1.1s;
}
.lightrope li:nth-child(odd) {
-webkit-animation-duration: 1.8s;
animation-duration: 1.8s;
}
.lightrope li:nth-child(3n+1) {
-webkit-animation-duration: 1.4s;
animation-duration: 1.4s;
}
.lightrope li:before {
content: "";
position: absolute;
background: #222;
width: 10px;
height: 6.3333333333px;
border-radius: 2px;
top: -4.6666666667px;
left: 1px;
}
.lightrope li:after {
content: "";
top: -14px;
left: 9px;
position: absolute;
width: 54px;
height: 18.6666666667px;
border-bottom: solid #222 2px;
border-radius: 50%;
}
.lightrope li:last-child:after {
width: 29px;
}
.lightrope li:first-child {
margin-left: -40px;
}
@-webkit-keyframes flash-1 {
0%,
100% {
background: #00f7a5;
box-shadow: 0px 4.6666666667px 22px 3px #00f7a5;
}
50% {
background: rgba(0, 247, 165, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(0, 247, 165, 0.2);
}
}
@keyframes flash-1 {
0%,
100% {
background: #00f7a5;
box-shadow: 0px 4.6666666667px 22px 3px #00f7a5;
}
50% {
background: rgba(0, 247, 165, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(0, 247, 165, 0.2);
}
}
@-webkit-keyframes flash-2 {
0%,
100% {
background: cyan;
box-shadow: 0px 4.6666666667px 22px 3px cyan;
}
50% {
background: rgba(0, 255, 255, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(0, 255, 255, 0.2);
}
}
@keyframes flash-2 {
0%,
100% {
background: cyan;
box-shadow: 0px 4.6666666667px 22px 3px cyan;
}
50% {
background: rgba(0, 255, 255, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(0, 255, 255, 0.2);
}
}
@-webkit-keyframes flash-3 {
0%,
100% {
background: #DB1E31;
box-shadow: 0px 4.6666666667px 22px 3px #DB1E31;
}
50% {
background: rgba(219, 30, 49, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(247, 0, 148, 0.5);
}
}
@keyframes flash-3 {
0%,
100% {
background: #DB1E31;
box-shadow: 0px 4.6666666667px 22px 3px #DB1E31;
}
50% {
background: rgba(219, 30, 49, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(247, 0, 148, 0.5);
}
}
<ul class="lightrope">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<br>
<br>
最佳答案
width: 100%;
已从原始 CSS 中删除,这将解决您的问题。另请注意,codepen 似乎在底层使用了“normalize.css”,这将删除某些默认样式,从而导致更多差异。例如,我在 body
中添加了 margin: 0;
以防止出现另一个水平滚动条,并更改了 .lightrope
上的负边距code> 返回其原始值。
body {
margin: 0;
}
.lightrope {
text-align: left;
white-space: nowrap;
overflow: hidden;
position: absolute;
z-index: 1;
margin: -15px 0 0 0;
padding: 0;
padding-left: 0px;
pointer-events: none;
width: 100%
}
.lightrope li {
position: relative;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
list-style: none;
margin: 0;
padding: 0;
display: block;
width: 12px;
height: 16px;
border-radius: 40%;
margin: 20px;
display: inline-block;
background: #00f7a5;
box-shadow: 0px 4.6666666667px 24px 3px #00f7a5;
-webkit-animation-name: flash-1;
animation-name: flash-1;
-webkit-animation-duration: 1.5s;
animation-duration: 1.5s;
}
.lightrope li:nth-child(2n+1) {
background: cyan;
box-shadow: 0px 4.6666666667px 24px 3px rgba(0, 255, 255, 0.5);
-webkit-animation-name: flash-2;
animation-name: flash-2;
-webkit-animation-duration: 0.4s;
animation-duration: 0.4s;
}
.lightrope li:nth-child(4n+2) {
background: #f70094;
box-shadow: 0px 4.6666666667px 24px 3px #f70094;
-webkit-animation-name: flash-3;
animation-name: flash-3;
-webkit-animation-duration: 1.1s;
animation-duration: 1.1s;
}
.lightrope li:nth-child(odd) {
-webkit-animation-duration: 1.8s;
animation-duration: 1.8s;
}
.lightrope li:nth-child(3n+1) {
-webkit-animation-duration: 1.4s;
animation-duration: 1.4s;
}
.lightrope li:before {
content: "";
position: absolute;
background: #222;
width: 10px;
height: 6.3333333333px;
border-radius: 2px;
top: -4.6666666667px;
left: 1px;
}
.lightrope li:after {
content: "";
top: -14px;
left: 9px;
position: absolute;
width: 54px;
height: 18.6666666667px;
border-bottom: solid #222 2px;
border-radius: 50%;
}
.lightrope li:last-child:after {
width: 29px;
}
.lightrope li:first-child {
margin-left: -40px;
}
@-webkit-keyframes flash-1 {
0%,
100% {
background: #00f7a5;
box-shadow: 0px 4.6666666667px 22px 3px #00f7a5;
}
50% {
background: rgba(0, 247, 165, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(0, 247, 165, 0.2);
}
}
@keyframes flash-1 {
0%,
100% {
background: #00f7a5;
box-shadow: 0px 4.6666666667px 22px 3px #00f7a5;
}
50% {
background: rgba(0, 247, 165, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(0, 247, 165, 0.2);
}
}
@-webkit-keyframes flash-2 {
0%,
100% {
background: cyan;
box-shadow: 0px 4.6666666667px 22px 3px cyan;
}
50% {
background: rgba(0, 255, 255, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(0, 255, 255, 0.2);
}
}
@keyframes flash-2 {
0%,
100% {
background: cyan;
box-shadow: 0px 4.6666666667px 22px 3px cyan;
}
50% {
background: rgba(0, 255, 255, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(0, 255, 255, 0.2);
}
}
@-webkit-keyframes flash-3 {
0%,
100% {
background: #DB1E31;
box-shadow: 0px 4.6666666667px 22px 3px #DB1E31;
}
50% {
background: rgba(219, 30, 49, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(247, 0, 148, 0.5);
}
}
@keyframes flash-3 {
0%,
100% {
background: #DB1E31;
box-shadow: 0px 4.6666666667px 22px 3px #DB1E31;
}
50% {
background: rgba(219, 30, 49, 0.4);
box-shadow: 0px 4.6666666667px 22px 3px rgba(247, 0, 148, 0.5);
}
}
<ul class="lightrope">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<br>
<br>
关于html - 限制 LI "Christmas Lights"的数量/宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53283125/