1

How i change the var daynames font-size and color, using css?

var monthNames = [ "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" ]; 

var dayNames= ["Domingo","Segunda-feira","Terça-feira","Quarta-feira","Quinta-feira","Sexta-feira","Sabado"]
var newDate = new Date();

newDate.setDate(newDate.getDate());

$('#Date').html(dayNames[newDate.getDay()] + "<br>" + newDate.getDate() + ' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getFullYear());
0

3 Answers 3

2

You can do this to add font-size and color.

 $('#Date').html("<span style='font-size:28px; color:#ffffff;'>" + dayNames[newDate.getDay()] + "</span><br>" + newDate.getDate() + ' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getFullYear());
Sign up to request clarification or add additional context in comments.

1 Comment

Glad i could help :), accept the answer, which works for you the best. So it may help others
0

You could do something like this JSFiddle

$('.date').html(
    '<span class="dayname">' +dayNames[newDate.getDay()] + '</span><br />' + 
    '<span class="day">' + newDate.getDate() + '</span> ' +
    '<span class="month">' + monthNames[newDate.getMonth()] + '</span> ' +
    '<span class="year">' + newDate.getFullYear() + '</span>'
);

then you can control the styling like this

.dayname {
    color: orange;
    font-size: 32px;
}
.day {
    color: red;
}
.month {
    color: green;
}
.year {
    color: blue;
}

I'm not really sure what you're trying to do here, but its usually smart to avoid inline styles, unless it needs to be dynamic.

Comments

0

try this

var dayNames= ["<p style='color:blue;font-size:10px;'>Domingo</p>",
               "<p style='color:red;font-size:10px;'>Segunda-feira</p>",
               "<p style='color:gray;font-size:10px;'>Terça-feira</p>",
               "<p style='color:yellow;font-size:10px;'>Quarta-feira</p>",
              "<p style='color:red;font-size:10px;'>Quinta-feira</p>",
               "<p style='color:red;font-size:10px;'>Sexta-feira</p>",
              "<p style='color:red;font-size:10px;'>Sabado</p>"]

or

 var style="<p style='color:red;font-size:10px;'>";

 var dayNames= [style+"Domingo</p>",
               style+"Segunda-feira</p>",
               style+"Terça-feira</p>",
               style+"Quarta-feira</p>",
              style+"Quinta-feira</p>",
               style+"Sexta-feira</p>",
              style+"Sabado</p>"]

2 Comments

this is not a good solution, you are mixing HTML with the DATA, the way you had it initially was much better.
@mauriatti heres an example of why you want to separate your data from your html. I was easily able to create something reusable jsfiddle.net/icodeforlove/h8Jh2/6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.