Grids are made but text won’t center. The image won’t fill the entire grid area on the right it keeps getting cropped and stretched over the background panel.
I want it to be like:
Centered text "Welcome to website" + description (~20px or so of space) Centered Image
I’m new to web design and this is my first time posting so I’d appreciate any explanation 🙂
I tried making a background panel with two side-by-side grids. It ended up with text on the left stuck at the very top of the panel and a small image on the right extending beyond the border of the panel.
.colored-panel {
background-color: #6A1A2F;
padding: 20px;
height: 460px;
text-align: center; /* #making a solid colored background panel */
color: #333;
}
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr; /* #1:1 split of grid with spacing */
grid-gap: 20px;
color: white;
}
.apu-image {
max-height: 100%; /* #adding image */
max-width: 100%;
}
/* -----------------------#cover to fit not sure what I'm missing? */
.colored-panel h1{.
padding: 10px;
size: 60px ;
text-align: center;
}
/* #tried making text centered but I'm not sure how to make it centered --------------------------with respect to its grid */
<div class="colored-panel">
<div class="grid-container">
<div class="text">
<h1>Welcome to my website!</h1>
<p>test</p>
</div>
<div class="apu-img">
<img class="apu-image" src="pics/apu.jpg" alt=""Picture of Apu Siqay>
</div>
</div>
</div>
2
Answers
in my opinion you can do this with flexbox.
I hope it helps and that is what you meant. I’ve used flexbox to center the text and image vertically within their respective grid cells.
Hey is this somewhat what you are looking for:
If so, the only thing you were missing was to define a
width
for the image in the grid to let it scale only within the grid. And to addalign-items:center
to the grid container to let the items be centered compared to other items in the same row.Have a great day!