how to hide a vertical scroll bar when not needed

HtmlCssForms

Html Problem Overview


I have a textarea which is contained in a div as I have jquery hint and wanted to use opacity without changing the border. There is a visible vertical scroll bar how I only want this displayed when I am typing in the text field and it goes beyond the container. I have tried overflow: auto; but does not work.

Textfield:

<label>
    <div id="name">
        <textarea name="message" type="text" id="message"
            title="Enter Message Here"
            rows=9 cols=60 maxlength="2000"></textarea>
    </div>
</label>

Styles:

#name { 
    border: 1px solid #c810ca;
	width: 270px;
	height:159px;
	overflow: hidden; 
	position: relative;
	}

#message {
	height: 400px;
	width: 235px;
	overflow: hidden;
	position: absolute;
}

Html Solutions


Solution 1 - Html

overflow: auto (or overflow-y: auto) is the correct way to go.

The problem is that your text area is taller than your div. The div ends up cutting off the textbox, so even though it looks like it should start scrolling when the text is taller than 159px it won't start scrolling until the text is taller than 400px which is the height of the textbox.

Try this: http://jsfiddle.net/G9rfq/1/

I set overflow:auto on the text box, and made the textbox the same size as the div.

Also I don't believe it's valid to have a div inside a label, the browser will render it, but it might cause some funky stuff to happen. Also your div isn't closed.

Solution 2 - Html

overflow: auto; or overflow: hidden; should do it I think.

Solution 3 - Html

Add this class in .css class

.scrol  { 
font: bold 14px Arial; 
border:1px solid black; 
width:100% ; 
color:#616D7E; 
height:20px; 
overflow:scroll; 
overflow-y:scroll;
overflow-x:hidden;
}

and use the class in div. like here.

<div> <p class = "scrol" id = "title">-</p></div>

I have attached image , you see the out put of the above code enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLukusView Question on Stackoverflow
Solution 1 - HtmlDavy8View Answer on Stackoverflow
Solution 2 - HtmlBoris BachovskiView Answer on Stackoverflow
Solution 3 - HtmlDareDevilView Answer on Stackoverflow