Awan
Awan

Reputation: 18580

HTML: How to create a DIV with only vertical scroll-bars for long paragraphs?

I want to show terms and condition note on my website. I dont want to use text field and also dont want to use my whole page. I just want to display my text in selected area and want to use only vertical scroll-bar to go down and read all text.

Currently I am using this code:

<div style="width:10;height:10;overflow:scroll" >
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
 text text text text text text text text text
</div>

Two Problems:

  1. It is not fixing the width and height and spread until the all text appears.
  2. Second it is showing horizontal scroll-bar and I don't want to show it.

Upvotes: 158

Views: 545967

Answers (11)

Neil Horne
Neil Horne

Reputation: 71

Sometimes this helps: Remember that the vertical scrollbar takes up horizontal space. You might have had a display that works well with width: 100% and too little content to warrant a vertical scrollbar. Then when you add more content, you get the vertical scrollbar - as expected - but while the content wraps its overflow in the div, an annoying horizontal scrollbar pops up too. The reason is that the vertical scrollbar itself take up some horizontal space, and the horizontal bar appear to allow the reader to scroll underneath the vertical scrollbar. The way around this is to shorten the width. e.g width: 95% would remove the horizontal bar, showing only the vertical one.

Upvotes: 0

Daniel De Le&#243;n
Daniel De Le&#243;n

Reputation: 13649

This is my mix:

overflow-y: scroll;
height: 13em; // Initial height.
resize: vertical; // Allow user to change the vertical size.
max-height: 31em; // If you want to constrain the max size.

Upvotes: 2

singhkumarhemant
singhkumarhemant

Reputation: 177

I also faced the same issue...try to do this...this worked for me

        .scrollBbar 
        {
        position:fixed;
        top:50px;
        bottom:0;
        left:0;
        width:200px;
        overflow-x:hidden;
        overflow-y:auto;
       }

Upvotes: 3

janmoesen
janmoesen

Reputation: 8020

Use overflow-y. This property is CSS 3.

Upvotes: 290

Brane
Brane

Reputation: 3339

For any case set overflow-x to hidden and I prefer to set max-height in order to limit the expansion of the height of the div. Your code should looks like this:

overflow-y: scroll;
overflow-x: hidden;
max-height: 450px;

Upvotes: 21

raji
raji

Reputation: 191

Thank you first

Use overflow:auto it works for me.

horizontal scroll bar disappears.

Upvotes: 19

Amobi Chuks
Amobi Chuks

Reputation: 41

overflow-y : scroll;
overflow-x : hidden;

height is optional

Upvotes: 4

Sunil Kumar
Sunil Kumar

Reputation: 665

You can use the overflow property

style="overflow: scroll ;max-height: 250px; width: 50%;"

Upvotes: 3

Daniel Vassallo
Daniel Vassallo

Reputation: 344351

You need to specify the width and height in px:

width: 10px; height: 10px;

In addition, you can use overflow: auto; to prevent the horizontal scrollbar from showing.

Therefore, you may want to try the following:

<div style="width:100px; height:100px; overflow: auto;" >
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
  text text text text text text text text text
</div>

Upvotes: 61

Ricardo Romo
Ricardo Romo

Reputation: 1624

To show vertical scroll bar in your div you need to add

height: 100px;   
overflow-y : scroll;

or

height: 100px; 
overflow-y : auto;

Upvotes: 15

Kornelius
Kornelius

Reputation: 1819

to hide the horizontal scrollbars, you can set overflow-x to hidden, like this:

overflow-x: hidden;

Upvotes: 86

Related Questions