Css overflow scroll safari

overflow

Свойство CSS overflow определяет, необходимо ли для переполненного блочного элемента содержимое обрезать, предоставить полосы прокрутки или просто отобразить.

Использование свойства overflow со значениями, отличными от visible , (значение, принятое по умолчанию), создаёт новый блочный контекст форматирования (en-US) . Это технически необходимо, поскольку если бы float пересекался с элементом прокрутки, это потребовало бы обеспечить обтекание содержимого прокручиваемого элемента вокруг вторгающихся float’ов. Обтекание при этом было бы необходимо производить после каждого шага прокрутки заново, что привело бы к заметному замедлению прокрутки. Обратите внимание, что при программной установке атрибута scrollTop для соответствующего HTML-элемента, даже если overflow имеет значение hidden , элемент, возможно, придётся прокрутить.

  • overflow-x (en-US): as specified, except with visible / clip computing to auto / hidden respectively if one of overflow-x (en-US) or overflow-y (en-US) is neither visible nor clip
  • overflow-y (en-US): as specified, except with visible / clip computing to auto / hidden respectively if one of overflow-x (en-US) or overflow-y (en-US) is neither visible nor clip

Синтаксис

overflow =
[ (en-US) visible | (en-US) hidden | (en-US) clip | (en-US) scroll | (en-US) auto ] (en-US) (en-US)

overflow: visible overflow: hidden overflow: scroll overflow: auto overflow: inherit 

Значения

По умолчанию. Содержимое не обрезается, может отображаться снаружи блока, в котором оно расположено.

Контент обрезается, без предоставления прокрутки.

Содержимое обрезается и браузер использует элементы прокрутки, не важно было ли обрезано содержимое или нет. Это избегает многих проблем касательно появления прокруток и их исчезновения в динамичной среде. Принтеры могут печатать переполненное содержимое.

Читайте также:  Compare with nan python

Зависит от агента пользователя. Браузеры такие как Firefox предоставляют прокрутку, если содержимое переполняет блок.

Расширения Mozilla

Главным образом предназначен для внутреннего использования и для тем. Отключает прокрутку XML root элементов и , клавишами со стрелками и колесом мыши.

Примеры

p  width: 12em; height: 6em; border: dotted; overflow: visible; /* содержимое не обрезается */ > 

visible (default) Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

p  overflow: hidden; /* полосы прокрутки не предоставляются */ > 

overflow: hidden Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

p  overflow: scroll; /* всегда показывать полосы прокрутки */ > 

overflow: scroll Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

p  overflow: auto; /* добавить полосы прокрутки, если это необходимо */ > 

overflow: auto Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

Спецификации

Спецификация Статус Комментарий
CSS Overflow Module Level 3
Определение ‘overflow’ в этой спецификации.
Рабочий черновик Changed syntax to allow one or two keywords instead of only one
CSS Box Model
Определение ‘overflow’ в этой спецификации.
Кандидат в рекомендации Без изменений
CSS Level 2 (Revision 1)
Определение ‘overflow’ в этой спецификации.
Рекомендация Initial definition.

Совместимость браузера

BCD tables only load in the browser

Firefox (Gecko) Примечания

Из-за Firefox 3.6 (Gecko 1.9.2), свойство overflow неверно применяется к элементам table-group ( , , ). Это поведение будет исправлено в следующих версиях.

Internet Explorer Примечания

Internet Explorer 4 — 6 увеличивает элемент с overflow:visible (значение по умолчанию), чтобы заполнить содержимое в нём. height/width действуют подобно min-height/min-width .

Смотрите также

Found a content problem with this page?

This page was last modified on 17 февр. 2023 г. by MDN contributors.

Your blueprint for a better internet.

Источник

-webkit-overflow-scrolling

Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The -webkit-overflow-scrolling CSS property controls whether or not touch devices use momentum-based scrolling for a given element.

Syntax

/* Keyword values */ -webkit-overflow-scrolling: auto; -webkit-overflow-scrolling: touch; /* Global values */ -webkit-overflow-scrolling: inherit; -webkit-overflow-scrolling: initial; -webkit-overflow-scrolling: revert; -webkit-overflow-scrolling: revert-layer; -webkit-overflow-scrolling: unset; 

Values

Use «regular» scrolling, where the content immediately ceases to scroll when you remove your finger from the touchscreen.

Use momentum-based scrolling, where the content continues to scroll for a while after finishing the scroll gesture and removing your finger from the touchscreen. The speed and duration of the continued scrolling is proportional to how vigorous the scroll gesture was. Also creates a new stacking context.

Formal definition

Formal syntax

-webkit-overflow-scrolling = auto | touch

Examples

HTML

div class="scroll-touch"> p>This paragraph has momentum scrollingp> div> div class="scroll-auto"> p>This paragraph does not.p> div> 

CSS

div  width: 100%; overflow: auto; > p  width: 200%; background: #f5f9fa; border: 2px solid #eaf2f4; padding: 10px; > .scroll-touch  -webkit-overflow-scrolling: touch; /* Lets it scroll lazy */ > .scroll-auto  -webkit-overflow-scrolling: auto; /* Stops scrolling immediately */ > 

Results

Specifications

Browser compatibility

BCD tables only load in the browser

See also

  • CSS-Tricks article with demo
  • Smashing Magazine — describing the effect of scroll bouncing and how it works on different web browsers
  • Safari 13 Release notes: Indicates the addition of support for one-finger accelerated scrolling to all frames and overflow:scroll elements, eliminating the need to set -webkit-overflow-scrolling: touch .

Found a content problem with this page?

This page was last modified on Mar 30, 2023 by MDN contributors.

Your blueprint for a better internet.

MDN

Support

Our communities

Developers

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

Источник

overflow

The overflow property controls what happens to content that breaks outside of its bounds: imagine a div in which you’ve explicitly set to be 200px wide, but contains an image that is 300px wide. That image will stick out of the div and be visible by default. Whereas if you set the overflow value to hidden , the image will cut off at 200px.

  • visible : content is not clipped when it proceeds outside its box. This is the default value of the property
  • hidden : overflowing content will be hidden.
  • scroll : similar to hidden except users will be able to scroll through the hidden content.
  • clip : content is clipped when it proceeds outside its box. This can be used with overflow-clip-margin to set the clipped area.
  • auto : if the content proceeds outside its box then that content will be hidden whilst a scroll bar should be visible for users to read the rest of the content.
  • initial : uses the default value which is visible
  • inherit : sets the overflow to the value of its parent element.

Remember that text will naturally wrap at the end of an element (unless white-space is changed) so text will rarely be the cause of overflow. Unless a height is set, text will just push an element taller as well. Overflow comes into play more commonly when explicit widths and heights are set and it would be undesirable for any content to spill out, or when scrolling is explicitly being avoided.

If you don’t set the overflow property at all, the default is visible. So in general, there is no reason to explicitly set this property to visible unless you are overriding it from being set elsewhere.

The important thing to remember here is that even though the content is visible outside of the box, that content does not affect the flow of the page. For example:

Generally, you shouldn’t be setting static heights on boxes with web text in them anyway, so it shouldn’t come up.

The opposite of the default visible is hidden. This literally hides any content that extends beyond the box.

This is particularly useful in use with dynamic content and the possibility of an overflow causing serious layout problems. However, bear in mind that content that is hidden in this way is utterly inaccessible (short of viewing the source). So for example a user has their default font size set larger than you would expect, you may be pushing text outside of a box and hiding it completely from their view.

Setting the overflow value of a box to scroll will hide the content from rendering outside the box, but will offer scrollbars to scroll the interior of the box to view the content.

Of note with this value is that you get BOTH horizontal and vertical scrollbars no matter what, even if the content requires only one or the other.

iOS’ momentum scrolling can be enabled for this value with -webkit-overflow-scrolling .

Note: In OS X Lion, when scrollbars are set to only show when being used, scroll behaves more like auto , in that only needed scrollbars will show up.

Auto overflow is very similar to the scroll value, only it solves the problem of getting scrollbars when you don’t need them. The scrollbars will only show up if there is content that actually breaks out of the element.

It’s also possible to manipulate the overflow of content horizontally or vertically with the overflow-x and overflow-y properties. For example in the demo below the horizontal overflow can be scrolled through whilst the text that extends beyond the height of the box is hidden:

One of the more popular uses of setting overflow, strangely enough, is float clearing. Setting overflow doesn’t clear the float at the element, it self-clears. This means that the element with overflow (any value except visible ) will extend as large as it needs to encompass child elements inside that are floated (instead of collapsing), assuming that the height isn’t declared. Like this:

A better float clearing technique is the clearfix, as it doesn’t require you to alter the overflow property in a way you don’t need.

Generating block formatting context

It’s interesting to note that overflow will also create a new block formatting context which is useful if we want to align a block element next to a floated one. In the example below we show how a number of paragraphs will interact with a floated image by default and then we use overflow: hidden to align the text within its own box:

This comes from a great post by Nicole Sullivan which went on to inspire the media object.

Can scrollbars be styled with CSS?

You used to be able to style scrollbars in IE (v5.5?) but no more. You can style them now again in WebKit browsers. If you need cross-browser custom scrollbars, look to JavaScript.

If an element needs to have scrollbars appended to honor the overflow value, Firefox puts them outside the element, keeping the visible width/height as declared. IE puts the scrollbars inside, keeping the overall width/height as declared.

Demos for this article taken from this sample page.

This browser support data is from Caniuse, which has more detail. A number indicates that browser supports the feature at that version and up.

Desktop

Mobile / Tablet

Источник

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