This is my first time ever using grid layout, and I'm having trouble having my p tags fill the content of the cell they occupy. So, I do not need help making the grid. I need help expanding the text of the p tag to fill the cell of which the p tag occupies.
Here is the code: NOTE: The first half consists of Andy Bell's Modern CSS Reset. I modified only parts of it which would've been overwritten later.
*, *::before, *::after {
box-sizing: border-box;
}
body, p {
margin: 0;
}
html:focus-within {
scroll-behavior: smooth;
}
html::-webkit-scrollbar {
display: none;
}
html, body {
width: 100%;
height: 100%;
}
body {
font-size: 1rem;
height: 100%;
overflow: hidden;
min-height: 100vh;
text-rendering: optimizeSpeed;
line-height: 1;
}
a:not([class]) {
text-decoration-skip-ink: auto;
}
img,
picture {
max-width: 100%;
display: block;
}
@media (prefers-reduced-motion: reduce) {
html:focus-within {
scroll-behavior: auto;
}
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
}
.container {
width: 100%;
height: 100%;
}
.typography-grid {
width: 100%;
height: 100%;
display: grid;
grid-auto-columns: 1fr;
grid-auto-rows: 1fr;
grid-template-areas:
'text-section-one text-section-one . . . . .'
'. . image image image . .'
'small-text . . . . text-section-two text-section-two';
}
img {
grid-area: image;
aspect-ratio: 1;
width: 65%;
margin: 0 auto;
z-index: 1;
box-shadow: 0px 0px 10px 0px black;
}
/* p {
width: 100%;
font-size: 2rem;
font-size: 5vw;
} */
.text--small {
font-style: italic;
width: 80%;
text-align: left;
grid-area: small-text;
}
#large1 {
grid-area: text-section-one;
}
#large2 {
letter-spacing: 1rem;
grid-column: 2 / 7;
grid-row: 2;
}
#large3 {
grid-area: text-section-two;
}
<!DOCTYPE html>
<html>
<head>
<!--
<script>
textFit(document.querySelector("p"), 0.5);
fitText(document.querySelector("p"), 0.5);
fitty('p');
</script>
-->
</head>
<body>
<div class="container">
<div class="typography-grid">
<p class="text text--large" id="large1">TEXT</p>
<p class="text text--large" id="large2">TEXT</p>
<img src="https://andyspizzaandsubs.com/wp-content/uploads/2018/11/blog-ph.jpg" alt="sample image">
<p class="text text--small">SAMPLE TEXT SAMPLE TEXT SAMPLE TEXT SAMPLE TEXT SAMPLE TEXT SAMPLE TEXT SAMPLE TEXT SAMPLE TEXT</p>
<p class="text text--large" id="large3">TEXT</p>
</div>
</div>
</body>
</html>
I've tried the items commented out under the p tag selector, but there doesn't seem to be a perfect magic number where everything doesn't get pushed out of frame. I've also tried width: fit-content;
to see if that would change anything, but nothing did.
Last thing I tried was following this previous SO post: Font scaling based on width of container I used script tags in the head of my HTML (which didn't work), and the relative units didn't work for reasons mentioned before.
Is this possible? I'm aiming for a large-typography-style website, so I need the p tags to fill the grid cells they occupy, or sort of stretch to fill the cells they occupy. Is there a workaround? Any help is appreciated! Thank you.