I’m learning HTML5, very basic level. The objective of the problem is to write a table that looks like this:Final Result.I’m unable to make the divisions on the 3rd column where says crítica 1,crítica2 and so on.
I’ve tried to mess with the rowspan and colspan attributes, but the table messes up and I can’t wrap my head around how to approach this. Also, the space of the image already makes the next row take the same space, so I can’t make it look like it. Please help.
This is where I am:Now
This is my code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<style>
table {
width: 75%;
text-align: center;
border: 6px solid blue;
border-collapse: collapse;
margin-inline: 2px;
font-family: Helvetica;
font-size: 16px;
}
td,
th {
border: 4px solid green;
background-color: lightpink;
}
</style>
<body>
<table>
<caption>
Cartelera
</caption>
<tr>
<th style="background-color: red; text-align: center; color: blue">
Sala 1
</th>
<td>
<a href="https://www.imdb.com/title/tt1454468/"
><img src="imagenes/films/gravity.jpg"
/></a>
</td>
<td>crítica 1</td>
</tr>
<tr>
<th style="background-color: orange; text-align: center; color: blue">
Sala 2
</th>
<td>
<a href="http://www.imdb.com/title/tt1981115/"
><img src="imagenes/films/thor.jpg"
/></a>
</td>
<td>crítica 1</td>
</tr>
</table>
</body>
</html>
2
Answers
You need to structure them as different elements within the element, so you can use
div
s to hold each of them and style them appropriately.In the code below, I have:
div
s inside the<td>
element and assigned different class names,1) HTML
Replace:
with:
2) Add the styles
This will give you your desired look and you can use the classes across the table for all cells of that column.
It is also still semantically correct since
div
s are basically wrapper elements and hold no semantic meaning.You were on the right track. You can do that with
<table>
androwspan
andcolspan
attributes like this:Just make sure that for every
<tr>
elements the column sum up to the same number.