0

How to move <h2> to center? I tried so many times :( :(

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Table 02</title> </head> <body> <!DOCTYPE html> <html> <head> <style> table { text-align: center; font-family: arial, sans-serif; border-collapse: collapse; width: 100%; } td, th { background-color: yellow; text-align: center; border: 1px solid grey; text-align: left; padding: 8px; } td, th{ text-align: center; } tr:nth-child{ background-color: yellow; } </style> </head> <body> <h2>HTML Table Sample 02</h2> <table> <tr> <th>Full Name</th> <th>Sex</th> <th>Age</th> <th>City</th> </tr> <tr> <td>Kiyoshi Teppei</td> <td>M</td> <td>18</td> <td>Tokyo</td> </tr> <tr> <td>Kagami Tiga</td> <td>M</td> <td>17</td> <td>Berlin</td> </tr> <tr> <td>Riko Aida</td> <td>F</td> <td>16</td> <td>Moscow</td> </tr> <tr> <td>Aomine Daiki</td> <td>M</td> <td>17</td> <td>Denver</td> </tr> </table> </body> </html> </body> </html>

6th Dec 2019, 4:16 AM
Kaisang Tamang
Kaisang Tamang - avatar
5 odpowiedzi
+ 2
1. <style> tag should be placed in <head> and not in the <body> tag. 2. For aligning <h2> to center use text-align: center in your <style> tag as: h2{text-align: center;} 3. When you have already written td,th{} once then why are you repeating it. Write all the style code in same td,th{} block.
6th Dec 2019, 4:21 AM
Chetali Shah
Chetali Shah - avatar
+ 2
DOCTYPE is only declared once at the top of the document. There is only one <html> and <body> block. Not multiples as you demonstrated above.
6th Dec 2019, 9:23 AM
Xyenia 🦉
Xyenia 🦉 - avatar
+ 1
Thank You Mate ^_^ Thanks A lot
6th Dec 2019, 4:33 AM
Kaisang Tamang
Kaisang Tamang - avatar
+ 1
none of you code told h2 to go to the center try: h2 { text-align: center; } also, why do you have multiple doctypes and <html> <head> and <body> tags?
7th Dec 2019, 4:58 PM
Joshua
0
Joshua hehe I was little nervous so I couldn't see that doubles 🙈🙈🙈
10th Dec 2019, 2:35 AM
Kaisang Tamang
Kaisang Tamang - avatar