Css чтобы блок растягивался

Как сделать, чтобы блок растягивался по высоте от содержимого?

Нашел шаблон в интернете, по нему начал заполнять своим контентом. Возинкла проблема, я сделал текст раскрывающимся списком, но тк его много, он заходит за следующий блок. Как сделать так, чтобы блок автоматически растягивался, когда открывается список с текстом?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
section id="process"> div class="row section-intro"> div class="col-twelve with-bottom-line"> h5>Образование/h5> h1>Учебный план/h1> p class="lead">Программа подготовки специалистов реализуется на базе среднего (полного) общего и основного общего образования./p> /div> /div> div class="row process-content"> div class="left-side"> div class="item" data-item="1"> h5>Курс/h5> p>Окончание средне-полного общего образования, состоящее из базовых и профессиональных дисциплин.пывпыв ывп ывпывпывп вфпфвафыафыа фыа фыафыафыаф афыафыафыаы./p> /div> div class="item" data-item="2"> h5>Upload/h5> p>Lorem ipsum Cupidatat nostrud non cupidatat ut dolor id eiusmod non minim aute consectetur incididunt tempor irure aute consequat quis voluptate./p> /div> /div>  div class="right-side"> div class="item" data-item="3"> h5>Create/h5> p>Lorem ipsum Cupidatat nostrud non cupidatat ut dolor id eiusmod non minim aute consectetur incididunt tempor irure aute consequat quis voluptate./p> /div> div class="item" data-item="4"> h5>Publish/h5> p>sequat quis voluptateLorem ipsum Cupidatat nostrud non cupidatat ut dolor id eiusmod non minim aute consectetur incididunt tempor irure aute consequat quis voluptateLorem ipsum Cupidatat nostrud non cupidatat ut dolor id eiusmod non minim aute consectetur incididunt tempor irure aute consequat quis voluptateLorem ipsum Cupidatat nostrud non cupidatat ut dolor id eiusmod non minim aute consectetur incididunt tempor irure aute consequat quis voluptateLorem ipsum Cupidatat nostrud non cupidatat ut dolor id eiusmod non minim aute consectetur incididunt tempor irure aute consequat quis voluptate./p> /div> /div>  div class="image-part">/div> /div>  /section> 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#process { background: #FFFFFF; padding-top: 12rem; padding-bottom: 15rem; overflow: hidden; } .process-content { position: relative; text-align: center; } .process-content .right-side, .process-content .left-side, .process-content .image-part { width: 33.33333%; font-size: 15px; line-height: 27px; } .process-content .right-side, .process-content .left-side { padding: 0 6% 24px; position: absolute; top: 0; } .process-content .right-side { right: 0; } .process-content .left-side { left: 0; } .process-content .image-part { margin: 0 auto; height: 660px; background-image: url("../images/appdesign.jpg"); background-repeat: no-repeat; background-position: center; -webkit-background-size: contain; -moz-background-size: contain; background-size: contain; } .process-content .item[data-item]::before { background: #38424e; color: #FFFFFF; border-radius: 100%; font-family: "montserrat-bold", sans-serif; content: attr(data-item); display: inline-block; font-size: 18px; height: 42px; width: 42px; line-height: 42px; text-align: center; vertical-align: middle; margin-bottom: 1.5rem; } .process-content h5 { color: #05bca9; font-size: 1.6rem; line-height: 1.875; letter-spacing: .2rem; margin-bottom: .3rem; }

Источник

Читайте также:  Взаимодействие сервера и клиента java

CSS Height Full Page CSS gotcha: How to fill page with a div?

So let’s say you want a div that fills up entire page.

div  height: 100%; width: 100%; font-size: 20px; background-color: lightskyblue; > 

./Untitled.png

What?! It doesn’t work! The height still only takes up the content, but not the whole page.

The width is good since a div is by default a block element, which takes as much width as possible anyways.

Can we just use a more «absolute» value like px ?

div  /* height: 100% */ height: 865px; /* current height of my browser */ /* . */ > 

It works. until the browser is resized It doesn’t adapt when the browser is resized. You can use JS for this, but that’s way overkill for what we wanted.

I mentioned px is «absolute», but only in the sense that they are not relative to anything else (like rem and vh). But the actual size still depends on the device. Here’s some details:

Relative units to the rescue!

Old school height: 100%

html, body  height: 100%; width: 100%; > div  height: 100%; /* . */ > 

Works! (We’ll fix the scrollbars later) By setting both and its child to 100% height, we achieve the full size. Note that only setting either of them won’t work, since percentage is always relative to another value. In this case:

  • div is 100% the height of the body
  • body is 100% the height of the html
  • html is 100% the height of the Viewport

Viewport is the visible area of the browser, which varies by device.

For example, an iPhone 6/7/8 has a 375×667 viewport. You can verify this on your browser dev tools mobile options.

For now, you can think about viewport as the device pixel size or resolution. But if you want to go deep:

newer solution: viewport units vh and vw

Viewport-percentage lengths aka Viewport units have been around for a while now, and is perfect for responding to browser resizes.

  • 1 viewport height ( 1vh ) = 1% of viewport height
  • 1 viewport width ( 1vw ) = 1% of viewport width

In other words, 100vh = 100% of the viewport height

100vw = 100% of the viewport width

So these effectively fills up the device viewport.

html, body  /* height: 100%; */ /* width: 100% */ > div  /* height: 100%; width: 100%; */ height: 100vh; width: 100vw; /* . */ > 

Looks good too! (We’ll fix the scrollbars later)

As mentioned in the comments by @angelsixuk and @mpuckett , there is a known jumping behavior during scrolling when using 100vh on mobile browsers, which is an issue but considered intentional by webkit. See these links for details: Viewport height is taller than the visible part of the document in some mobile browsers and Stack Overflow: CSS3 100vh not constant in mobile browser

How about min-height: 100vh ?

While height fixes the length at 100vh , min-height starts at 100vh but allows content to extend the div beyond that length. If content is less than the length specified, min-height has no effect.

In other words, min-height makes sure the element is at least that length, and overrides height if height is defined and smaller than min-height .

For our goal of having a div child with full height and width, it doesn’t make any difference since the content is also at full size.

A good use case of min-height is for having a sticky footer that gets pushed when there is more content on the page. Check this out here and other good uses of vh

A very common practice is to apply height: 100vh and width: 100vw to directly.

In this case, we can even keep the container div relatively sized like in the beginning, in case we change our minds later.

And with this approach, we assure that our entire DOM body occupies full height and width regardless of our container div.

body  height: 100vh; width: 100vw; > div  height: 100%; width: 100%; /* height: 100vh; width: 100vw; */ /* . */ > 

vh/vw versus %

A good way of thinking about vh, vw vs % is that they are analogous to em and rem

% and em are both relative to the parent size, while vw/vh and rem are both relative to «the highest reference», root font size for rem and device viewport for vh/vw.

But why the scrollbar?

and have default margins and paddings!

Browsers feature a default margin, padding and borders to HTML elements. And the worst part is it’s different for each browser!

Chrome default for has a margin: 8px

And 100vh + 8px causes an overflow, since it’s more than the viewport

Luckily, it’s fairly easy to fix that:

html, body  margin: 0; padding: 0; > body . 

This is a «blanket» solution that would cover all margin and padding variations for any browser you might have.

Cool! Now we have our div filling up the page without scrollbars!

no more scrollbars

Finally, let’s add a little padding, since it’s awkward that the content is right on the edges.

What?! The scrollbar is back! What happened?

box-sizing border-box

box-sizing allows you to define whether the padding and border is included in the div’s height and width.

The default content-box of box-sizing doesn’t include padding and border in the length, so div becomes

border-box includes padding and border, so div stays at our required sizes:

It’s quite common to set all elements to border-box for a consistent layout and sizing throughout pages, using * selector:

Источник

Css чтобы блок растягивался

Давайте сделаем, чтобы блок растягивался по горизонтали с помощью мышки!

Нам понадобится для растягивания. например тег div.

Как вы знаете есть «3 способа css». воспользуемся одним из них : Не будем делать отдельные стили добавим ему attribute style + background-color + width + height

Смотрим, что у нас получилось — его и будем растягивать мышкой!

Добавим второй div — сделаем его линией справа. добавим «cursor: col-resize»

Добавим сюда javascript, но поскольку. объяснение html заняло столько места, то объяснение скрипта, который будет растягивать блок по ширине. боюсь займет намного места больше! Поэтому его можно будет скачать в архиве!

Готовый блок для растягивания мышкой по горизонтали:

Для того, чтобы растянуть блок по ширине, наведите мышку на вертикальную линию справа нажмите левую кнопку мыши и потяните вправо.

Растягиваем блок по вертикали мышкой.

Скачиваем пример растягивания блока открываем файл в любом редакторе кода либо в простом блокноте и раскоментируйте три строки. выделено красным ниже:

И после этого. ваш блок будет растягиваться и по вертикали!

if( nx // if( ny // el.style.height = ny + ‘px’;

P.S

Удивительно работает человеческий мозг.

Эта страница была написана. более 2 месяцев назад.

И как единственный вариант — рассматривались пункты растяжения мышкой — javascript.

И там использовал «resize» и тут. думаю. где-то я писал про растягивание блока мышкой. и вообще даже не вспомнил про «resize» — вот же прикол!

Источник

Оцените статью