Using css grid for this vertical table, I want the top row height to be larger than the other rows. How can I make it, for example, 100px? I believe grid-template-rows: repeat(4, 25px);
controls the height… but I have not figured out a way to apply that to just a single top row.
body {
font-family: "Benton Sans", "Helvetica Neue", helvetica, arial, sans-serif;
margin: 2em;
}
h1 {
font-style: italic;
color: #373fff;
}
.grid {
display: grid;
grid-auto-flow: column;
grid-template-columns: repeat(auto-fill, minmax(min-content, 1fr));
grid-template-rows: repeat(4, 25px);
border-top: 1px solid black;
border-right: 1px solid black;
}
.grid > span {
padding: 8px 4px;
border-left: 1px solid black;
border-bottom: 1px solid black;
}
.top {
grid-template-rows: repeat(4, 100px);
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello!</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- import the webpage's stylesheet -->
<link rel="stylesheet" href="/style.css">
<!-- import the webpage's javascript file -->
<script src="/script.js" defer></script>
</head>
<body>
<div class="grid">
<span class="top"></span>
<span class="top">name</span>
<span class="top">city</span>
<span class="top">dob</span>
<span>Person 1</span>
<span>Aaron Kris</span>
<span>Philippines</span>
<span>1991-05-23T14:19:51</span>
<span>Person 2</span>
<span>Simeon McLaughlin</span>
<span>Singapore</span>
<span>2012-03-07T00:08:36</span>
<span>Person 3</span>
<span>Kelsie Shanahan</span>
<span>Brazil</span>
<span>1985-03-10T20:13:04</span>
</div>
</body>
</html>
3
Answers
You could use
grid-template-rows: 100px repeat(3, 25px)
.repeat(4, 25px)
is syntactical-sugar for25px 25px 25px 25px
, so you can replace the first25px
for100px
as per your example.You need to add
grid-template-rows: 100px repeat(3, 25px);
property to the grid class and remove the .top class from both css & htmlCSS:
HTML
Change this:
To this:
What you can do is specify the size you want to give to first row and after that add
repeat()
function for remaining rows.For example,
This code will set the height of first row as 50px and after that it will give the remaining 3 lines 25px of height each. Like this, you can add specific height if you want to each of the row that you want to customise.
Another example,
This code will set the height of first row to 50px, then after that next two rows will be set 25px each and last row will be set to 100px of height.
Be careful though when using this. Use this way only if you are absolutely sure of the number of lines in your grid template, otherwise it may create some weird structure or break the ui.