Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS hide scroll bar if not needed

Tags:

html

css

I am trying to figure out how I can hide the overflow-y:scroll; if not needed. What I mean is that I am building a website and I have a main area which posts will be displayed and I want to hide the scroll bar if content does not exceed the current width.

Also, my second question. I want to make it so when the posts exceed the current width, the width will increase automatically and the content won't go out of the box.

Does anyone have a clue how to do this?

Posts area:

.content {     height: 600px;     border-left: 1px solid;     border-right: 1px solid;     border-bottom: 1px solid;     font-size: 15px;     text-align: justify;     line-height: 19px;     overflow-y:scroll; } 

Main website container:

.container {     margin: 0 auto;     width: 757px;     margin-top: 30px;     text-align: center; } 
like image 247
Thanos Paravantis Avatar asked Sep 10 '13 10:09

Thanos Paravantis


People also ask

How do I show the scroll bar only when needed CSS?

Use overflow: auto . Scrollbars will only appear when needed. (Sidenote, you can also specify for only the x, or y scrollbar: overflow-x: auto and overflow-y: auto ).

How do I get rid of the scroll bar?

Type "Remove Scrollbars" (without quotes) in the search box and press "Enter." Click the "Remove Scrollbars" option located on top of the search results.


2 Answers

Set overflow-y property to auto, or remove the property altogether if it is not inherited.

like image 119
RJo Avatar answered Oct 28 '22 03:10

RJo


You can use overflow:auto;

You can also control the x or y axis individually with the overflow-x and overflow-y properties.

Example:

.content {overflow:auto;} .content {overflow-y:auto;} .content {overflow-x:auto;} 
like image 32
Ayyappan K Avatar answered Oct 28 '22 04:10

Ayyappan K