List (UL/LI) displayed as grid - responsive (with Bootstrap) - html

Is there any way that I can create a gallery like this
on bootstrap using an unordered list? I've accomplished that look with the column system but I really needed to use li items for this project.
So basically I want to create a list displayed as a grid. And it needs to be responsive as well. I want it turn into a one-column on mobile:
The reason why I want to use ul/li is because I'll be using wordpress and would like to use the wp_list_pages function.
This might be very easy but I just can't think of a solution that doesn't involve workarounds.
Thanks!

This is easier if use CSS Grids:
.gallary{
margin-top:50px;
width:80%;
height:100%;
display: grid;
grid-template-columns: 1fr 0.5fr 1fr;
grid-template-rows: 300px 200px;
}
.area1{
grid-column: 1/2;
grid-row: 1/2 ;
background-color: blue;
}
.area2{
grid-column: 2/4;
grid-row: 1/1;
background-color: yellow;
}
.area3{
grid-column: 1/2;
grid-row: 2/2;
background-color: green;
}
.area4{
grid-column: 2/3;
grid-row: 2/2;
background-color: orange;
}
.area5{
grid-column: 3/4;
grid-row: 2/2;
background-color: purple;
}
#media (max-width: 650px) {
.gallary{
margin-top:50px;
width:100%;
height:100%;
display: grid;
grid-template-columns: 100%;
grid-template-rows: 1fr 1fr 1fr 1fr 1fr;
}
.area1{
grid-column: 1/-1;
grid-row: 1/2 ;
background-color: blue;
}
.area2{
grid-column: 1/-1;
grid-row: 2/3 ;
background-color: yellow;
}
.area3{
grid-column: 1/-1;
grid-row: 3/4 ;
background-color: green;
}
.area4{
grid-column: 1/-1;
grid-row: 4/5 ;
background-color: orange;
}
.area5{
grid-column: 1/-1;
grid-row: 5/6;
background-color: purple;
}
}
<div class="gallary">
<div class="area1">AAA</div>
<div class="area2">AAA</div>
<div class="area3">AAA</div>
<div class="area4">AAA</div>
<div class="area5">AAA</div>
</div>

Related

Why is there a huge gap on the grid I created?

Im learning how to use grid container and so far i created a grid with 2 images on top and 2 on the bottom and then 1 to the left side that stretches vertically. I have the grid how i want it, however i cannot get rid of the huge gap in between each image. I tried adjusting the grid gap and even got rid of it but it does not change nothing at all. How can i fix this problem?
Thanks
.PopDestination-Header{
text-align: center;
margin: 100px;
}
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(4, 1fr);
}
.grid-item-1 {
grid-column: 1/2;
grid-row: 1/3;
}
.grid-item-2 {
grid-column: 2/3;
grid-row: 1/2;
}
.grid-item-3 {
grid-column: 3/4;
grid-row: 1/2;
}
.grid-item-4 {
grid-column: 2/3;
grid-row: 3/4;
}
.grid-item-5 {
grid-column: 3/4;
grid-row: 3/4;
}
<section class="PopularDestination">
<div class="PopDestination-Header">
<h1>Popular Destination</h1>
</div>
<div class="grid-container">
<div class="grid-item-1"><img src ="Images/meric-dagli-CK_MX9mBGRo-unsplash.jpg" height="700" width="350"></div>
<div class="grid-item-2"><img src ="Images/doug-watanabe-9uiUGnGeeUo-unsplash.jpg" height="350" width="500"></div>
<div class="grid-item-3"><img src ="Images/ryan-stone-VnZMKbXrA0I-unsplash.jpg" height="350" width="500"></div>
<div class="grid-item-4"><img src ="Images/clay-elliot-3xJAVC07AYk-unsplash.jpg" height="350" width="500"></div>
<div class="grid-item-5"><img src ="Images/mike-dierken-KmA5OdUkAj8-unsplash.jpg" height="350" width="500"></div>
</div>
</section>
.grid-item-4 {
grid-column: 2/3;
/* grid-row: 3/4; */
grid-row: 2/3;
}
.grid-item-5 {
grid-column: 3/4;
/* grid-row: 3/4; */
grid-row: 2/3;
}
I edited your code like below. I hope it works for you. While running code snippet please make full screen for right view.
.PopDestination-Header{
text-align: center;
margin: 100px;
}
.grid-container {
display: grid;
grid-template-columns: auto auto auto;
grid-template-rows: auto;
grid-column-gap: 30px;
grid-row-gap: 30px;
justify-content: center;
}
.grid-item-1 {
grid-column: 1/2;
grid-row: 1/4;
}
.grid-item-2 {
grid-column: 2/3;
grid-row: 1/2;
}
.grid-item-3 {
grid-column: 3/3;
grid-row: 1/2;
}
.grid-item-4 {
grid-column: 2/3;
grid-row: 2/2;
}
.grid-item-5 {
grid-column: 3/3;
grid-row: 2/2;
}
<section class="PopularDestination">
<div class="PopDestination-Header">
<h1>Popular Destination</h1>
</div>
<div class="grid-container">
<div class="grid-item-1"><img src ="https://picsum.photos/211" height="700" width="350"></div>
<div class="grid-item-2"><img src ="https://picsum.photos/222" height="350" width="500"></div>
<div class="grid-item-3"><img src ="https://picsum.photos/256" height="350" width="500"></div>
<div class="grid-item-4"><img src ="https://picsum.photos/247" height="350" width="500"></div>
<div class="grid-item-5"><img src ="https://picsum.photos/265" height="350" width="500"></div>
</div>
</section>
Gaps columns and rows looks like this in chrome browser:
Try this
.grid-container {
max-width: min-content;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(4, 1fr);
}

CSS Grid - can we adjust the gap according to rows?

I am trying to recreate a Mondrian painting.
.wrapper {
width: 600px;
height: 600px;
background: url(painting.png) no-repeat;
display: grid;
grid-gap: 40px 20px;
grid-template-rows: 178px 219px 61px 63px;
grid-template-columns: 128px 392px 44px;
}
div {
border: 1px solid black;
background-color: white;
opacity: 0.5;
}
.a {
grid-row: 1/2;
grid-column: 1/2;
}
.b {
grid-row: 2/3;
grid-column: 1/2;
}
.c {
grid-row: 1/3;
grid-column: 2/4;
}
.d {
grid-row: 3/5;
grid-column: 1/2;
}
.e {
grid-row: 3/5;
grid-column: 2/3;
}
.f {
grid-row: 3/4;
grid-column: 3/4;
}
<body>
<div class="wrapper">
<div class="a">a</div>
<div class="b">b</div>
<div class="c">c</div>
<div class="d">d</div>
<div class="e">e</div>
<div class="f">f</div>
<div class="g">g</div>
</div>
</body>
I pretty much nailed it withe layout. The problem is that between the rows there are different values of gaps. So on one there is e.g. 24px and other 40px. Is there a way a can apply different values on gaps on different rows. Or should I be satisfied with this existing one.
Thank you!
You can't have multiple gap sizes in a single grid.
A workaround would be to use the lowest size of gap for the grid, and complement it with margins whenever needed:
.wrapper {
width: 600px;
height: 600px;
background: url(painting.png) no-repeat;
display: grid;
grid-gap: 20px 20px;
grid-template-rows: 178px 219px 61px 63px;
grid-template-columns: 128px 392px 44px;
}
div {
border: 1px solid black;
background-color: blue;
opacity: 0.5;
}
.a {
grid-row: 1/2;
grid-column: 1/2;
margin-bottom: 20px;
}
.b {
grid-row: 2/3;
grid-column: 1/2;
}
.c {
grid-row: 1/3;
grid-column: 2/4;
}
.d {
grid-row: 3/5;
grid-column: 1/2;
}
.e {
grid-row: 3/5;
grid-column: 2/3;
}
.f {
grid-row: 3/4;
grid-column: 3/4;
}
<body>
<div class="wrapper">
<div class="a">a</div>
<div class="b">b</div>
<div class="c">c</div>
<div class="d">d</div>
<div class="e">e</div>
<div class="f">f</div>
<div class="g">g</div>
</div>
</body>

Css grid lines layout

I'm trying to create this layout
I have this aurelia template
And this CSS rules
#containerPlanner {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(4, 1fr);
}
#cabecera {
display: flex;
grid-column: 1/4;
grid-row: 1;
grid-area: cabecera;
}
#resumen {
grid-column: 1;
grid-row: 2;
border: 2px solid black;
background-color: aqua;
grid-area: resumen;
}
#grafica {
grid-column: 2/4;
grid-row: 2;
border: 2px solid black;
background-color: yellow;
grid-area: grafica;
}
#opciones {
display: flex;
grid-column: 1/4;
grid-row: 3;
grid-area: opciones;
}
#datos {
grid-column: 1/4;
grid-row: 4;
grid-area: datos;
}
But the result is this
I don't understand why the resumen section occupies the entire width of the screen if it has grid-column:1.
And the same with grafica section
Any idea please?
Regards

Placing the footer out of view using CSS grid

I have a header that is 70px high, the main content which I want to fill the rest of the screen and then a 70px footer. I am trying to find the most simple approach of hiding a footer. This works with the footer in view - see jsfiddle and snippet below:
* {
margin: 0;
padding: 0;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
display: grid;
margin: 0px;
grid-gap: 10px;
height: 100vh;
grid-template-columns: [side__nav] 250px [main] 1fr;
grid-template-rows: [header] 70px auto [footer] 70px;
}
.header {
grid-column: main;
grid-row: 1;
background: pink;
}
.side__nav {
grid-column: side__nav;
grid-row: 1/span 3;
background: red;
}
.content {
grid-column: main;
grid-row: 2;
background: green;
}
.footer {
grid-column: main;
grid-row: 3;
background: purple;
opacity: 0.5;
}
.a {
grid-column: col/span 2;
grid-row: row;
}
.b {
grid-column: col 3/span 2;
grid-row: row;
}
.c {
grid-column: col/span 2;
grid-row: row 2;
}
.d {
grid-column: col 3/span 2;
grid-row: row 2;
display: grid;
grid-gap: 10px;
grid-template-columns: 1fr 1fr;
}
.e {
grid-column: 1/3;
grid-row: 1;
}
.f {
grid-column: 1;
grid-row: 2;
}
.g {
grid-column: 2;
grid-row: 2;
}
<header class="header">header</header>
<nav class="side__nav">side__nav</nav>
<content class="content">content</content>
<footer class="footer">footer</footer>
But I want to push it off screen so I can use a button to show when needed. I have tried using grid-template-rows: [header] 70px calc(100vh - 70px) [footer] 70px
which does give me the effect I want see jsfiddle and snippet below:
* {
margin: 0;
padding: 0;
}
*, *::before, *::after {
box-sizing: border-box;
}
body {
display: grid;
margin: 0px;
grid-gap: 10px;
height: 100vh;
grid-template-columns: [side__nav] 250px [main] 1fr;
grid-template-rows: [header] 70px calc(100vh - 70px) [footer] 70px;
}
.header {
grid-column: main;
grid-row: 1;
background: pink;
}
.side__nav {
grid-column: side__nav;
grid-row: 1/span 3;
background: red;
}
.content {
grid-column: main;
grid-row: 2;
background: green;
}
.footer {
grid-column: main;
grid-row: 3;
background: purple;
opacity: 0.5;
}
.a {
grid-column: col/span 2;
grid-row: row;
}
.b {
grid-column: col 3/span 2;
grid-row: row;
}
.c {
grid-column: col/span 2;
grid-row: row 2;
}
.d {
grid-column: col 3/span 2;
grid-row: row 2;
display: grid;
grid-gap: 10px;
grid-template-columns: 1fr 1fr;
}
.e {
grid-column: 1/3;
grid-row: 1;
}
.f {
grid-column: 1;
grid-row: 2;
}
.g {
grid-column: 2;
grid-row: 2;
}
<header class="header">header</header>
<nav class="side__nav">side__nav</nav>
<content class="content">content</content>
<footer class="footer">footer</footer>
But the problem with that is, If I use grid-gap: 10px I have to
calculate that in grid-template-rows which then gets messy if I add
more sections.
For instance, 3 sections will have 2 gaps, if I set the gap as 10px, the total will be 20px, plus the 70px for the footer meaning a total of 90px. If someone takes over the code they need to know that they need to add this manually to the grid-template-row line which I know will get missed. Anyone have a simple idea that I am missing?
You can remove your footer from the explicit grid (change your explicit grid row definition into grid-template-rows: [header] 70px 1fr and remove grid-row: 3 from footer) and set the grid container height to calc(100vh + 70px) and set the implicit grid row (which is your footer height) using grid-auto-rows: 70px.
See demo below with vanilla CSS:
* {
margin: 0;
padding: 0;
}
*, *::before, *::after {
box-sizing: border-box;
}
body {
display: grid;
margin: 0px;
grid-gap: 10px;
height: calc(100vh + 70px); /* adding footer height */
grid-template-columns: [side__nav] 250px [main] 1fr;
grid-template-rows: [header] 70px 1fr; /* removed footer from here */
grid-auto-rows: 70px; /* implicit grid height - footer height */
}
.header {
grid-column: main;
grid-row: 1;
background: pink;
}
.side__nav {
grid-column: side__nav;
grid-row: 1/span 3;
background: red;
}
.content {
grid-column: main;
grid-row: 2;
background: green;
}
.footer {
grid-column: main;
/*grid-row: 3;*/
background: purple;
opacity: 0.5;
}
.a {
grid-column: col/span 2;
grid-row: row;
}
.b {
grid-column: col 3/span 2;
grid-row: row;
}
.c {
grid-column: col/span 2;
grid-row: row 2;
}
.d {
grid-column: col 3/span 2;
grid-row: row 2;
display: grid;
grid-gap: 10px;
grid-template-columns: 1fr 1fr;
}
.e {
grid-column: 1/3;
grid-row: 1;
}
.f {
grid-column: 1;
grid-row: 2;
}
.g {
grid-column: 2;
grid-row: 2;
}
<header class="header">header</header>
<nav class="side__nav">side__nav</nav>
<content class="content">content</content>
<footer class="footer">footer</footer>
But again you'll have to do those messy calculations when new sections are added to the grid. A more dynamic option is to keep a grid item (zero-width adjuster element in demo below) just for setting the layout height:
placed in the first column and spanned across the first two rows
has height: 100vh set and pushed behind with z-index: -1 so that it doesn't affect the layout.
See demo below:
* {
margin: 0;
padding: 0;
}
*, *::before, *::after {
box-sizing: border-box;
}
body {
display: grid;
margin: 0px;
grid-gap: 10px;
grid-template-columns: [side__nav] 250px [main] 1fr;
grid-template-rows: [header] 70px 1fr; /* removed footer from here */
grid-auto-rows: 70px; /* implicit grid height - footer height */
}
.header {
grid-column: main;
grid-row: 1;
background: pink;
}
.side__nav {
grid-column: side__nav;
grid-row: 1/span 3;
background: red;
}
.content {
grid-column: main;
grid-row: 2;
background: green;
}
.footer {
grid-column: main;
/*grid-row: 3;*/
background: purple;
opacity: 0.5;
}
.a {
grid-column: col/span 2;
grid-row: row;
}
.b {
grid-column: col 3/span 2;
grid-row: row;
}
.c {
grid-column: col/span 2;
grid-row: row 2;
}
.d {
grid-column: col 3/span 2;
grid-row: row 2;
display: grid;
grid-gap: 10px;
grid-template-columns: 1fr 1fr;
}
.e {
grid-column: 1/3;
grid-row: 1;
}
.f {
grid-column: 1;
grid-row: 2;
}
.g {
grid-column: 2;
grid-row: 2;
}
.adjuster { /* grid items spanning two rows with explicit height set */
width: 0;
position: relative;
z-index: -1;
grid-column: 1;
grid-row: 1 / span 2;
height: 100vh;
}
section { /* new sections added*/
background: cadetblue;
}
<header class="header">header</header>
<nav class="side__nav">side__nav</nav>
<content class="content">content</content>
<footer class="footer">footer</footer>
<!-- height adjuster for viewport -->
<span class="adjuster"></span>
<!-- other page sections below -->
<section></section>
<section></section>
Excerpts on implicit and explicit grids from MDN:
The implicit and explicit grid (MDN)
If you place something outside of the defined grid—or due to the
amount of content, more grid tracks are needed—then the grid creates
rows and columns in the implicit grid. These tracks will be auto-sized
by default, resulting in their size being based on the content that is
inside them.
You can also define a set size for tracks created in the implicit grid
with the grid-auto-rows and grid-auto-columns properties.
You can read more about Explicit and Implicit Grids here: CSS Grid unwanted column added automatically

Grid layout using grid-column and grid-row

I am using the grid rows and column. I am getting the issue at the last element. I need the second row with equal height and width. So I tried below code.
expected output is
I am getting the output
.content {
display: grid;
margin: 0 auto;
grid-template-columns: repeat(5, 1fr);
grid-auto-rows: minmax(150px, auto);
grid-gap: 10px;
}
.content div {
background-color: #333;
padding: 30px;
color: #fff;
}
.one {
grid-column: 1/4;
grid-row: 1/3
}
.two {
grid-column: 4/6;
grid-row: 1/3;
}
.three {
grid-column: 1/3;
grid-row: 3/5
}
.four {
grid-column: 3/5;
grid-row: 3/5;
}
.five {
grid-column: 5/6;
grid-row: 3/5;
}
<div class="content">
<div class="one">1</div>
<div class="two">2</div>
<div class="three">3</div>
<div class="four">4</div>
<div class="five">5</div>
</div>
You used the number 5 which make it difficult to divide by 3. Use 15 for example and you can easily divide it by 3 and for the first row you will have 9 + 6 instead of 3 + 2
.content {
display: grid;
margin: 0 auto;
grid-template-columns: repeat(15, 1fr);
grid-auto-rows: minmax(150px, auto);
grid-gap: 10px;
}
.content div {
background-color: #333;
padding: 30px;
color: #fff;
}
.one {
grid-column: 1/10;
grid-row: 1/3
}
.two {
grid-column: 10/16;
grid-row: 1/3;
}
.three {
grid-column: 1/6;
grid-row: 3/5
}
.four {
grid-column: 6/11;
grid-row: 3/5;
}
.five {
grid-column: 11/16;
grid-row: 3/5;
}
<div class="content">
<div class="one">1</div>
<div class="two">2</div>
<div class="three">3</div>
<div class="four">4</div>
<div class="five">5</div>
</div>
UPDATE
As per the OP comments, this is the correct output needed:
.content {
display: grid;
margin: 0 auto;
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: minmax(150px, auto);
grid-gap: 10px;
}
.content div {
background-color: #333;
padding: 30px;
color: #fff;
}
.one {
grid-column: 1/3;
grid-row: 1/3
}
.two {
grid-column: 3/4;
grid-row: 1/3;
}
.three {
grid-column: 1/2;
grid-row: 3/5
}
.four {
grid-column: 2/3;
grid-row: 3/5;
}
.five {
grid-column: 3/4;
grid-row: 3/5;
}
<div class="content">
<div class="one">1</div>
<div class="two">2</div>
<div class="three">3</div>
<div class="four">4</div>
<div class="five">5</div>
</div>