revision:
- specifies what should happen if content overflows an element's box. This property specifies whether to clip content or to add scrollbars when an element's content is too big to fit in a specified area.
Note: the overflow property only works for block elements with a specified height.
Property values:
visible : the overflow is not clipped. It renders outside the element's box. This is default
hidden : the overflow is clipped, and the rest of the content will be invisible. Content can be scrolled programmatically (e.g. by setting scrollLeft or scrollTo())
clip : the overflow is clipped, and the rest of the content will be invisible. Forbids scrolling, including programmatic scrolling.
scroll : the overflow is clipped, but a scroll-bar is added to see the rest of the content
auto : if overflow is clipped, a scroll-bar should be added to see the rest of the content
initial : sets this property to its default value.
inherit : inherits this property from its parent element.
example: overflow property
<div> <h4>overflow: scroll:</h4> <div class="ex1">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</div> <h4>overflow: hidden:</h4> <div class="ex2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</div> <h4>overflow: auto:</h4> <div class="ex3">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</div> <h4>overflow: clip:</h4> <div class="ex4">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</div> <h4>overflow: visible (default):</h4> <div class="ex5">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</div> </div> <style> .DIV-A{height: 85vh;} div.ex1 {background-color: lightblue; width: 6vw; height: 6vw; overflow: scroll;} div.ex2 {background-color: lightblue; width: 6vw; height: 6vw; overflow: hidden;} div.ex3 {background-color: lightblue; width: 6vw; height: 6vw; overflow: auto;} div.ex4 {background-color: lightblue; width: 6vw; height: 6vw; overflow: clip;} div.ex5 {background-color: lightblue; width: 6vw; height: 6vw; overflow: visible;} </style>
- makes it possible to turn off scroll anchoring. Scroll anchoring is a feature in the browser that prevents a viewable area that is scrolled into focus to move when new content is loaded above. This is typically a problem on a slow connection if the user scrolls down and starts reading before the page is fully loaded..
Property values:
auto : default value. Scroll anchoring is enabled
none : scroll anchoring is disabled
initial : sets this property to its default value.
inherit : inherits this property from its parent element.
example: overflow-anchor property
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<div> <div id="container"> <div id="newBoxes"></div> <h4>Scroll down to button, then click it</h4> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> <button onclick="addBox()">Click me</button> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </div> </div> <style> #container {padding: 0.5vw; width: 25vw; aspect-ratio: 1; border: solid black 0.2vw; overflow: scroll; overflow-anchor: none;} .blue {background-color: lightblue; height: 2vw; width: 80%; animation: contentExpand 5s infinite;} .greenDiv{background-color: lightgreen; width: 80%; margin: 0.3vw; aspect-ratio: 4/1;} </style> <script> function addBox(){ let newBoxesDiv = document.querySelector("#newBoxes"); let newDiv = document.createElement("div"); newDiv.className = "greenDiv"; newBoxesDiv.appendChild(newDiv); } </script>
- specifies whether or not the browser can break lines with long words, if they overflow the container.
Property values:
normal : long words will not break, even if they overflow the container. This is default
anywhere : long words will break if they overflow the container
break-word : long words will break if they overflow the container
initial : sets this property to its default value.
inherit : inherits this property from its parent element.
example: overflow-wrap property
<div> <h4>overflow-wrap: normal (default):</h4> <div class="main a">This div contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will not break and wrap to the next line.</div> <h4>overflow-wrap: break-word:</h4> <div class="main b">This div contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</div> <h4>overflow-wrap: anywhere:</h4> <div class="main c">This div contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</div> </div> <style> .main {width: 15vw; border: 0.1vw solid #000000;} div.a {overflow-wrap: normal;} div.b {overflow-wrap: break-word;} div.c {overflow-wrap: anywhere;} </style>
- specifies whether to clip the content, add a scroll bar, or display overflow content of a block-level element, when it overflows at the left and right edges.
Tip: use the overflow-y property to determine clipping at the top and bottom edges..
Property values:
visible : the content is not clipped, and it may be rendered outside the left and right edges. This is default
hidden : the content is clipped - and no scrolling mechanism is provided
scroll : the content is clipped and a scrolling mechanism is provided
auto : should cause a scrolling mechanism to be provided for overflowing boxes
initial : sets this property to its default value.
inherit : inherits this property from its parent element.
example: overflow-x property
<div> <h4>overflow-x: scroll:</h4> <div class="first ex11">Lorem ipsum dolor sit amet, consectetuer adipiscing elit...</div> <h4>overflow-x: hidden:</h4> <div class="first ex22">Lorem ipsum dolor sit amet, consectetuer adipiscing elit..</div> <h4>overflow-x: auto:</h4> <div class="first ex33">Lorem ipsum dolor sit amet, consectetuer adipiscing elit...</div> <h4>overflow-x: visible (default):</h4> <div class="first ex44">Lorem ipsum dolor sit amet, consectetuer adipiscing elit...</div> </div> <style> div.ex11 {background-color: lightblue; width: 4vw; overflow-x: scroll;} div.ex22 {background-color: lightblue; width: 4vw; overflow-x: hidden;} div.ex33 {background-color: lightblue; width: 4vw; overflow-x: auto;} div.ex44 {background-color: lightblue; width: 4vw; overflow-x: visible;} </style>
- specifies whether to clip the content, add a scroll bar, or display overflow content of a block-level element, when it overflows at the top and bottom edges.
Tip: use the overflow-x property to determine clipping at the left and right edges.
Property values:
visible : the content is not clipped, and it may be rendered outside the content box. This is default
hidden : the content is clipped - and no scrolling mechanism is provided
scroll : the content is clipped and a scrolling mechanism is provided
auto : should cause a scrolling mechanism to be provided for overflowing boxes
initial : sets this property to its default value.
inherit : inherits this property from its parent element.
example: overflow-y property
<div class="second"> <h4>overflow-y: scroll:</h4> <div class="ex111">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.</div> <h4>overflow-y: hidden:</h4> <div class="ex222">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.</div> <h4>overflow-y: auto:</h4> <div class="ex333">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.</div> <h4>overflow-y: visible (default):</h4> <div class="ex444">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.</div> <style> .second{height: 80vh;} div.ex111 { background-color: lightblue; height: 4vw; width: 20vw; overflow-y: scroll;} div.ex222 { background-color: lightblue; height: 4vw; width: 20vw; overflow-y: hidden;} div.ex333 { background-color: lightblue; height: 4vw; width: 20vw; overflow-y: auto;} div.ex444 { background-color: lightblue; height: 4vw; width: 20vw; overflow-y: visible;} </style>