I have a webpage designed using CSS Grid. This is how it looks like -
There are certain cases where I want to remove the Username - CSS Grid User such that the rendered page looks like this -
I am using this in a react/redux project. Based on a variable, I have to show/hide the username of the user.
Thus I want to change the number of rows of the grid, I tried making the class display: none like so
.username {
display: none;
}
However, all it does is removes the CSS Grid User string, but the row exists, leaving a blank space.
Is there any way where I would be able to change the number of rows/columns dynamically. I don't want to use CSS in JS solutions. I have a plain CSS file that sets styles to the react component.
.layout {
display: grid;
grid-template-columns: minmax(200px, auto) minmax(200px, 300px) minmax(900px, auto) minmax(200px, auto);
grid-template-rows: 60px 60px 60px minmax(700px, auto);
grid-gap: 5px;
height: calc(100vh);
}
.navbar {
grid-column: 1 / -1;
grid-row: 1 / 2;
background-color: #3a3f51;
border-bottom: 1px solid #797d89;
text-align: center;
color: aliceblue;
}
.username {
grid-column: 1 / -1;
grid-row: 2 / 3;
background-color: #f7f9f9;
border-bottom: 1px solid #dee5e7;
text-align: center;
}
.statement-list {
grid-column: 2 / 3;
grid-row: 3 / 5;
max-height: 600px;
overflow-y: auto;
}
.title {
grid-column: 3 / 4;
grid-row: 3 / 4;
}
.content {
grid-column: 3 / 4;
grid-row: 4 / 5;
overflow-x: auto;
overflow-y: auto;
}
<body class="layout">
<div class="navbar">About</div>
<div class="username">CSS Grid User</div>
<div class="title">Lorem Ipsum</div>
<div class="statement-list">
Phasellus commodo sit amet eros non pharetra. Phasellus consequat augue est, ornare finibus lectus auctor non. Praesent rutrum odio tortor. Proin id massa magna. Phasellus commodo sit amet eros non pharetra. Phasellus consequat augue est, ornare finibus
lectus auctor non. Praesent rutrum odio tortor. Proin id massa magna.
</div>
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean laoreet a odio quis commodo. In nisl justo, tincidunt vel aliquet eget, mollis eget lorem. Aenean sit amet nibh eget nunc sodales vestibulum id ac ante. Nullam eleifend sodales ipsum, sed
porta tellus posuere molestie. Vestibulum congue porta odio sed iaculis. Phasellus varius sodales ullamcorper. Praesent consectetur ante eget turpis pretium, eget sagittis leo volutpat. Aenean posuere, sapien quis placerat pulvinar, lectus est interdum
dui, at pretium risus sapien et neque. Sed eu fringilla turpis. Ut viverra, nisl non euismod sollicitudin, tellus lectus finibus leo, in ornare sem mauris non eros. Fusce augue est, rhoncus vitae tristique in, malesuada nec libero. Sed venenatis vehicula
ultricies. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce interdum auctor ante a fermentum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam malesuada
scelerisque tortor ac faucibus. Integer pharetra eget velit a tempus. Aenean at lobortis massa, vel accumsan ligula.
</div>
</body>

