问题
I have some text in marquee tag.
<marquee direction="left" scrollamount="4">
Test Test Test Test Test
</marquee>
I am using html 5 and css 3. When i check my html in w3c validator, it shows the following error.
Element marquee not allowed as child of element div in this context. (Suppressing further errors from this subtree.)
<marquee direction="left" scrollamount="4">
How to fix this?
回答1:
Marquee tag is not html5 (is not html at all, but Microsoft proprietary tag from 1995)
you can :
- use javascript to animate your text
- use css animation (not fully browser compatible)
- use css3 marquee (not fully browser compatible)
- use marquee and ignore W3C warning (marquee is full browser compatible, even in iOS safari!)
- don't use marquee effect (it's ugly)
Be careful with W3C validator, it is not always know all W3C specifications !
回答2:
The marquee tag has been made obsolete in HTML5, but has returned in CSS3 (see http://www.w3.org/TR/css3-marquee/).
回答3:
Use CSS3 Marquee instead of it
html
<p class="marquee"><span>This is your sample text.</span></p>
css
/* Make it a marquee */
.marquee {
width: 450px;
margin: 0 auto;
white-space: nowrap;
overflow: hidden;
box-sizing: border-box;
}
.marquee span {
display: inline-block;
padding-left: 100%;
text-indent: 0;
animation: marquee 15s linear infinite;
}
.marquee span:hover {
animation-play-state: paused
}
/* Make it move */
@keyframes marquee {
0% { transform: translate(0, 0); }
100% { transform: translate(-100%, 0); }
}
来源:https://stackoverflow.com/questions/15128716/html-5-marquee-tag-error-in-w3c-validation