body {
background-color: hsl(210, 46%, 95%);
font-size: 13px;
font-family: "Barlow Semi Condensed", sans-serif;
height: 100vh;
}
svg {
position: absolute;
justify-self: right;
padding-right: 20px;
}
.attribution {
font-size: 11px;
text-align: center;
}
.attribution a {
color: hsl(228, 45%, 44%);
}
.testimonialsmain {
display: grid;
grid-template-columns: auto auto auto auto;
grid-template-rows: auto auto;
gap: 20px;
padding: 20px;
}
.testimonialitem {
border-radius: 5px;
}
.testimonialitem:nth-child(3) {
grid-row: span 2;
background-color: hsl(0, 0%, 100%);
padding: 20px;
display: grid;
}
.testimonialitem:nth-child(1) {
grid-column: span 2;
background-color: hsl(263, 55%, 52%);
color: hsl(0, 0%, 81%);
padding: 20px;
display: grid;
width: auto;
}
.testimonialitem:nth-child(2) {
background-color: hsl(217, 19%, 35%);
color: hsl(0, 0%, 81%);
padding: 20px;
display: grid;
width: auto;
}
.testimonialitem:nth-child(4) {
background-color: hsl(0, 0%, 100%);
padding: 20px;
display: grid;
width: auto;
}
.testimonialitem:nth-child(5) {
grid-column: span 2;
background-color: hsl(219, 29%, 14%);
color: hsl(0, 0%, 81%);
padding: 20px;
display: grid;
width: auto;
}
.card {
display: grid;
grid-template-columns: 1fr 6fr;
}
.pic {
border-radius: 50%;
}
.intro {
padding-top: 10px;
font-size: large;
z-index: 2;
}
.testimonial {
padding-top: 10px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- displays site properly based on user's device -->
<link
rel="icon"
type="image/png"
sizes="32x32"
href="./images/favicon-32x32.png"
/>
<title>Frontend Mentor | Testimonials Grid</title>
<!-- Feel free to remove these styles or customise in your own stylesheet 👍 -->
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Barlow+Semi+Condensed:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet"
/>
</head>
<body>
<div class="main">
<div class="testimonialsmain">
<div class="testimonialitem">
<svg width="104" height="102" xmlns="http://www.w3.org/2000/svg">
<path
d="M104 102V59.727H84.114c0-5.871.689-11.182 2.068-15.933 1.379-4.75 3.42-9.287 6.125-13.61C95.01 25.86 98.909 22.257 104 19.375V0c-9.758 4.27-17.712 9.874-23.864 16.813-6.151 6.939-10.712 14.545-13.681 22.818C63.485 47.904 62 59.941 62 75.74V102h42zm-62 0V59.727H22.114c0-5.871.689-11.182 2.068-15.933 1.379-4.75 3.42-9.287 6.125-13.61C33.01 25.86 36.909 22.257 42 19.375V0c-9.652 4.27-17.58 9.874-23.784 16.813C12.01 23.752 7.424 31.358 4.455 39.631 1.485 47.904 0 59.941 0 75.74V102h42z"
fill="#A775F1"
fill-rule="nonzero"
/>
</svg>
<div class="card">
<img src="./images/image-daniel.jpg" class="pic" />
Daniel Clifford <br />
Verified Graduate
</div>
<div class="intro">
I received a job offer mid-course, and the subjects I learned were
current, if not more so, in the company I joined. I honestly feel I
got every penny’s worth.
</div>
<div class="testimonial">
“ I was an EMT for many years before I joined the bootcamp. I’ve
been looking to make a transition and have heard some people who had
an amazing experience here. I signed up for the free intro course
and found it incredibly fun! I enrolled shortly thereafter. The next
12 weeks was the best - and most grueling - time of my life. Since
completing the course, I’ve successfully switched careers, working
as a Software Engineer at a VR startup. ”
</div>
</div>
<div class="testimonialitem">
<div class="card">
<img src="./images/image-jonathan.jpg" class="pic" /> Jonathan
Walters <br />
Verified Graduate
</div>
<div class="intro">
The team was very supportive and kept me motivated
</div>
<div class="testimonial">
“ I started as a total newbie with virtually no coding skills. I now
work as a mobile engineer for a big company. This was one of the
best investments I’ve made in myself. ”
</div>
</div>
<div class="testimonialitem">
<div class="card">
<img src="./images/image-kira.jpg" class="pic" /> Kira Whittle
<br />
Verified Graduate
</div>
<div class="intro">
Such a life-changing experience. Highly recommended!
</div>
<div class="testimonial">
“ Before joining the bootcamp, I’ve never written a line of code. I
needed some structure from professionals who can help me learn
programming step by step. I was encouraged to enroll by a former
student of theirs who can only say wonderful things about the
program. The entire curriculum and staff did not disappoint. They
were very hands-on and I never had to wait long for assistance. The
agile team project, in particular, was outstanding. It took my
learning to the next level in a way that no tutorial could ever
have. In fact, I’ve often referred to it during interviews as an
example of my developent experience. It certainly helped me land a
job as a full-stack developer after receiving multiple offers. 100%
recommend! ”
</div>
</div>
<div class="testimonialitem">
<div class="card">
<img src="./images/image-jeanette.jpg" class="pic" /> Jeanette
Harmon <br />
Verified Graduate
</div>
<div class="intro">An overall wonderful and rewarding experience</div>
<div class="testimonial">
“ Thank you for the wonderful experience! I now have a job I really
enjoy, and make a good living while doing something I love. ”
</div>
</div>
<div class="testimonialitem">
<div class="card">
<img src="./images/image-patrick.jpg" class="pic" /> Patrick Abrams
<br />
Verified Graduate
</div>
<div class="intro">
Awesome teaching support from TAs who did the bootcamp themselves.
Getting guidance from them and learning from their experiences was
easy.
</div>
<div class="testimonial">
“ The staff seem genuinely concerned about my progress which I find
really refreshing. The program gave me the confidence necessary to
be able to go out in the world and present myself as a capable
junior developer. The standard is above the rest. You will get the
personal attention you need from an incredible community of smart
and amazing people. ”
</div>
</div>
</div>
<div class="attribution">
Challenge by
<a href="https://www.frontendmentor.io?ref=challenge" target="_blank"
>Frontend Mentor</a
>. Coded by <a href="#">Aparna Gopalakrishnan</a>.
</div>
</div>
</body>
</html>
I have created a Grid with 3 columns and 2 rows. But not able to centralize it vertically and horizontally.
Can someone please suggest a solution that will work with the code that I have written?
I tried using different properties like align-items, align-self, align-content etc. Also refered to some of the solutions in this forum. Nothing worked for me so far.
padding is working. But with my basic knowledge, my understanding is that it is not a good design for a responsive page.
Now the Grid is located at the top of the page.The expected result is to move it down to the middle of the page as in the below screen shot.
2
Answers
Set the align-content property and the justify-content property to the centre. Make sure there is some space horizontally and vertically, otherwise the properties won’t be effective.
Solution
To center the content vertically and horizontally using a grid container, you need to apply your styling from the parent element of your content. Per your example, your content is within
testimonialsmain
, so the parentdiv
ismain
. First, you need to setmain
to occupy the whole page like this:If you want to view this using mobile, you may do this:
After that, you can use grid container to center your content vertically and horizontally like this:
By default, the
div
will have default width of 100%, so you need to setmax-width
for your content like this:You can refer to this for your solution.
Bonus
After you applied all the styles as I described above, you may find that you still see scroll bars both horizontally and vertically. This is due to by default, different browsers and elements have different default styles. You can use below CSS to reset it: