Запретить элементам сетки, содержащим изображение, растягивать другие элементы сетки [дубликат]CSS

Разбираемся в CSS
Ответить Пред. темаСлед. тема
Гость
 Запретить элементам сетки, содержащим изображение, растягивать другие элементы сетки [дубликат]

Сообщение Гость »


I've seen a bunch of similar looking questions and went through them all, but none of the solutions seem to work for my problem.

I have a grid and a bunch of sections within it. One contains the visual result - an image (with a manipulated via the controls in the other sections, but that part isn't really relevant here).

The problem is that the containing the stretches the other sections.

Код: Выделить всё

* { margin: 0 } main {   --space: .5em;   --imcol: min(40%, 400px);   display: grid;   grid-gap: var(--space);   grid-template-columns:      min(100% - var(--space) - var(--imcol), 32em)      var(--imcol);   padding: var(--space) } section { background: pink } .ctrl { padding: inherit } .result { grid-area: 1/ 2/ span 2 } /* often found this as a fix, but it doesn't work */ section, figure, img {   min-height: 0;   max-height: 100% } img {   width: 100%;   object-fit: cover }

Код: Выделить всё

        Some heading                   boo              foo              moo          Jelly-o danish cupcake jelly-o bonbon lollipop danish chocolate bar. Oat cake cheesecake marshmallow chocolate bar caramels macaroon gummi bears. Gingerbread cotton candy topping carrot cake fruitcake tart.     action           Some other heading                   mew              few              pew                       
[img]https://images.unsplash.com/photo-1707767787271-b00e648a61e4?w=400[/img]
         


The only way I can think of that would give me the result I want would be to absolutely position the image and set

Код: Выделить всё

overflow: hidden
on the .

Код: Выделить всё

* { margin: 0 } main {   --space: .5em;   --imcol: min(40%, 400px);   display: grid;   grid-gap: var(--space);   grid-template-columns:      min(100% - var(--space) - var(--imcol), 32em)      var(--imcol);   padding: var(--space) } section { background: pink } .ctrl { padding: inherit } .result { grid-area: 1/ 2/ span 2 } figure {   overflow: hidden;   position: relative;   height: 100% } img {   position: absolute;   width: 100%;   height: 100%;   object-fit: cover }

Код: Выделить всё

        Some heading                   boo              foo              moo          Jelly-o danish cupcake jelly-o bonbon lollipop danish chocolate bar. Oat cake cheesecake marshmallow chocolate bar caramels macaroon gummi bears.  Gingerbread cotton candy topping carrot cake fruitcake tart.     action           Some other heading                   mew              few              pew                       
[img]https://images.unsplash.com/photo-1707767787271-b00e648a61e4?w=400[/img]
         


Is there any way of getting this result without taking the image out of the document flow?


Источник: https://stackoverflow.com/questions/781 ... grid-items
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Запретить таблицу растягивать всю страницу Blazor по горизонтали
    Anonymous » » в форуме CSS
    0 Ответы
    21 Просмотры
    Последнее сообщение Anonymous
  • Запретить таблицу растягивать всю страницу Blazor по горизонтали
    Anonymous » » в форуме CSS
    0 Ответы
    34 Просмотры
    Последнее сообщение Anonymous
  • Поиск элементов с набором, содержащим все элементы заданного набора, с помощью jpql
    Anonymous » » в форуме JAVA
    0 Ответы
    23 Просмотры
    Последнее сообщение Anonymous
  • Как создать файл docx с текстовым полем, содержащим изображение?
    Anonymous » » в форуме JAVA
    0 Ответы
    22 Просмотры
    Последнее сообщение Anonymous
  • Как запретить flex-box выталкивать другие элементы из контейнера?
    Anonymous » » в форуме Html
    0 Ответы
    19 Просмотры
    Последнее сообщение Anonymous

Вернуться в «CSS»