将单词添加到文本滑块的 CSS 中

huangapple go评论60阅读模式
英文:

Add words into a text slider css

问题

I'm struggling to add more words at this slider.
我在尝试在这个滑块上添加更多的词。

Works fine with 3 words but I need 7
与3个单词一起工作正常,但我需要7个。

After changing the html with this one
在使用这个HTML后

There no change and I don't find a way to reach my goal with the CSS 将单词添加到文本滑块的 CSS 中
没有变化,我找不到使用CSS达到目标的方法:(

I don't need background etc ...
我不需要背景等...

In fact I would love to have a div centered on my page with: [My words] Text Slider [My words 2] but with "Text Slider" align left with 7 words (or more) into the slider
事实上,我希望在我的页面上有一个居中的div,上面写着:[我的词] 文本滑块 [我的词2],但“文本滑块”左对齐,其中有7个词(或更多)。

Page test where I'm working on it : https://www.petrescue.do/test/
我正在测试的页面:https://www.petrescue.do/test/

If anyone can help me with this... It would be greatly appreciated
如果有人可以帮助我...将不胜感激。谢谢!

英文:

I'm struggling to add more words at this slider.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

@import url(&#39;https://fonts.googleapis.com/css?family=Roboto:700&#39;);

body {
  margin:0px;
  font-family:&#39;Roboto&#39;;
  text-align:center;
}

#container {
  color:#999;
  text-transform: uppercase;
  font-size:36px;
  font-weight:bold;
  padding-top:200px;  
  position:fixed;
  width:100%;
  bottom:45%;
  display:block;
}

#flip {
  height:50px;
  overflow:hidden;
}

#flip &gt; div &gt; div {
  color:#fff;
  padding:4px 12px;
  height:45px;
  margin-bottom:45px;
  display:inline-block;
}

#flip div:first-child {
  animation: show 5s linear infinite;
}

#flip div div {
  background:#42c58a;
}
#flip div:first-child div {
  background:#4ec7f3;
}
#flip div:last-child div {
  background:#DC143C;
}

@keyframes show {
  0% {margin-top:-270px;}
  5% {margin-top:-180px;}
  33% {margin-top:-180px;}
  38% {margin-top:-90px;}
  66% {margin-top:-90px;}
  71% {margin-top:0px;}
  99.99% {margin-top:0px;}
  100% {margin-top:-270px;}
}

p {
  position:fixed;
  width:100%;
  bottom:30px;
  font-size:12px;
  color:#999;
  margin-top:200px;
}

<!-- language: lang-html -->

&lt;div id=container&gt;
  Make 
  &lt;div id=flip&gt;
    &lt;div&gt;&lt;div&gt;wOrK&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;lifeStyle&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;Everything&lt;/div&gt;&lt;/div&gt;
  &lt;/div&gt;
  AweSoMe!
&lt;/div&gt;

&lt;p&gt;a css3 animation demo&lt;/p&gt;

<!-- end snippet -->

Works fine with 3 words but I need 7

After changing the html with this one

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

@import url(&#39;https://fonts.googleapis.com/css?family=Roboto:700&#39;);

body {
  margin:0px;
  font-family:&#39;Roboto&#39;;
  text-align:center;
}

#container {
  color:#999;
  text-transform: uppercase;
  font-size:36px;
  font-weight:bold;
  padding-top:200px;  
  position:fixed;
  width:100%;
  bottom:45%;
  display:block;
}

#flip {
  height:50px;
  overflow:hidden;
}

#flip &gt; div &gt; div {
  color:#fff;
  padding:4px 12px;
  height:45px;
  margin-bottom:45px;
  display:inline-block;
}

#flip div:first-child {
  animation: show 5s linear infinite;
}

#flip div div {
  background:#42c58a;
}
#flip div:first-child div {
  background:#4ec7f3;
}
#flip div:last-child div {
  background:#DC143C;
}

@keyframes show {
  0% {margin-top:-270px;}
  5% {margin-top:-180px;}
  33% {margin-top:-180px;}
  38% {margin-top:-90px;}
  66% {margin-top:-90px;}
  71% {margin-top:0px;}
  99.99% {margin-top:0px;}
  100% {margin-top:-270px;}
}

p {
  position:fixed;
  width:100%;
  bottom:30px;
  font-size:12px;
  color:#999;
  margin-top:200px;
}

<!-- language: lang-html -->

&lt;div id=container&gt;
  Make 
  &lt;div id=flip&gt;
    &lt;div&gt;&lt;div&gt;wOrK&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;lifeStyle&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;Everything&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;wOrK2&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;lifeStyle2&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;Everything2&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;wOrK3&lt;/div&gt;&lt;/div&gt;
  &lt;/div&gt;
  AweSoMe!
&lt;/div&gt;

<!-- end snippet -->

There no change and I don't find a way to reach my goal with the CSS 将单词添加到文本滑块的 CSS 中

I don't need background etc ...

In fact I would love to have a div centered on my page with:
[My words] Text Slider [My words 2]
but with "Text Slider" align left with 7 words (or more) into the slider

Page test where I'm working on it : https://www.petrescue.do/test/

If anyone can help me with this... It would be greatly appreciated
Thanks in advance

答案1

得分: 2

以下是已翻译的代码部分:

@keyframes show {
  0%, 12%, 100% {margin-top:-630px;}
  13%, 25% {margin-top:-540px;}
  26%, 38% {margin-top:-450px;}
  39%, 41% {margin-top:-360px;}
  42%, 54% {margin-top:-270px;}
  55%, 67% {margin-top:-180px;}
  68%, 80% {margin-top:-90px;}
  99.99% {margin-top:0px;}
}

如果需要进一步的翻译或说明,请告诉我。

英文:

The reason this is happening is because of this code:

@keyframes show {
  0% {margin-top:-270px;}
  5% {margin-top:-180px;}
  33% {margin-top:-180px;}
  38% {margin-top:-90px;}
  66% {margin-top:-90px;}
  71% {margin-top:0px;}
  99.99% {margin-top:0px;}
  100% {margin-top:-270px;}
}

You are only changing the margin-top to have 3 different values. To see what I mean, I've removed the overflow:hidden and added a red border to the #flip element so you can see what is happening.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

@import url(&#39;https://fonts.googleapis.com/css?family=Roboto:700&#39;);

body {
  margin:0px;
  font-family:&#39;Roboto&#39;;
  text-align:center;
}

#container {
  color:#999;
  text-transform: uppercase;
  font-size:36px;
  font-weight:bold;
  padding-top:200px;  
  position:fixed;
  width:100%;
  bottom:45%;
  display:block;
}

#flip {
  height:50px;
  /*overflow:hidden;*/
  border: 1px solid red;
}

#flip &gt; div &gt; div {
  color:#fff;
  padding:4px 12px;
  height:45px;
  margin-bottom:45px;
  display:inline-block;
}

#flip div:first-child {
  animation: show 5s linear infinite;
}

#flip div div {
  background:#42c58a;
}
#flip div:first-child div {
  background:#4ec7f3;
}
#flip div:last-child div {
  background:#DC143C;
}

@keyframes show {
  0% {margin-top:-270px;}
  5% {margin-top:-180px;}
  33% {margin-top:-180px;}
  38% {margin-top:-90px;}
  66% {margin-top:-90px;}
  71% {margin-top:0px;}
  99.99% {margin-top:0px;}
  100% {margin-top:-270px;}
}

p {
  position:fixed;
  width:100%;
  bottom:30px;
  font-size:12px;
  color:#999;
  margin-top:200px;
}

<!-- language: lang-html -->

&lt;div id=container&gt;
  Make 
  &lt;div id=flip&gt;
    &lt;div&gt;&lt;div&gt;wOrK&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;lifeStyle&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;Everything&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;wOrK2&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;lifeStyle2&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;Everything2&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;wOrK3&lt;/div&gt;&lt;/div&gt;
  &lt;/div&gt;
  AweSoMe!
&lt;/div&gt;

<!-- end snippet -->


To fix this you will need to add the other margin-top offset positions. Probably something like this:

@keyframes show {
  0%, 12%, 100% {margin-top:-630px;}
  13%, 25% {margin-top:-540px;}
  26%, 38% {margin-top:-450px;}
  39%, 41% {margin-top:-360px;}
  42%, 54% {margin-top:-270px;}
  55%, 67% {margin-top:-180px;}
  68%, 80% {margin-top:-90px;}
  99.99% {margin-top:0px;}
}

It's not perfect, but you get the idea. You'll have to play with the timings on it. FYI, you'll notice you can use multiple percentages to have the same value, this way you don't need to repeat the value in the keyframe animation.

See it kinda-working below

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

@import url(&#39;https://fonts.googleapis.com/css?family=Roboto:700&#39;);

body {
  margin:0px;
  font-family:&#39;Roboto&#39;;
  text-align:center;
}

#container {
  color:#999;
  text-transform: uppercase;
  font-size:36px;
  font-weight:bold;
  padding-top:200px;  
  position:fixed;
  width:100%;
  bottom:45%;
  display:block;
}

#flip {
  height:50px;
  overflow:hidden;
}

#flip &gt; div &gt; div {
  color:#fff;
  padding:4px 12px;
  height:45px;
  margin-bottom:45px;
  display:inline-block;
}

#flip div:first-child {
  animation: show 10s linear infinite;
}

#flip div div {
  background:#42c58a;
}
#flip div:first-child div {
  background:#4ec7f3;
}
#flip div:last-child div {
  background:#DC143C;
}

@keyframes show {
  0%, 12%, 100% {margin-top:-630px;}
  13%, 25% {margin-top:-540px;}
  26%, 38% {margin-top:-450px;}
  39%, 41% {margin-top:-360px;}
  42%, 54% {margin-top:-270px;}
  55%, 67% {margin-top:-180px;}
  68%, 80% {margin-top:-90px;}
  99.99% {margin-top:0px;}
}

<!-- language: lang-html -->

&lt;div id=container&gt;
  Make 
  &lt;div id=flip&gt;
    &lt;div&gt;&lt;div&gt;wOrK&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;lifeStyle&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;Everything&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;wOrK2&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;lifeStyle2&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;Everything2&lt;/div&gt;&lt;/div&gt;
    &lt;div&gt;&lt;div&gt;wOrK3&lt;/div&gt;&lt;/div&gt;
  &lt;/div&gt;
  AweSoMe!
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月7日 05:43:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76191287.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定