After a couple hours of debugging my code, i tried removing the comment and the background-color suddenly was shown.
.announcement-bar1 {
background-color: blue;
width: 100%;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.announcement-text1 {
display: flex;
position: relative;
align-items: center;
justify-content: center;
white-space: nowrap;
background-color: black;
animation: loopText 20s linear infinite;
}
.announcement-text1 span {
margin: 0;
padding: 0 40px;
color: #000;
display: flex;
align-items: center;
justify-content: center;
white-space: nowrap; /* Prevent text from wrapping */
background-color: black;
}
@keyframes loopText {
0% {
transform: translateX(50%);
}
100% {
transform: translateX(-50%);
}
}
vs
(incorrect code)
//*Announcement bar*//
.announcement-bar1 {
background-color: blue;
width: 100%;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.announcement-text1 {
display: flex;
position: relative;
align-items: center;
justify-content: center;
white-space: nowrap;
background-color: black;
animation: loopText 20s linear infinite;
}
.announcement-text1 span {
margin: 0;
padding: 0 40px;
color: #000;
display: flex;
align-items: center;
justify-content: center;
white-space: nowrap; /* Prevent text from wrapping */
background-color: black;
}
@keyframes loopText {
0% {
transform: translateX(50%);
}
100% {
transform: translateX(-50%);
}
}
Why does the first code result in the following .announcement.bar1{} not work?
I tried everything but only removing the comment worked. Not seen this question anywhere so i thought i would post here so people dont run into this frustrating issue.
2
Answers
The correct format for CSS comments is
The extra slashes are not inside the comment, and are making the CSS invalid.
Reference from MDN web docs:
Comments can be placed wherever white space is allowed within a style sheet. They can be used on a single line, or traverse multiple lines.
Correct CSS comment Syntax:
Examples