Force browser to always scroll horizontally? - css

Is there a way to force a browser to always scroll horizontally?
Without setting a fixed width on any divs?
I've made it so that the Div in question (which contains a table) will scroll with:
overflow-x:auto;
But I need the browser scroll bars to be used, and not scroll bars on the div itself.
The page code looks similar to this:
<div id="content">
<div id="MenuContainer">
.....various divs for menu
</div>
<div id="TableContainer">
...ASP Gridview that renders a table
</div>
</div>
I want to be able to make the page scroll horizontally using the browsers scroll bars, Firefox does this already with the code as it is, but IE6,7,8 all force the content in the "TableContainer" div to go below the menu.
The menu and the table container are both floated left.

Try to set this:
{overflow-x:scroll}
on the body of css

I presume you're using floats just now? you can force floats to sit side by side in IE7 by triggering hasLayout (zoom: 1;) but not in IE8 so I'd use the table display properties instead of floats and feed IE7 the floated version with the hacks or put the IE7 properties in a conditional CSS
try this:
#MenuContainer {
float: left !ie7;
display: table-cell;
min-width: 300px;
background: #cfc;
}
#TableContainer {
zoom: 1 !ie7;
display: table-cell;
}
added jsfiddle

Related

display inline-block not applying

I am trying to align the first two divs inside "product-details" class. I removed the last div with clear:both; I gave 150px width to the first div with class "text-center".I gave display:inline-block and position:relative to both of the first divs. I made width of the second div auto.
When I check the computed values in the inspect element the first div is not accepting the display:inline-block. It shows display:block; and the two divs are not aligned horizontally. I have had this situation before also.
div.text-center {
display: inline-block;
position: relative;
}
div:nth-child(2) {
display: inline-block;
position: relative;
}
<div class="product-details">
<div class="text-center">...</div>
<div>...</div>
<div style="clear:both;"></div>
</div>
div.text-center is not taking display inline-block instead shows display block in the element inspector
The code does work. I right clicked on the second ... and clicked inspect element. You can see in the "Elements" tab then in the "Styles" tab that the default display: block was overridden by display: inline-block. What browser are you using? This is on the latest version of Chrome that I am getting this result.
As pointed out above, the code should work. You can try and force it to work by adding an important rule
div.text-center {display: inline-block !important;}
I removed floats and display changes from block to inline-block as required. That was the only option. Also I need to remove width auto and give width in % for both divs to align them horizontally. This was the solution I found. Thanks for your answers.

two divs with display:inline-block - second div with iframe ad being pushed down a few pixels

Background: working on a responsive redesign. normalize.css used for reset.
DFP Ads inserted into div's using this technique. The ad container div's are hidden depending on window size and the ad iframe's are only inserted once into the non-hidden div. I also have a site logo div, .brand, that is hidden or not depending on width. Both the ad div container, .ta, and the logo container, .brand, are contained within a div called .secondnav. All three divs are 90 px tall. .brand, #ldr and .ta are all display:inline-block.
When .brand is display:none, the iframe ad in #ldr div contained by .ta sits perfectly within the height of 90px.
When the window is a bit bigger and .brand becomes display:inline-block, .ta suddenly gets pushed down about 4-5 pixels. They're still side by side but suddenly the ad is a few pixels lower.
I can't see what could be pushing it down. I thought it could be how the div is interacting with the ad's iframe, but why is it only happening when it's next to another inline-block div?
Here's the CSS:
.brand {
width:200px;height:90px;
background:#660000 url('/dh5.svg') no-repeat left top;
display:inline-block
}
.multiplebgs .brand {
width:200px;height:90px;
background-color:#fff;
background-image:url(/dh5.svg),url(/dhw.svg);
background-position:0 0,30px 0;
background-size:30px,170px;
background-repeat:repeat-y,repeat-y;
display:inline-block
}
.ta {
height:90px;
display:inline-block
}
.secondnav {
height:90px;
background:url('/fs.jpg') 0 0 repeat
}
#ldr {
background:blue;
width:728px;height:90px;
display:inline-block
}
#mldr {
background:yellow;
width:320px;height:50px;
display:inline-block
}
#smallban {
background:green;
width:468px;height:60px;
display:inline-block
}
Here's the html:
<div class="secondnav">
<div class="brand"></div>
<div class="ta">
<div id="ldr" class=
"adslot hidden-phone hidden-tablet visible-desktop" data-dfp=
"728x90"></div>
<div id="mldr" class=
"adslot hidden-desktop hidden-tablet visible-phone" data-dfp=
"320x50"></div>
<div id="smallban" class=
"adslot visible-tablet hidden-phone hidden-desktop" data-dfp=
"Smallbanner"></div>
</div>
</div>
Wasn't sure if I could include an URL to my test page so you could see this in action. Will edit it and include one if it's kosher. Will Google more on iframe alignment but thought I'd ask here. Thanks.
My test is here: http://www.digitalhit.com/bptest/index.shtml The issue appears at any size where there is an ad next to the .brand. e.g. at 480px, 600px, 1024px or higher. Please ignore the garish colours, just there for seeing the divs clearly as I test the design.
Try this in the iFrame:
style="border: 0px; top:0px;"
Despite Sergio's great suggestions, I couldn't get it to work for me, probably as I had no control over the HTML in the iframe ad from Google. Going back to floating the .brand div to the left and centering a width-defined div containing .brand and the ad divs worked for me and everything was vertically aligned.

Outer Div will not stretch to fit inner div (using clear)

I've been reading about how elements with the float attribute do not have their height accounted for. Therefore, I should use clear:both right before the end of the parent div so that it will stretch over the entire inner div.
You can see on This Page that the div with the id full-height-template-container is not stretching over its inner content, and therefore the footer (copyright text on the bottom right) is coming up too high on the page.
The layout looks like this:
<div id="full-height-template-containter">
<div id="content-container">
<div id="full-width" style="float:left;">
</div>
<div style="clear:both;"></div>
</div>
<div style="clear:both;"></div>
</div>
What else can I try in order to make the outer div stretch over its children?
Thanks in advance!
That's a common problem. To solve it, the clearfix hack in its many variants was invented.
I was confronting the same issue until I inserted this version of "Clearfix" at the top of the container that needs to be stretched as such:
CSS:
.clearfix:after {content: "."; display: block; height: 0; clear: both; visibility:hidden;}
.clearfix {display: inline-block;}
/* Hides from IE-mac \*/
* html .clearfix {height: 1%;}
.clearfix {display: block;}
/* End hide from IE-mac */
HTML:
<div class="clearfix"> </div>
<span class="doc">
John Nixon
Henry Wright
</span>
In #full-height-template-container you are using height: 100% which means the div takes 100% height of the parent.
If we track back in your CSS each parent element is assigned height: 100%, including the html and body elements, which means that the height is taken from the window - so as a result the div will never exceed the size of the window (but content will still overflow).
So it is not the floats that are causing the problem, it is the height you are explicitly assigning to each div.
i put your sample on fiddle and gave it some css to show the divs:
http://jsfiddle.net/WRzsE/
You can clearly see that it works perfectly as you describe you would expect it to. You are doing something else wrong i suspect...
Perhaps you are using a position: absolute somewhere, wich would cause the elemnt to be lifted out of its parent, and would make the parent not stretch (just thinking out loud here...)
edit:
I just took a look at the actual page (overlooked the link). Your div's are stretching just fine. The problem is with the positioning of your footer, wich is set to absolute. I suspect you are trying to achieve a sticky footer, have a look at this, works like a charm. I use it all the time: http://ryanfait.com/sticky-footer/

Firefox overflow:scroll resize issue

In Firefox......
<div id="container" style="overflow:scroll; width:400px; height:500px">
<div id="content" style="height:500px; width:800px"/>
</div>
The "container" DIV should have scroll bars since the div with id "content" is wider than it.
If, using JavaScript (see below), I reset the size of the "content" div to "200px", I would expect the scroll bars on the div "container" to disappear. They dont, unless I manually resize the the browser window.
function Resize() {
document.getElement("content").style.width="200px";
}
I tried forcing a reflow on container by applying a css class. This didnt work...
function Resize() {
document.getElement("content").style.width="200px";
document.getElement("container").className="test";
}
Setting overflow: scroll; should force scrollbars to be on.
If you want them to appear and disappear with the content size, try overflow: auto;

Internet explorer creates horizontal scrollbar for vertical scrollbar's width

A div, containing a table has the following CSS styling:
#formulaAlts {
float: right;
height: 200px;
overflow: auto;
}
This makes it so that when the table is >200px, a scrollbar appears only for the table and the other elements on the page stay put. Great!
Now for our friend IE...
In IE, the element spawns the vertical scrollbar without growing the containing element. To "solve" this, a horizontal scrollbar is created.
That sucks. And I don't want it to suck...
Any ideas?
--EDIT--
I found out that the line
overflow-x: hidden;
forces IE to ignore the horizontal scrollbar. This is better.. but not quite there because now part of my table is invisble.
Careful.
overflow-x
isn't the most widely supported attribute out there.
I tend to go with a containing div with some right padding:
CSS:
div.scroll {
overflow:auto;
padding-right:6px;
/* I've found 6px to be just right my purposes, but try others*/
}
EDIT: You'll need to add a height attribute somewhere for this to work! I usually have a default set in the div.scroll declaration then tweak that for specific cases (most).
HTML:
<div class="scroll" >
<table>
<!-- your table stuff in here -->
</table>
</div>

Resources