<div class="demo1">
<p class="text1">Text1</p>
<p class="text2">Text2</p>
<p class="des">Lorem ipsum dolor sit amet ...</p>
</div>
<div class="demo2">
<p class="text1">Text1</p>
<p class="text2">Text2</p>
<p class="des">Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto modi fugiat odio impedit, ullam eveniet eos ea enim veritatis doloremque Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto modi fugiat odio impedit, ullam eveniet eos ea enim veritatis doloremque minima perferendis eius ipsa dicta inventore, optio vero cupiditate cum. Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto modi fugiat odio impedit, ullam eveniet eos ea enim veritatis doloremque minima perferendis eius ipsa dicta inventore, optio vero cupiditate cum. Lorem ipsum dolor sit amet consectetur adipisicing elit. Iusto modi fugiat odio impedit, ullam eveniet eos ea enim veritatis doloremque minima perferendis eius ipsa dicta inventore, optio vero cupiditate cum. minima perferendis eius ipsa dicta inventore, optio vero cupiditate cum.</p>
</div>
* {
margin: 0;
padding: 0;
}
.demo1,
.demo2 {
display: grid;
grid-template-columns: repeat(2, auto);
grid-template-rows: repeat(2, auto);
}
.demo1 {
margin-bottom: 50px;
}
.demo1 .des {
grid-area: 2/1/3/3;
}
.demo2 .des {
grid-area: 1/1/3/2;
}
When i use css gird layout, i have some questions.
How to set .text1
& .text2
element width or height not auto scaling?
I want to their width or height equal content width or height.
Please help me,thank you.
2
Answers
You can do that by using
aspect-ratio
:I believe you are asking how to set
.text1
&.text2
so that the width and height are equal to its contents. Usewidth: fit-content
Info about fit-content
Can I use
width: fit-content
? is showing 95% global support.