const spans = document.querySelectorAll("span");
const animation = function () {
for (let span of spans) span.classList.toggle("fade");
};
//setInterval(animation, 2400);
.animated {
font-size: 40px;
color: #d1d8e0;
margin-top: 20px;
font-weight: 900;
height: 60px;
line-height: 50px;
}
.animated span {
opacity: 1;
transition: all 0.5s;
}
.animated>.fade {
opacity: 0;
}
@media (max-width: 800px) {
.animated {
height: 70px;
font-size: 25px;
}
}
<div class="animated">
Hey, I'm<br>
<span class="color-primary fade" id="animated-name">Name Name</span>
<span class="color-primary" id="animated-text">Description about something <br>Text & Text</span>
</div>
I am trying to align text to the center of the page and to be responsive for all devices.
I have tried several option but none of them worked:
Trial No.1:
added style="margin:auto;
in the span
Trial No.2:
added style="margin-left:-188;
in the span
Trial No.3:
added style="text-align: center;"
in the div before the span
Trial No.4
added position: absolute;
in the animated span
In the home.html
<div class="animated">
Hey, I'm<br>
<span class="color-primary fade" id="animated-name">Name Name</span>
<span class="color-primary" id="animated-text">Description about something</br>Text &
Text</span>
</div>
In the css
.animated {
font-size: 40px;
color: #d1d8e0;
margin-top: 20px;
font-weight: 900;
height: 60px;
line-height: 50px;
}
.animated span {
opacity: 1;
transition: all 0.5s;
}
.animated>.fade {
opacity: 0;
}
@media (max-width: 800px) {
.animated {
height: 70px;
font-size: 25px;
}
}
In the base.html
<script>
const spans = document.querySelectorAll("span");
const animation = function () {
for (let span of spans) span.classList.toggle("fade");
};
setInterval(animation, 2400);
</script>
My question is how to cetner the text in the span and when there are long sentences similar to the second span to be also centered