In fact to tag <marquee>
is considered obsolete in HTML5, because it is an element focused on behavior and appearance, and not on content structure. Therefore, it is recommended that something similar be done with CSS and/or Javascript.
Below is a CSS-only solution, based on an answer in English. Note that the example uses the -prefix-free to make CSS cleaner (this is a JS that adds prefixes to you, so that resources that depend on prefixes, like -webkit
, -moz
and -ms
, operate in the largest possible number of browsers).
.marquee {
width: 100px;
height: 22px;
overflow: hidden;
white-space: nowrap;
border: 1px solid #ccc;
padding: 2px;
}
.marquee span {
display: inline-block;
padding-left: 100%;
animation: marquee 15s linear infinite;
}
@keyframes marquee {
0% {
transform: translate(0, 0);
}
100% {
transform: translate(-100%, 0);
}
}
<div class="marquee"><span>Lorem ipsum dolor sit amet</span></div>
Demonstration
The operation is very simple:
The rules in .marquee
define the appearance of the outer box. Important detail is the white-space: nowrap;
, that keeps the content in a single line.
The rules in .marquee span
push the whole content to the right (so that the empty start), and the basic parameters of the animation (called marquee
), with a duration of 15 seconds and infinite repetition.
@keyframes marquee
sets two key frames for the animation, one with the content in the original position, and the other for the content fully shifted to the left at the end of the animation.
Tip: I could change
translateX(x)
fortranslate(x,y)
, so it could combine with other possible effects and or combinations if necessary :)– Guilherme Nascimento
Yeah, but not anymore?
– bfavaretto
i was editing the comment and reversed the order, the correct would be: change
translate(x,y)
fortranslateX(x)
– Guilherme Nascimento
@Guilhermenascimento Gave laziness to change, but is a +1 in the suggestion.
– bfavaretto