Reputation: 1490
I am using grid framework in css for that using following code
.grid {
display: grid;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
grid-gap: 8px;
@media (min-width: 1440px) {
grid-gap: 12px;
}
@media (min-width: 1920px) {
grid-gap: 16px;
}
grid-template-columns: repeat(12, 1fr);
margin-left: 0;
margin-right: 0
}
.grid-col {
padding-left: 0;
padding-right: 0;
width: auto
}
.grid-row-1 {
grid-row: span 1
}
.grid-row-2 {
grid-row: span 2
}
.grid-row-3 {
grid-row: span 3
}
.grid-col-1 {
grid-column: span 1
}
.grid-col-2 {
grid-column: span 2
}
.grid-col-3 {
grid-column: span 3
}
.grid-col-4 {
grid-column: span 4
}
.grid-col-5 {
grid-column: span 5
}
.grid-col-6 {
grid-column: span 6
}
.grid-col-7 {
grid-column: span 7
}
.grid-col-8 {
grid-column: span 8
}
.grid-col-9 {
grid-column: span 9
}
.grid-col-10 {
grid-column: span 10
}
.grid-col-11 {
grid-column: span 11
}
.grid-col-12 {
grid-column: span 12
}
Here is demo link https://jsfiddle.net/vedankita/yrd5p79v/
My problem is I am not able to center align columns using grid structure. I don't want to use flex I have to achieve this using grid. I want result like this. Result using diplay inline-block Please help me in this.
Upvotes: 0
Views: 149
Reputation: 747
You can use this code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Hello, world!</title>
<style type="text/css">
body {
margin: 0;
}
* {
box-sizing: border-box;
}
.main {
border: 2px solid #f76707;
border-radius: 5px;
background-color: #fff4e6;
text-align: center;
}
.main>.box {
border: 2px solid #ffa94d;
border-radius: 5px;
background-color: #ffd8a8;
padding: 1em;
color: #d9480f;
display: inline-block;
}
.c-book-tile {
text-align: center;
font-size: 15px;
}
</style>
</head>
<body>
<div class="container">
<div class="main">
<div class="box"><a href="#" class="c-book-tile">Lorem ipsum</a></div>
<div class="box"><a href="#" class="c-book-tile">Lorem ipsum</a></div>
<div class="box"><a href="#" class="c-book-tile">Lorem ipsum</a></div>
<div class="box"><a href="#" class="c-book-tile">Lorem ipsum</a></div>
<div class="box"><a href="#" class="c-book-tile">Lorem ipsum</a></div>
<div class="box"><a href="#" class="c-book-tile">Lorem ipsum</a></div>
<div class="box"><a href="#" class="c-book-tile">Lorem ipsum</a></div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
Upvotes: 0
Reputation: 4459
Can you try with following code, hope it will work for you. here the align of content is set center as vertically and horizontally, and min-height is just for the checking the things work correctly.
Demo Link: https://jsfiddle.net/yudizsolutions/gmrj0nfk/1/
.grid {
display: grid;
grid-gap: 8px;
@media (min-width: 1440px) {
grid-gap: 12px;
}
@media (min-width: 1920px) {
grid-gap: 16px;
}
grid-template-columns: repeat(12, 1fr);
margin-left: 0;
margin-right: 0
}
.grid-col {
padding: 10px;
width: auto;
background: #888;
color: #fff;
display: grid;
justify-items: center;
min-height: 150px;
align-items: center;
}
.grid-row-1 {
grid-row: span 1
}
.grid-row-2 {
grid-row: span 2
}
.grid-row-3 {
grid-row: span 3
}
.grid-col-1 {
grid-column: span 1
}
.grid-col-2 {
grid-column: span 2
}
.grid-col-3 {
grid-column: span 3
}
.grid-col-4 {
grid-column: span 4
}
.grid-col-5 {
grid-column: span 5
}
.grid-col-6 {
grid-column: span 6
}
.grid-col-7 {
grid-column: span 7
}
.grid-col-8 {
grid-column: span 8
}
.grid-col-9 {
grid-column: span 9
}
.grid-col-10 {
grid-column: span 10
}
.grid-col-11 {
grid-column: span 11
}
.grid-col-12 {
grid-column: span 12
}
@media only screen and (min-width:480px) {
.grid-col-xs-1 {
grid-column: span 1
}
.grid-col-xs-2 {
grid-column: span 2
}
.grid-col-xs-3 {
grid-column: span 3
}
.grid-col-xs-4 {
grid-column: span 4
}
.grid-col-xs-5 {
grid-column: span 5
}
.grid-col-xs-6 {
grid-column: span 6
}
.grid-col-xs-7 {
grid-column: span 7
}
.grid-col-xs-8 {
grid-column: span 8
}
.grid-col-xs-9 {
grid-column: span 9
}
.grid-col-xs-10 {
grid-column: span 10
}
.grid-col-xs-11 {
grid-column: span 11
}
.grid-col-xs-12 {
grid-column: span 12
}
.grid-row-xs-1 {
grid-row: span 1
}
.grid-row-xs-2 {
grid-row: span 2
}
.grid-row-xs-3 {
grid-row: span 3
}
}
@media only screen and (min-width:768px) {
.grid-col-sm-1 {
grid-column: span 1
}
.grid-col-sm-2 {
grid-column: span 2
}
.grid-col-sm-3 {
grid-column: span 3
}
.grid-col-sm-4 {
grid-column: span 4
}
.grid-col-sm-5 {
grid-column: span 5
}
.grid-col-sm-6 {
grid-column: span 6
}
.grid-col-sm-7 {
grid-column: span 7
}
.grid-col-sm-8 {
grid-column: span 8
}
.grid-col-sm-9 {
grid-column: span 9
}
.grid-col-sm-10 {
grid-column: span 10
}
.grid-col-sm-11 {
grid-column: span 11
}
.grid-col-sm-12 {
grid-column: span 12
}
.grid-row-sm-1 {
grid-row: span 1
}
.grid-row-sm-2 {
grid-row: span 2
}
.grid-row-sm-3 {
grid-row: span 3
}
}
@media only screen and (min-width:1024px) {
.grid-col-md-1 {
grid-column: span 1
}
.grid-col-md-2 {
grid-column: span 2
}
.grid-col-md-3 {
grid-column: span 3
}
.grid-col-md-4 {
grid-column: span 4
}
.grid-col-md-5 {
grid-column: span 5
}
.grid-col-md-6 {
grid-column: span 6
}
.grid-col-md-7 {
grid-column: span 7
}
.grid-col-md-8 {
grid-column: span 8
}
.grid-col-md-9 {
grid-column: span 9
}
.grid-col-md-10 {
grid-column: span 10
}
.grid-col-md-11 {
grid-column: span 11
}
.grid-col-md-12 {
grid-column: span 12
}
.grid-row-md-1 {
grid-row: span 1
}
.grid-row-md-2 {
grid-row: span 2
}
.grid-row-md-3 {
grid-row: span 3
}
}
@media only screen and (min-width:1280px) {
.grid-col-lg-1 {
grid-column: span 1
}
.grid-col-lg-2 {
grid-column: span 2
}
.grid-col-lg-3 {
grid-column: span 3
}
.grid-col-lg-4 {
grid-column: span 4
}
.grid-col-lg-5 {
grid-column: span 5
}
.grid-col-lg-6 {
grid-column: span 6
}
.grid-col-lg-7 {
grid-column: span 7
}
.grid-col-lg-8 {
grid-column: span 8
}
.grid-col-lg-9 {
grid-column: span 9
}
.grid-col-lg-10 {
grid-column: span 10
}
.grid-col-lg-11 {
grid-column: span 11
}
.grid-col-lg-12 {
grid-column: span 12
}
.grid-row-lg-1 {
grid-row: span 1
}
.grid-row-lg-2 {
grid-row: span 2
}
.grid-row-lg-3 {
grid-row: span 3
}
}
@media only screen and (min-width:1440px) {
.grid-col-xl-1 {
grid-column: span 1
}
.grid-col-xl-2 {
grid-column: span 2
}
.grid-col-xl-3 {
grid-column: span 3
}
.grid-col-xl-4 {
grid-column: span 4
}
.grid-col-xl-5 {
grid-column: span 5
}
.grid-col-xl-6 {
grid-column: span 6
}
.grid-col-xl-7 {
grid-column: span 7
}
.grid-col-xl-8 {
grid-column: span 8
}
.grid-col-xl-9 {
grid-column: span 9
}
.grid-col-xl-10 {
grid-column: span 10
}
.grid-col-xl-11 {
grid-column: span 11
}
.grid-col-xl-12 {
grid-column: span 12
}
.grid-row-xl-1 {
grid-row: span 1
}
.grid-row-xl-2 {
grid-row: span 2
}
.grid-row-xl-3 {
grid-row: span 3
}
}
.grid-col-end {
grid-column-end: -1
}
<section class="grid">
<div class="grid-col grid-col-12 grid-col-sm-4 grid-col-md-3">
<a href="#" class="c-book-tile">
<div class="c-book-tile__body">
Lorem ipsum
</div>
</a>
</div>
<div class="grid-col grid-col-12 grid-col-sm-4 grid-col-md-3">
<a href="#" class="c-book-tile">
<div class="c-book-tile__body">
Lorem ipsum
</div>
</a>
</div>
<div class="grid-col grid-col-12 grid-col-sm-4 grid-col-md-3">
<a href="#" class="c-book-tile">
<div class="c-book-tile__body">
Lorem ipsum
</div>
</a>
</div>
</section>
Upvotes: 1