How can I prevent horizontal overflow? - html

Say I have a <span> that contains a very long sequence of numbers - long enough that it flows right off the right hand side of the page.
Most browsers would give me a scrollbar such that I can then scroll left and right.
How can I prevent the ability to horizontally scroll?
I've tried body { overflow-x: hidden; }, which works for desktop Chrome, but Chrome for Android retains the ability to horizontally scroll.
How can I absolutely guarantee no scrolling?
(I can adjust both HTML and CSS in this scenario, but I cannot use JS.)

Do you mind breaking the string of numbers? If not, you can try word-break:break-all. Here's the same HTML with and without word-break.
#break {
width: 300px;
word-break: break-all;
padding: 3px;
}
#noBreak {
width: 300px;
padding: 3px;
}
<div id="break">
<span>123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789
</span>
</div>
<div id="noBreak">
<span>123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789
</span>
</div>

I think applying overflow-x :hidden works.
But unless you share the part of your code its difficult to answer to your requirement.
The better approach i would suggest is to use the container class of bootstrap 4, which makes the div responsive and you can keep this span inside that, or keep it in the div.
<div class="wrapper container">
<div class="row">
...
</div>
</div>
The row class will always give -15px margins.
and container class gives padding of +15px.
Your question can get a clearer response if you can share the code snippet.

Related

Putting box-shadow on site-wrapper

Here's the page that I'm having trouble with. You can see that when I scroll down the shadow is in the wrong place. http://michaelaharvey.github.io/
I'm trying to make my page have have box-shadow css property. However, I can't seem to make box-shadow apply to the entire webpage. As a result, when I scroll down there is a shadow in the middle of the page when there shouldn't be. I tried using...
#site-wrapper {overflow: hidden;}
...but that caused my page-jump navigation to break. How can I set the div height of site-wrapper equal to the entire page, including all the overflow? Thank you!!!
You have to make one more element that wraps up the .cover-container
<div class="site-wrapper-inner">
<div class="cover-wrapper">
<div class="cover-container">
....
</div>
</div>
</div>
then place its CSS like
.cover-wrapper {
height: 100%;
overflow-x: hidden;
}
since you use table and table-cell in .site-wrapper and .site-wrapper-inner
so you must add something to wrap the content in order to control its height

scrollable html panel with scroll buttons using css and flexbox

I'm having layout difficulties when creating a scrollable panel using css and flexbox. I saw this one (http://jsfiddle.net/5A9c9/)
that works well as long as no elements are added into the divs. When I modify that and add one line (line 11 in http://jsfiddle.net/5A9c9/7/), the layout is completely messed up. It could be almost any other tag and it still gets messed up.
`<!-- adding this line messes it up -->
<p>abcd</p>`
How do I get this to lay itself out properly?
p.s. or any other full working examples of such a panel using only css and flexbox?
Edit:
One of the issues I hit with the scrollable area using flexbox was that the elements were getting crushed and force-fitted into the area, and therefore it had no chance to scroll.
To start with, use "display:flex" in your CSS if you want to use the flexbox magic.
Set display to flex in both the outer and inner divs like so:
#scrollBox {
display:flex; /* <--- here */
overflow-x: auto;
overflow-y: hidden;
-ms-overflow-x: auto;
-ms-overflow-y: hidden;
white-space: nowrap;
}
#scrollBox > div {
display: flex; /* <--- and here */
margin-right: 10px;
}
Secondly, in your html, put your "abcd" paragraph inside the fieldset. I can't imagine you would want it outside of the fieldset... Like this:
<div class="firstPanel">
<fieldset class="firstPanel">
<legend>Panel 1</legend>
<p>abcd</p>
</fieldset>
</div>
I hope this helps some :-)
I came across this page http://fantasai.inkedblade.net/style/discuss/flexbox-min-size/ which gave me a hint on why the components were getting crushed or started overlapping within my supposed scrollable area. To solve it, I put a min-width size to the elements/components within my scroll area. This allows the scroll to happen.

Div getting pushed to the right when using float:left on it

I'm currently creating a website and I came across a strange thing: I have a content div that's 950 width and centered on the page. Inside that I have a header div, a menu div and some other content div. I would like the menu div and that other content div to be right next to each other so I thought about using float:left on both divs. However, when I use this float:left on the menu div, it's getting pushed to the right and I can't figure out why. I think some other element is pushing it to the right.
I'm using a custom Drupal theme, a subtheme of Zen to create the page by the way.
Here's the HTML I'm using to create the page (without the header):
<div id="root">
<div class="content">
<div class="left-menu">
<ul>
<li><p>Camera</p></li>
<li><p>Audio</p></li>
<li><p>Licht</p></li>
<li><p>Lenzen</p></li>
<li><p>Grip</p></li>
<li><p>Accessoires</p></li>
<li><p>Recorders</p></li>
<li><p>Transport</p></li>
<li><p>Edit suits</p></li>
<li><p>Crew</p></li>
</ul>
</div>
<div class="products-overview">
This is some other content that I want to the right of the menu.
</div>
</div>
And here are some CSS properties I've set on left-menu and products-overview:
.left-menu {
margin-top: 10px;
background-color: #BBB;
width: 150px;
float: left;
}
.products-overview {
background-color: #BBB;
float: left;
}
Could anyone please explain me why the left-menu is being pushed to the right?
Hmm, I believe this is a result of the normalize.css stylesheet you're using.
The problem stems actually from the .header element, which has a table within it. The normalizing stylesheet has a margin-bottom:1.5em applied to the table, which translates into a margin on the .header element (since it has no padding/border), which in turn sends the .left-menu to the right (since the margin causes there to be no space for it to fit on the left).
Adding to your current .header table definition can fix this, with a simple:
.header table{
margin-bottom: 0;
}
I hope this is what you were looking for! If not, let me know and I'll be happy to help further. Good luck!
I tried to replicate your problem. I did and found a solution that should work. Just set the products-overview class to float:none. See this fiddle. http://jsfiddle.net/shaansingh/yj4Uc/
In Mozilla Firefox it looks ok to me. From your code, I can only see that you need a width for the content div. and watch the dimensions, especially left/right padding and borders.

CSS3 columns: how to get proper horz padding with overflow-x?

So, I'm playing with CSS3 columns and trying to lay out content in a bunch of horizontal columns where, if the content is long enough, it creates a horizontally scrolling page. However, I don't want the content to butt right up against the left/right edges of the viewport but I do want the scrollbar to touch the left/right edges. I thought I could do this with padding, and initially it looked like it was working perfectly, until I scrolled all the way to the end of the content.
The code is pretty simple. HTML:
<section id="content">
<p>Lorem ipsum...</p>
<p>And a bunch more paragraphs to overflow the viewport...</p>
</section>
And the CSS:
#content {
height: 400px;
padding: 10px 50px;
column-count: 2;
column-gap: 50px;
-webkit-column-count: 2;
-webkit-column-gap: 50px;
overflow-x: scroll;
overflow-y: hidden;
}
#content p {
/* just to make it easier to see the boundaries */
background-color: rgba(255,0,0,0.1);
}
​
I also set up a fiddle here: http://jsfiddle.net/uu9Tv/.
I've tried a bunch of things, but nothing seems to give the desired effect... margins on #content cause the scrollbars to not reach the sides of the viewport.
I also tried it a different way and basically let a wrapper div handle the overflow/scrolling and putting horizontal margins on the #content element, but it didn't seem to help at all. See here: http://jsfiddle.net/vQLCz/.
Anyone able to shed any light on how to get some space on the far right of the columned content in a horizontally scrolling layout?
Your approach makes sense, but padding section#content doesn't apply to the overflowed content. Having columns makes this harder to see, so first look at my example section#no-columns in http://jsfiddle.net/ansonhoyt/wGKFa/. The section contains a paragraph with nowrap. Notice how the padding constrains the background color, but not the overflowing text.
When you add columns into the mix, the padding still doesn't apply to the overflowed paragraphs. A good alternative would be to put a margin on the <p>. This solution is limited. Since margin provides both the right "padding" and the "gap", they both have to be 50px.
Ah, the limits of CSS. CSS3 columns are nice, but limited....we can hope CSS4 will add some more elegant additions like p:last-column { margin-right: 50px; }.

Setting the width of HTML div's with %'s

Here is the relevant HTML:
<div class="row">
<div class="arrow box">◄</div>Month Year<div class="dayMonth box"></div>►<div class="arrow box"></div>
</div>
Here is the css which the .html file that the above HTML is in links to:
*
{
margin: 0;
padding: 0;
}
body
{
font-family: "Times New Roman";
font-size: 12pt;
}
.dayMonth
{
width: 80%;
}
.arrow
{
width: 10%;
}
.row
{
width: 58em;
background-color: gray;
margin-right: auto;
margin-left: auto;
}
.box
{
float: left;
text-align: center;
}
This is the output:
The "row" is centering in the browser right but the stuff inside it (the two arrows and the Month Year) aren't doing what I want.
What I think this should be doing is, because there are two arrows and both of their widths is sent to 10% and then the dayMonth width is 80% that all the divs should take up the entire "row" (because they sum to 100%) and that the text "Month Year" should be centered within the "row" because the .dayMonth css class says it should be centered in its div and because its div should be the center 80% of the "row". This, obviously, isn't happening though.
I don't want a different solution (per se) I want to know why the code I've written doesn't express the idea that I want it to express, doesn't work the way I want it to.
I think I must be misunderstanding how %'s governs widths. http://www.w3schools.com/css/pr_dim_width.asp says that %'s "Defines the width in percent of the containing block" though and that looks like %'s should do what I intend them to do so I'm thoroughly confused.
Where have I gone wrong?
This works fine for me in Opera.
I did notice that you have "Month Year" outside of the <div>. Try putting it inside and see if that fixes it.
Edit
And again with the last arrow, it's outside its <div> tag as well.
Your HTML should be like this:
<div class="row">
<div class="arrow box">◄</div><div class="dayMonth box">Month Year</div><div class="arrow box">►</div>
</div>
Also, once you do this, the row <div> will not have a height so you might want to explicitly set a height (try 20px).
Once i fix your HTML, it works fine for me in FF. You have empty divs and the Month Year and left arrow are not in their respective divs.
I figured this out real quick when i used firebug. You should debug using firebug or chrome's developer tools.
<div class="row">
<div class="arrow box">◄</div><div class="dayMonth box">Month Year</div><div class="arrow box">►</div>
</div>
Try the code like this, with the content inside the divs. Worked for me in FF, IE7/8, and Chrome. You may want to use a hex value for the .row color, like #333333 - the color wasn't rendering for me in any browser but IE7.
First, your markup is wrong, that's why you're seeing issues. It has to do with the content not being in the divs, but outside of them, causing height issues with the floated elements.
Here's the work corrected:
http://jsbin.com/ezari4/edit