Multi-pane scrolling via CSS - javascript

I would like to create a dual pane view, where the top banner of the screen is fixed, while the bottom can scroll horizontally. As the user scrolls horizontally, they should still be able to see the same top banner. I've attached some sample code and a corresponding jsfiddle.
The problem is that as the user scrolls past GROUP2 to GROUP3, the top header gets cropped. I would like the header to continue across the top of the screen as the user scrolls.
<div>
<div class="header">
COMPANY NAME
</div>
<div class="scroller">
<div class="group1">
GROUP1
</div>
<div class="group2">
GROUP2
</div>
<div class="group3">
GROUP3
</div>
</div>
</div>
.header {
width:100%;
height:60px;
background:red;
}
.scroller {
overflow-y:hidden;
overflow-x:scroll;
}
.group1 {
top:80px;
left:0px;
width:500px;
position:absolute;
}
.group2 {
top:80px;
left:540px;
width:500px;
position:absolute;
}
.group3 {
top:80px;
left:1080px;
width:500px;
position:absolute;
}

try this updated fiddle
.header {
width:100%;
height:60px;
background:red;
position: fixed;
top:0px;
left:0px;
}

Related

How do I get a fixed scrolling div to scroll with the rest of the window?

Here's the jfiddle http://jsfiddle.net/pq5ckkcg/4/. I basically need the whole window and div to scroll together no matter where the mouse is. How would I accomplish this?
<div id="bottomwrap">
<div id="element"></div>
<div id="element"></div>
<div id="element"></div>
</div>
#bottomwrap {
position:fixed;
top:45px;
right:0;
width:80%;
overflow-y:scroll;
bottom:0;
background-color:#666;
}
#element {
float:left;
width:200px;
height:300px;
background-color:#000;
margin:20px;
}
Your parent div needs to be relative positioned:
#bottomwrap {
position:relative;
margin-top:45px;
float: right;
width:80%;
overflow-y:scroll;
bottom:0;
background-color:#666;
}
http://jsfiddle.net/pq5ckkcg/3/

obtain a table/chart design overlapping divs

I've been wondering for the past few days on how to obtain such as design as the one attached below. First of all, my concern is the "sparkline/area" chart at the bottom of the table/divs.
I can't wrap my head around on how I can code something like this. The chart data should "overlap" each div - how is that done? Should I maybe use a table?
Could someone, please try to help me out here. A quick code example on how to obtain the overlapping effect would help tremendous.
If this post doesn't belong on Stackoverflow, please accept my apologies.
Use z-index to position element above/below other elements:
HTML
<div class="wrapper">
<div class="row">
<div class="col">One</div>
<div class="col above">Two Above</div>
<div class="col">Three</div>
<div class="col above">Four Above</div>
<div class="col">Five</div>
</div>
<div class="btmOne"></div>
<div class="btmTwo"></div>
</div>
CSS
.wrapper{
width:500px;
height:150px;
position:relative;
}
.row{
width:500px;
height:150px;
background-color:gray;
}
.btmOne{
position:absolute;
bottom:0px;
left:0px;
width:500px;
height:50px;
background-color:red;
opacity:0.5;
z-index:1;
}
.btmTwo{
position:absolute;
bottom:0px;
left:0px;
width:500px;
height:30px;
background-color:blue;
opacity:0.5;
z-index:10;
}
.col{
float:left;
background-color:lightgray;
width:98px;
border:1px solid gray;
height:148px;
position:relative;
text-align:center;
line-height:100px;
font-weight:bold;
}
.col.above{
z-index:5;
}
To make the column come forward just add the class 'above' to the row.
See here for an example:
jsFiddle example

Two fixed width divs, and another div with dynamic size between

The title says everything. I want something like this:
The left box should be positioned in the left, the right one in the right. They both should have fixed widths, e.g. 200px. The middle div should take the size between. Its width is not set, but it takes the width that's remaining.
Thanks.
Here's a working one.
Use margin: 0 auto; will get your element centered most of the time. (Quick note: your element must have a declared width for this to work.)
The margin: 0 auto; rule is shorthand for 0 top and bottom margin, and automatic left and right margins. Automatic left and right margins work together to push the element into the center of its container.
The margin: 0 auto; setting doesn't work perfectly in every centering situation, but it works in a whole lot of them.
reference: You Can't Float Center with CSS
HTML
<div class="leftsidebar">a</div>
<div class="rightsidebar">b</div>
<div class="content">c</div>
CSS
.leftsidebar
{
height: 608px;
width: 60px;
background:red;
float:left; }
.rightsidebar
{
background:blue;
height: 608px;
width: 163px;
float:right;
}
.content
{
width: auto; //or any width that you want
margin:0 auto;
background:yellow;
}
Here is the DEMO http://jsfiddle.net/yeyene/GYzVS/
Working great on onReady and onResize too.
JS
$(document).ready(function(){
resizeMid();
$(window).resize(function() {
resizeMid();
});
});
function resizeMid(){
var mid_width = $('#main').width() - ($('#left').width()+$('#right').width());
$('#middle').css({'width':mid_width});
}
HTML
<div id="main">
<div id="left">Left</div>
<div id="middle">Middle</div>
<div id="right">Right</div>
</div>
CSS
html, body{
margin:0;
padding:0;
}
#main {
float:left;
width:100%;
margin:0;
padding:0;
}
#left {
float:left;
width:100px;
height:300px;
margin:0;
background:red;
}
#middle {
float:left;
width:100%;
height:300px;
margin:0;
background:blue;
}
#right {
float:left;
width:100px;
height:300px;
margin:0;
background:red;
}
You can try this one FIDDLE just html and css, without javascript
<div class="container">
<div class="c1"></div>
<div class="c2"></div>
<div class="c3"></div>
</div>
CSS
div {
height:500px;
position:absolute;
border:0px;
padding:0px;
margin:0px;
}
.c1, .c3 {
width: 200px;
background-color:red;
}
.c1, {
left:0px;
}
.c3 {
right:0px;
}
.c2 {
margin-left:10px;
margin-right:10px;
background-color:blue;
left:200px;
right:200px;
}
.container {
width:99%;
}
[updated]
use a table, it will adjust it's own width. float style was the first that came to my mind but it doesn't adjust the element's width to fill in the gap.
html:
<table>
<tr>
<td style="width:10%;"><div id="d1"></div></td>
<td><div id="d2"></div></td>
<td style="width:10%;"><div id="d3"></div></td>
</tr>
</table>
css:
#d1,#d3{
background-color:red;
width:100%;
height:300px;
}
#d2{
background-color:blue;
width:100%;
height:300px;
}
table{
width:100%;
height:100%;
}
DEMO
update:
if you don't want to use tables or excessive js calculations use this:
#d1,#d3{
float:left;
background-color:red;
width:10%;
height:300px;
}
#d2{
float:left;
background-color:blue;
width:80%;
height:300px;
}
DEMO
I would personally avoid using JS and do this using CSS.
You can add a #container wrapper and then define the width to whatever you want and then use % for the left right and the middle div's
Sample CSS below:
<div id="container">
<div id="left-column"> </div>
<div id="middle-column"> <p>Content goes in here and dynamically stretches</p></div>
<div id="right-column"> </div>
</div>
#container{
float:left;
width:1000px;
*background-color:blue;
}
#left-column, #middle-column, #right-column{
height:500px;
float:left;
}
#left-column, #right-column {
width:20%;
background-color:red;
}
#middle-column {
background-color:green;
width:60%;
}
I'm late to the party, still here goes.
This can be done using flexbox.
HTML
<div class="flex">
<div class="fixed-div"></div>
<div class="dynamic-div"></div>
<div class="fixed-div"></div>
</div>
CSS
.flex {
display:flex;
}
.fixed-div {
width:30px;
background-color:blue;
height:200px;
}
.dynamic-div {
width:100%;
background-color:red;
height:200px;
margin: 0px 10px;
}
You can checkout the implementation here.

position fixed element always inside the div

I need to be able to position fixed element always inside the div.
Problem is occuring when I resize the window. Then the fixed div is always floating above all other elements. How to prevent that? I need that div to be fixed but positioned inside the div .
Here is an example:
<div id="main">
<div id="one" style="background-color:yellow;"></div>
<div id="two" style="background-color:black;"></div>
<div id="three" style="background-color:yellow;">
<div id="four"></div>
</div>
</div>
CSS:
#main
{
position:relative;
width:1200px;
top:0;
bottom:0;
left:100px;
}
#one,#two,#three
{
position:relative;
width:100px;
height:1000px;
float:left;
top:0;
bottom:0;
}
#four
{
position:fixed;
top:50px;
background-color:blue;
width:100px;
height:200px;
}
EXAMPLE try moving horizontal scroll left and right and you will see what is happening.
Change position to relative.
Example
#four {
background-color: blue;
height: 200px;
position: relative;
top: 50px;
width: 100px;
}
Check out this answer on a similar question. The problem you're facing is something that can't be solved with CSS alone, unfortunately.

How do I make a div's height remain 100% to the "main" container?

<div id="main">
<div id="left">
news feed goes here
</div>
<div id="right">
another news feed ges here
</div>
<div style="clear:both;"></div>
</div>
Suppose I have a container "main", and I have 2 columns. Both columns are float:left;.
When people click "load more" on the left news feed column, of course it will expand the height of that column because we load more content. But I want the right column to also expand with it. In other words, I want the "right" column to be 100% height of main, always.
How can I do that? Do I se the "right" column's height to be 100%? or what?
duplicate or not.. here's a fiddle to give you an idea how you could do this
http://jsfiddle.net/pixelass/uAur5/
HTML
<span class="more">load more</span>
<div class="main">
<div class="left">this is a left box</div>
<div class="full">this is the right box</div>
</div>
CSS
.left {
background:#666;
margin:10px;
width:130px;
height:80px;
float:left;
padding:10px;
}
.full {
width:130px;
background:#eee;
float:right;
height:80px;
padding:10px;
margin:10px;
}
.main {
width:500px;
background:#000;
height:140px;
margin:20px 10px;
}
.more{
border:#000 1px solid;
padding:3px;
background:#222;
color:#aaa;
margin:20px;
cursor:pointer;
}
jQuery
$('.more').click(function(){
$('.main').append('<div class="left">this is a left box</div>');
$('.full').css('height', '+=120px');
$('.main').css('height', '+=120px');
});
If you mean you want to change height of div, then;
document.getElementById("yourRightDivsId").style.height = yourNewHeight;

Categories