I'm looking to build a gantt chart with the days, months and years across the top and the tasks below them.
Here is what I have so far:
So in the image above, the scroll-x is working on everything including the blue, red and yellow divs and the grey div below them. This is to ensure that as you scroll across, the days stay with the contents of the grey div. scroll-y is only acting on the grey div with the blue campaign name div in it.
Here is the problem:
The problem is that when you move the scroll-x of parent, the scroll-y moves across the screen (so that it is sitting in the middle of the parent div). What I'm looking to do is have the scroll-x work on all of the parent's content and the scroll-y only work on the grey div but for the scroll bar to stay on the far right of the parent.
Any advice would be really appreciated and thanks in advance.
css:
.container {
position: relative;
}
.parent {
overflow-x: scroll;
overflow-y: hidden;
height: 100%;
width: 100%;
position: absolute;
}
.date {
width: 2000px;
height: 25px;
float: left;
}
.hold_content {
overflow-y: scroll;
overflow-x: hidden;
height: calc(100% - 50px)
}
.content {
height: 2000px;
width: 2000px;
float:left;
}
html
<div class="container">
<div class="parent">
<div class="date"></div>
<div class="date"></div>
<div class="date"></div>
<div class="hold_content">
<div class="content"></div>
</div>
</div>
</div>
So, the scrollbar is relative to whatever it's scrolling, which, here, is the hold-content div. And, unfortunately, when that's set to its full width of 2000px, that means the scroll-y scrollbar is not visible because it's offscreen, like so:
html {
box-sizing: border-box;
font-family: sans-serif;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
html,
body,
.container,
.parent {
height: 100vh;
}
html,
body,
div {
margin: 0;
padding: 0;
}
.container {
position: relative;
}
.parent {
overflow-y: hidden;
}
.date {
height: 25px;
width: 2000px;
}
.date:nth-of-type(1) {
background: blue;
}
.date:nth-of-type(2) {
background: red;
}
.date:nth-of-type(3) {
background: yellow;
}
.hold_content {
background: silver;
height: calc(100vh - 75px);
overflow: scroll;
width: 2000px;
}
.content {
height: 2000px;
text-align: center;
width: 2000px;
}
<div class="container">
<div class="parent">
<div class="date">Year</div>
<div class="date">Month</div>
<div class="date">Date</div>
<div class="hold_content">
<div class="content">
<button>Campaign Name</button>
</div>
</div>
</div>
</div>
Not sure if that's ideal or what you were going for. If you want the scrollbar to always be connected to the window (as it is by default), you're probably better off not scrolling these individual divs and instead using position:fixed on your date divs.
Note that this solution uses both viewport units (http://caniuse.com/#feat=viewport-units) and calc (http://caniuse.com/#feat=calc). Also, my code doesn't perfectly mirror your CSS because the code you provided didn't match up with your screenshots.
Related
I want horizontal overflow and when the screen width is not that wide the DIV starts scrolling right - left, but I want it to look not that ugly I have it right now (scrollbars in the bottom of the div).
.wrapper {
position: relative;
overflow-x: scroll;
overflow-y: hidden;
}
.content {
margin: 0 auto;
width: 1198px;
}
HTML
<div class=wrapper>
<div class=content">
My content here..
</div>
</div>
And the other question - is there setting for CSS what allows "swipe" for the div instead of "drag and move".. ?
For a pure CSS solution with browser support you could use the combination of ::-webkit-scrollbar and some padding like this:
.wrapper {
width: 100%;
height: 400px;
position: relative;
overflow: hidden;
}
.content {
width: 100%;
height: 100%;
overflow: auto;
padding-right: 17px; /* This hides the right scrollbar */
padding-bottom: 17px; /* This hides the bottom scrollbar */
}
.content::-webkit-scrollbar {
display: none;
}
<div class="wrapper">
<div class="content">
<img src="https://via.placeholder.com/1500x700" />
</div>
</div>
Better to play around with in JSFiddle: https://jsfiddle.net/thepio/pavb2hfy/
I've been breaking my head the past two days figuring this out. Basically, i am creating a one page layout, where the first block takes the width and height of the screen and the second block needs to be relative.
Example: http://www.shegy.nazwa.pl/themeforest/exit/normal/
<body>
<div id = "block1">
This is block 1 taking 100% width and height of screen.
</div>
<div id="block2">
Block 2 is relative to block 1
</div>
</body>
The trick is to add height: 100%; and margin: 0; to the body/html. Then it works wonders :).
HTML:
<div id="box1">HELLO HELLO THIS IS RED BOX, ARE YOU HEARING ME BLUE?</div>
<div id="box2">YES, RED, I'VE GOT YOU LOUD AND CLEAR. OVER. <div>
CSS:
html, body {
height: 100%;
margin: 0;
}
#box1 {
min-height: 100%;
min-width: 100%;
color: white;
background-color: red;
}
#box2 {
min-height: 100%;
min-width: 100%;
color: white;
background-color: blue;
}
FIDDLE:
http://jsfiddle.net/ewzLM/1/
I would like to put footer on the bottom of the page (or bottom of the screen, if page is shorter than a screen). I am using code:
<div id="wrapper">
<div id="header-wrapper">
...
</div> <!--header-wrapper-->
<div class="clear"></div>
<div id="body-wrapper">
<div class="row960">
<div class="menu">...</div>
<div class="content">...</div>
</div> <!--row960-->
</div> <!--body-wrapper-->
<div class="clear"></div>
<div id="footer-wrapper" class="gray">
</div> <!--footer-wrapper-->
</div> <!--wrapper-->
and css:
.clear{
clear:both;
display:block;
overflow:hidden;
visibility:hidden;
width:0;
height:24px;
margin:0px
}
html, body{
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
body{
background-color: #000000;
color: #FFFFFF;
font-size: 14px;
}
#wrapper{
min-height: 100%;
position: relative;
}
#header-wrapper{
height: 100px;
}
#body-wrapper{
padding-bottom: 50px;
}
#footer-wrapper{
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
}
.row960{
width: 960px;
margin: auto;
overflow: auto;
}
#menu{
width: 200px;
float: left;
}
.content{
width: 740px;
margin-left: 20px;
float: right;
}
The problem is that footer is on the bottom of the screen even if the page is longer than a screen (it covers a text). I've checked it with Firebug and body-wrapper has right height, but row960 has height of screen instead of height of page. I can't figure out how to fix it. Does any one have idea what to do?
You can see my page on http://www.domenblenkus.com/fiap/notice.php
Thanks for your help!
EDIT: I don't know if I emphasized it enough, so I would like to point it out that the main problem is that height of row960 is not right.
Hmmm, I think I have a solution that fits the requirements you stated. There are certainly other ways to do this though, so you can keep looking around if you don't agree with this method. (Also, when I looked on your site it appeared that your #wrappper element was a sibling of #footer-wrapper, and not a parent.)
So, the HTML would look like (structure copied from your site):
<div id="wrappper">
<div id="header-wrapper" class="gray">
<div class="clear"></div>
<div id="body-wrapper"></div>
<div class="clear"></div>
<div class="spacer"></div>
</div>
<div id="footer-wrapper" class="gray"></div>
Note the addition of the .spacer element at the bottom of #wrappper, it's required for this approach of the "sticky footer".
Now, CSS you'll need to add (add to any current definitions if you already have them):
body, html{
height: 100%;
}
#wrappper{
min-height: 100%;
margin-bottom: -50px;
height: auto;
}
.spacer{
height: 50px;
}
If you're wondering why I chose 50px for the height, it's because that's the height of your footer element, #footer-wrapper.
Anyways, I only really tested this in the Firebug console, so I'm not sure how it will behave in a live environment, but I'm fairly certain this will give you what you want. If this isn't what you were looking for, let me know and I'll be happy to help further!
If you want it at the bottom, then you don't need the position:absolute or bottom:0, it will be at the bottom of your div anyway.
You can try doing it using margin. Here is a fiddle of what I'm taking about: http://jsfiddle.net/8WLyP/
Basically for your HTML, place all your content inside a "container" element and then your footer will be a sibling of that element.
Then in your CSS what you will need is to give them html and body elements a min-height: 100%
You "container" element will also have min-height: 100%
You will then need to give your footer a heightof X, in my example it's 50 pixels.
The "container" element will need to have margin-bottom: -50px or whatever value you give the height of the footer.
With all that done, make sure you don't give "container" and "footer" any other margins or paddings than the ones shown, if you need to give them, then you will need to give it to the child elements, in my example p element.
With this technique, as opposed to position: fixed the footer will stick to the bottom of the window if the content is too short, and it will move with the content when the content is bigger than the window/viewport.
HTML:
<div id="container">
<header>
<p>Header</p>
</header>
<section>
<p>Section</p>
</section>
</div>
<footer>
<p>Footer</p>
</footer>
CSS:
html, body, header, footer, section, p, div {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
p {
padding: 5px 10px;
}
header {
width: 100%;
background: #f00;
color: #fff;
}
section {
width: 100%;
height: 200px;
background :#0f0;
color: #fff;
}
#container {
width: 100%;
min-height: 100%;
margin-bottom: -50px;
}
footer {
width: 100%;
background :#00f;
color: #fff;
height: 50px;
}
You want to place the footer at the bottom of the content. BUT: You want to have it at the bottom of the viewport (window) if the content above it is shorter.
So, try this:
the CSS:
#footer-wrapper {
position: relative;
width: 100%;
height: 50px;
}
#body-wrapper {
position: relative;
height: 100%;
}
… and the JavaScript (jQuery):
var bodyWrap = $('#body-wrapper'),
footerWrap = $('#footer-wrapper'),
windowHeight = $(window).height();
var heightRemaining = parseInt(windowHeight - bodyWrap.outherHeight() - footerWrap.outerHeight());
if (heightRemaining > 0) bodyWrap.css('min-height', heightRemaining);
Didn't test it due to little time.
Give it a try.
The problem I'm trying to solve is quite simple, yet I find hard to achieve what I want using my CSS techniques.
What I want is to have some sort of parent div with height set to relative value (like: 100% or 30%). Please do not ask why do I need it, as this is simply a partial and explaining whole layout goes beyond this question.
Inside this parent, I need to have a header h1 followed by child div containing lots of text. And the most important, I need to have scrollbars only inside child div, so that the header will always stay attached to the top of container.
Markup:
<div class="wrapper">
<h1>Test</h1>
<div class="text">
Lorem ipsum (... lots of text)
</div>
</div>
(NOT)Working fiddle:
http://jsfiddle.net/CodeConstructors/BEVSS/
Is this something you want to achieve?
HTML
<div class="wrapper">
<div class="header">
HEADER
</div>
<div class="content">
Lorem ipsum (... lots of text)
</div>
</div>
CSS
html, body {
height: 100%;
margin: 0px;
padding: 0px;
}
.wrapper {
width: 400px;
height: 100%;
background-color: #fec;
margin: auto;
position: relative;
}
.header {
height: 40px;
background-color: green;
color: #fff;
}
.content {
position:absolute;
bottom:0px;
top: 40px;
width:100%;
overflow: auto;
background-color: #333;
color: #666;
}
You can use CSS3 properties calc(),like this:
html, body { height: 100% }
.wrapper {
height: 30%;
overflow: hidden;
width: 400px;
background-color: yellow;
}
h1 {height: 20px}
.text {
overflow: auto;
height:-webkit-calc(100% - 20px);
height: -moz-cale(100% - 20px);
height: -ms-cale(100% - 20px);
height: -o-cale(100% - 20px);
height: cale(100% - 20px);
}
you need define the heading's height.
The DEMO.If you want to know the calc () method of use, you can click here.
I'm trying to make a simple DIV layout compatible with IE, and it's giving me hell.
Here's the basic layout I'm working for:
<div id="body" style="background: blue;">
<div id="header">
HEADER
</div>
<div id="content" style="height: 88%;">
CONTENT HERE
</div>
<div id="footer">
FOOTER
</div>
</div>
I'm using CSS rounded corners on the Body div, and I have a navbar and footer info in #footer as well as a tabbed main navbar in #header.
My main problem has been making the #content div stretch vertically to fit the full page when I only have a small amount of content WITHOUT creating vertical scrollbars.
If I make #content height: 100%; the header and footer cause the page's height to go above 100% and triggers scrollbars.
Making #content's height 88% does the trick in FireFox, but there are two problems with this solution:
a) It's an ugly hack
b) It doesn't work in IE (of course).
Anyone have ideas on how to accomplish this? I assume is should be a fairly common situation for web designers out there.
There you go, try this template, it's really simple and i think it would solve your problem.
HTML:
<div id="wrapper">
<div id="header">
<div id="header_900">
<p>header</p>
</div><!--header_900-->
</div>
<div id="content">
<div id="content_900">
<p>content</p>
</div> </div>
</div><!--wrapper-->
<div id="footer">
<div id="footer_900">
<p>footer</p>
</div> </div>
CSS
body, html{
height: 100%;
}
body, p {
margin: 0; padding: 0;
}
#wrapper {
min-height: 100%;
}
* html #wrapper {
height: 100%;
}
/*HEADER------------------------------------*/
#header {
width: 100%;
background: #666;
}
#header_900 {
width: 960px;
height: 100px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
/*FOOTER------------------------------------*/
#footer {
width: 100%;
height: 100px;
margin: -100px auto 0 auto; /*THIS SHOULD BE EQUAL TO THE FOOTERS HEIGHT*/
position: relative;
background: #666;
}
#footer_900 {
width: 960px;
height: 100px;/*THIS IS THE FOOTERS HEIGHT*/
position: relative;
margin: 0 auto;
}
/*CONTENT------------------------------------*/
#content {
width: 100%;
padding-bottom: 100px; /*THIS SHOULD BE EQUAL TO THE FOOTERS HEIGHT*/
}
#content_900 {
width: 960px;
margin: 0 auto;
overflow: hidden;
}
I don't think there is an official way to accomplish this unless you use quirks mode. If you use quirks mode (no doctype), it would look something like this:
html, body {
margin: 0;
padding: 0;
height: 100%:
}
#content {
height: 100%:
}
Maybe what you're looking for is an adapted version of something like this: http://www.alistapart.com/comments/fauxcolumns