I have a fixed element locked to the bottom of the page spanning the full width of the window. There are two floating elements (they are clearfixed in the actual code, but not in the fiddle) within this element. The rightmost element is of fixed width and the leftmost element's width is determined by a css calc. The leftmost element's child is significantly wider than it, but it is not causing an overflow scrollbar to appear.
Fiddle: http://jsfiddle.net/hMgR5/3/
Now, one possible solution would be to forgo the native browser support for scrolling and add my own scrolling buttons on both sides of the viewing element, but I would prefer using the browser's native support of scrolling if possible unless user experience with it done this way has been poor.
EDIT: The problem is that the child elements have the same height as the fixed position element. Because of this, the scrollbar is being rendered beneath the fixed element, preventing the user from interacting with it. A more savvy solution may be necessary: possibly doing away with floats and moving to absolute positioning with padding on the end of the overflowing element may work better.
Markup:
<div class="bottom-bar">
<div class="viewer">
<ul class="list">
<li class="element">Hello</li>
<li class="element">World</li>
<li class="element">Hello</li>
<li class="element">World</li>
<li class="element">Hello</li>
<li class="element">World</li>
</ul>
</div>
<div class="other-bar-item">
Other Item
</div>
Styles:
*{
box-sizing: border-box;
font-size: 1em;
font-weight: bold;
color: white;
}
.bottom-bar{
position: fixed;
bottom: 0;
width: 100%;
height: 40px;
background: #1a1a1a;
}
.other-bar-item{
float: left;
width: 200px;
text-align: center;
}
.viewer{
float: left;
width: calc(100% - 200px);
overflow-x: auto;
}
.list{
margin: 0;
padding: 0;
width: 2000px;
height: 40px;
}
.element{
list-style: none;
display: inline-block;
width: 200px;
height: 100%;
position: relative;
background-color: navy;
border-right: 2px solid white;
text-align: center;
}
here is the link: jsfiddle
you don't have to set a high width for your ul,
you can set white-space: nowrap; to parent element and set inline-block display for its children. this would force parent to be as wide as needed.
and you don't need to set overflow:auto; for parent cause it does that automatically.
and here is the code:
.bottom-bar{
position: fixed;
bottom: 0;
width: 100%;
height: 40px;
background: #1a1a1a;
overflow-y: hidden;
white-space: nowrap;
}
.other-bar-item{
display: inline-block;
width: 200px;
text-align: center;
background-color: red;
}
.viewer{
display: inline-block;
}
.list{
margin: 0;
padding: 0;
height: 40px;
}
.element{
list-style: none;
display: inline-block;
width: 200px;
height: 100%;
position: relative;
background-color: navy;
border-right: 2px solid white;
text-align: center;
}
On my mac the scroll bar seems to show up on it's own, not sure why PC was different but, to have the horizontal scroll bar show up (but not a vertical), add the following to the viewer class:
overflow-y: hidden;
height: 100%;
Related
I'm currently making a simple landing page with Bootstrap. My Jumbotron is set to 100VH.
When testing yesterday I noticed the content inside of my Jumbotron breaks when the browser is zoomed in beyond 100%.
Example of what is happening here(Zoom IN): https://jsfiddle.net/y8dnbz3t/
The Code:
CSS
*{margin: 0;}
.jumbotron {position: relative;
width: 100%;
height: 100vh;
background-color: lightblue;
text-align: center;}
/* Div that breaks */
.box {
position: relative;
display: block;
height: 250px;
width: 50%;
background-color: black;
color: white;
text-align: center;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
}
/* Content after 100VH */
.after {
text-align: center;
padding: 10px;
}
What I tried:
I attempted setting the height of the 'Box' to auto. Didn't help.
I do not anticipate that many people zoom in or out.. but this is part of the development process and a bug I'd like to know how to fix.. and what causes it.
How I somewhat Solved it:
I simply changed the height of the Jumbotron from
'height: 100vh'
to
'min-height: 100vh;'
It does not keep the box element at the middle of the div as it should. But, it does solve the simple breaking issue that was occurring before.
I will try and add some transform:translate properties and see if I can get it to center properly this way.
try changing .box class height to 50%
.box {
position: relative;
display: block;
height: 50%;
width: 50%;
background-color: black;
color: white;
text-align: center;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
}
In my navigation I have a protruding red box. I want that red box to overlap all Divs bellow it. I set a margin for it so it would space it out among the other elements I put in the black box. The problem is that it's margin is also effecting the layout of separate elements' children bellow it. When I add a negative margin to the child elements of the section bellow it does overlap but I want the red box to be on-top. I use z-index and it doesn't seem to work.
Here's my example on Jsfiddle:
http://jsfiddle.net/1qsuvhnd/29/
HTML
<nav>
<div id="ribbon"></div>
</nav>
<div id="context">
<div class="link"></div>
</div>
CSS
#context {
width: auto;
padding: 20px;
height: 300px;
background-color: blue;
z-index: 1;
}
#context .link {
float: Left;
height: 260px;
width: 300px;
margin-left: -140px;
background-color: White;
z-index:1 !important;
}
nav {
width: auto;
height: 65px;
background-color: black;
z-index:99 !important;
clear:both;
}
nav #ribbon {
float: left;
margin: 0px 50px;
Width: 65px;
height: 130px;
background-color: red;
z-index= 99;
}
To use z-index, you need to specify a position (like absolute, fixed, or relative).
And the last line written is wrong:
z-index = 99;
The correct way to write it is:
z-index: 99;
How about: http://jsfiddle.net/1qsuvhnd/30/
change the ribbon to position: absolute; and fix the z-index = typo :D
Now you don't need that margin hack!!
nav #ribbon {
float: left;
margin: 0px 50px;
Width: 65px;
height: 130px;
background-color: red;
z-index: 99; /* take that equal out and make it a colon */
position: absolute; /* position: absolute to the rescue!!!! */
}
You need to specify a position CSS rule for the nav div for the z-index to work correctly, like this:
nav #ribbon {
float: left;
margin: 0px 50px;
Width: 65px;
height: 130px;
background-color: red;
z-index:99;
position: relative;
}
Here is the new jsFiddle link:
http://jsfiddle.net/1qsuvhnd/54/
This weird behavior is driving me crazy.
If I upload the page on the server, the first time I open it on chrome/safari I get this problem:
If i refresh it, or when I'm working on the page locally, no problems at all.
The nav simply doesn't expand its width: auto to fit all a floated elements.
This is the really simple code (I deleted not-related rules, but if it could be useful to know I'm using a webfont):
html:
<nav>
button
button
button
<div class="clear"></div>
</nav>
css:
nav {
position: absolute;
top: 50%;
margin-top: -17px;
width: auto;
height: 33px;
}
nav > a {
box-sizing: border-box;
display: block;
float: left;
padding: 11px 13px;
height: 100%;
border: 1px solid #7a7e7f;
}
div.clear {
clear: both;
}
Basically setting the width of the nav element to 100% does the trick. Here’s an optimized example:
HTML
<nav>
button
button
button
</nav>
CSS
nav {
position: absolute;
top: 50%;
margin-top: -17px;
width: 100%;
overflow: hidden; /* Makes the clearing div obsolete */
}
nav > a {
box-sizing: border-box;
float: left;
padding: 11px 13px;
border: 1px solid #7a7e7f;
}
Check it out on Codepen: http://codepen.io/zitrusfrisch/pen/Jcirx
After I did some changes, my feedback div no longer centers on screen and I can't figure out why.
To center a element one only have to set the width and then just do margin: 0 auto; That should normally be enough.
The goal is to have the div shown at the top of the screen, centered. You can see my fiddel here:
http://jsfiddle.net/3u3fd/
Code:
#feedback {
position: fixed;
top: 0px;
min-height: 50px;
width: 300px;
margin: 10px auto;
z-index: 9000;
font-weight: bold;
line-height: 24px;
border: solid 1px #d1d2d1;
padding: 10px;
background-color: #f7f2e7;
display: none;
border-radius: 5px;
-moz-border-radius: 5px; /* FF < 4.0 */
-webkit-border-radius: 5px; /* Rounded corners for Safari */
}
#feedback span { display: block; float: left;}
#feedback #feedback_icon { width: 24px; height: 24px; overflow: hidden; margin-right: 10px; }
#feedback #feedback_text { height: 24px; line-height: 24px; display: inline-block; }
<div class="clearfix" id="feedback" style="display: block;"><span class="dialogFail" id="feedback_icon"></span><div class="" id="feedback_text">Message here</div></div>
Any help appreciated!
auto margins do not work on elements with position: fixed.
Instead, you need to do this:
left: 50%;
margin-left: -Xpx;
width: Ypx;
box-sizing: border-box;
Where X = Y/2.
(The box-sizing: border-box ensures that even if you have padding or borders, it will still be centred. If that interferes with the desired width, then remove it and subtract the value of padding-left + border-left-width from the margin-left.)
You have a fixed position set. Get rid of it and it will center just fine.
In order for margin: 0 auto; to work, the parent element must have a specified width. It can be percentage or units, but it must have it.
For this solution to work in this case, you need to remove the position: fixed; and top declaraions and add a wrapping element.
http://jsfiddle.net/3u3fd/16/
I see that when we use table + tr + td we never see inner elements outside of outer elements.
But in case of Divs it can be.
Now I see that my inner div is located outside of parent div.
How to control child divs? What is wrong in my html?
I mean I have next html and I see that child div is outside of the parent
<div id="page">
<div id="main">
<div id="djInfo">
</div>
<div id="footer">
</div>
</div>
</div>
#page
{
width: 100%;
margin-left: auto;
margin-right: auto;
height: 100%;
position: relative;
}
#main
{
padding: 0px 0px 0px 0px;
background-color: #0c1114;
margin-bottom: 30px;
_height: 1px; /*only IE6 applies CSS properties starting with an underscore */
text-align: center;
height: 100%;
position: relative;
}
#footer
{
color: #999;
padding: 0px 0;
text-align: center;
line-height: normal;
margin: 0;
font-size: .9em;
background-image: url('img/BottomGradient.jpg');
background-repeat:repeat;
height: 160px;
width: 100%;
float: left;
}
#djInfo
{
float: left;
position: relative;
margin-left: 250px;
}
I kinda constructed what you posted and everything seems to work fine?
http://jsfiddle.net/XrDTe/
But please, double check your code, there are some redundancies in it.
(Why give something with 100% width margin-left/right: auto? Why all the float: left's and the position: relative's? Why the IE6 height of 1px? All of this is not necessary and may hinder you in writing decent, to-the-point CSS)