简体   繁体   中英

Title and Universal Selector (*) in Javascript CSS/HTML5

How do I add a title to the following div?

document.write('<div style="width:auto; margin:10px;"><table style="background-color:purple;" 
border="1" cellspacing="1" cellpadding="35">')

Below is the complete script:

<html>
<body>

<script Language="JavaScript">
rows = 6;
cols = 6;

document.write('<div style="width:auto; margin:10px;"><table style="background-color:purple;" 
border="1" cellspacing="1" cellpadding="35">')

/* Not apart of the Table */
//document.write('<h3> <center>Table </center> </h3>')

for (i = 0; i < rows; i++) {
   document.write('<tr>')

   for (j = 0; j < cols; j++)
   {
    document.write('<td style="color:orange;">' + (i*j) + '</td>')
   }
   document.write('</tr>')
}

document.write('</table></div>')

</script>
</body>
</html>

How do I also use a Universal Selector (*) to make all the font size the same?

Just add a <caption> element inside the table:

document.write('<div style="width:auto; margin:10px;"><table style="background-
color:purple;" border="1" cellspacing="1" cellpadding="35"><caption>Title</caption>')

for the * universal selector I believe you want css:

<style type="text/css">
    *{
        font-size: 12px;
    }
</style>

Try this:

var elements = document.getElementsByTagName("*");
for (var i = 0, len = elements.length; i < len; i++) {
    var element = elements[i];
    element.style.fontSize = "20px"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM