I’m trying to implement a table in html with a Vue framework. I can modify a size variable with v-model, which changes the number of rows AND columns (the table must have the same number of rows and columns).
My problem is that I would want to make it so that it is displayed in the same size whether it is at the minimum number of rows and columns (which is 2) or it is at maximum rows and columns (which is 10). However I’m struggling when it comes to implementing this in CSS because I’m finding that at a certain amount the table gets bigger than at the beginning, and also it never starts being a square, it is always stretched.
This is the HTML of the table section:
`<section class="arena-preview">
<table>
<tr v-for="row in this.size">
<td v-for="column in this.size"></td>
</tr>
</table>
</section>`
//And this is the corresponding CSS:
@media only screen and (min-width: 768px) {
.arena-preview {
flex: 3;
max-width: 60%;
overflow-x: auto;
}
}
.arena-preview {
display: flex;
justify-content: center;
align-content: center;
flex: 100%;
box-sizing: border-box;
}
table {
width: 80%;
}
table, th, td {
border: 1px solid;
border-collapse: collapse;
}
th, td {
padding: 15px;
}
td {
max-width: 40px;
max-height: 40px;
}
I was expecting to fix the td size so that it would at least display as a square instead of a rectangle but I don’t think you can fix the height in CSS. As you can see I’m pretty inexperienced with CSS so if there’s a solution to my problem I would appreciate an explanation.
Thanks in advance!
2
Answers
updated CSS
Next, assign the
--size
variable to a CSS custom property in your Vue template:The width and height of the table’s cells are determined in this case using the
--size
variable. To fit your layout, adjust the table’s width and other elements as necessary.Simply changing the table css to something like
Does the job, then, depending on your cells content you could use some position:absolute in a container inside to prevent the cells from changing size depending on content.