HTML: How to create a DIV with only vertical scroll-bars for long paragraphs?
Use overflow-y
. This property is CSS 3.
How to create div with vertical scroll bar only for long content
If you set width:100%
to #scrolldiv
the problem will be solved.
Because the width
of the #scrolldiv
was bigger than parent width
the horizontal scrollbar was activated for the parent.
#scroldiv { margin-left: auto; margin-right: auto; overflow-y: scroll; overflow-x: hidden; width: 100%; height: 1200px; background-color: wheat;}#iframe { width: 803px; height: 1000px; background: #FFFFFF;}
<script src="script/jquery-1.11.1.min.js"></script>
<form id="form1" runat="server"> <div id="scroldiv" style=""> <iframe id="iframe" scrolling="auto" frameborder="0" onload="window.scrollTo(0, 0)" src="http://www.myhotels24.eu/fibe.aspx?hid=10000&chid=0&rate=IBE&css=brown" allowtransparency="true"></iframe> </div>
</form>
Making a div vertically scrollable using CSS
You have it covered aside from using the wrong property. The scrollbar can be triggered with any property overflow
, overflow-x
, or overflow-y
and each can be set to any of visible
, hidden
, scroll
, auto
, or inherit
. You are currently looking at these two:
auto
- This value will look at the width and height of the box. If they are defined, it won't let the box expand past those boundaries. Instead (if the content exceeds those boundaries), it will create a scrollbar for either boundary (or both) that exceeds its length.scroll
- This values forces a scrollbar, no matter what, even if the content does not exceed the boundary set. If the content doesn't need to be scrolled, the bar will appear as "disabled" or non-interactive.
If you always want the vertical scrollbar to appear:
You should use overflow-y: scroll
. This forces a scrollbar to appear for the vertical axis whether or not it is needed. If you can't actually scroll the context, it will appear as a"disabled" scrollbar.
If you only want a scrollbar to appear if you can scroll the box:
Just use overflow: auto
. Since your content by default just breaks to the next line when it cannot fit on the current line, a horizontal scrollbar won't be created (unless it's on an element that has word-wrapping disabled). For the vertical bar,it will allow the content to expand up to the height you have specified. If it exceeds that height, it will show a vertical scrollbar to view the rest of the content, but will not show a scrollbar if it does not exceed the height.
How to have only a vertical scroll bar on a div
You are hiding the vertical scrollbar, and not the horizontal one.
Change overflow-y: hidden;
to overflow-x: hidden;
Heres a quick demo
I've added content surpassing the height, and a div
with a width greater than 340px inside #CamListDiv
. The content is only scrollable vertically.
Adding Vertical Scrollbar in Paragraph inside Div
Short and quick answer, add a scrollbar to the #bodydesc
by adding overflow-y
to the style attribute:
<div id="bodydesc" style="margin-left:auto; margin-right:auto; width:960px; height: 600px; overflow-y: scroll;">
<p id="desc" style="float:left;color: #666666; width:700px; font-family: Candara,Trebuchet MS,sans-serif; font-size: 12px; font-weight: bold; border-right: thin dotted #666666; line-height: 18px;">
//Here is my large content with images...
</p>
</div>
The front end developer that is in me insists that I tell you to move all those style declarations in an external css file.
Scrollable table vertical only
The overflow-y
property 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.
<div style="height: 700px !important; width: 100%; overflow-y: scroll;">
<table class="table table-bordered">
<!-- Content Here -->
</table>
</div>
How to add vertical scroll bar to one div only without specifying height?
Fiddle http://jsfiddle.net/RSh9H/2/show/
Corrected Fiddle : http://jsfiddle.net/RSh9H/8/show/
jQuery:
$(window).on('load resize',function(){
var heightOfWindow = $(window).height();
var totalHeightOfContents = $(document).height();
if(heightOfWindow <= totalHeightOfContents){
var heightExcludingInfo = $('table#main').height() - $('#info').height();
var availableHeightForInfo = heightOfWindow - heightExcludingInfo;
$('#info').height(availableHeightForInfo);
}
else{
$('#info').css({height:'auto'});
}
});
Horizontal and vertical scroll bar if the content overflows the specified width and height in div
Instead of using float
, you could use display: flex
.
display: flex
aligns block
children side-by-side (similar to float
). Adding flex: 0 0 auto;
to these children stops them from wrapping.
To display the horizontal scrollbar, you can use overflow-x: auto;
.
.container { display: flex;}
#myLeft { width: 20%;}
#myRight { width: 80%; display: flex; overflow-x: auto;}
.displayBox { width: calc(100% / 3); /* to achieve perfect thirds */ flex: 0 0 auto; height: 60px; overflow: auto;}
<div class="container"> <div id="myLeft"> <h4>Left Content</h4> </div> <div id="myRight"> <div class="displayBox"> <p>Display the first content on BOX 1</p> </div> <div class="displayBox"> <p>Display the first content on BOX 2. The content might overflow if it exceeds the height of 60px otherwise its perfectly fine.</p> </div> <div class="displayBox"> <p>Display the first content on BOX 3</p> </div> <div class="displayBox"> <p>Display the first content on BOX 4 and horizontal scroll bar</p> </div> </div></div>
How do I make the scrollbar on a div only visible when necessary?
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
).
Related Topics
CSS Webkit Transition - Fade Out Slowly Than Fade In
How to Change Img Src Attribute Using CSS
CSS 3D Transforms Works at Random in Chrome 16
Using Two CSS Files in the Same HTML File
Modernizr Reporting Laptop as Touch Device in Chrome and Ff
Multiple Background Images Using SASS/Compass
Wobbly CSS Animation with Border-Radius in Internet Explorer
Global Disable Magnifying Glass on iOS 9 in Meteor Cordova App
Combining Pseudo-Selectors in CSS
How to Over-Ride an @Media CSS for a Material-Ui React Component
How to Style the Scrollbar of on Iframe
Using Position:Absolute to Set an Inputs Width
Cross-Browser CSS3 Keyframe Animation Firefox
Force Elements to Be Horizontally Aligned
CSS Background Image Centered with Stellar Js
Background Url Path in a Jsf Template
Fluid Navigation Items of Different Widths with Equidistant Spacing