Set height of section in fullpage.js - html

I am using fullPage.js
This may sound very noobish, but can't figure how to set a section to have a height of less than 100%, I have tried setting it in the css using .section and #section1 (eg. height: 80%;), but this has no effect...
Many thanks.
Max

The same question was answered in the plugin's github issues forum.
This is a FULL PAGE plugin.
There's no such option
It is not an option the plugin offers.
If you want to do it, you would need to do it by yourself. Probably by overwriting the height property of the sections and slides after the plugin is rendered (on the afterRender callback) and after it gets resized (afterResize).
You can try it with by adding CSS styles as well, by adding things like:
#section1,
#section1 .fp-slide,
#section1 .fp-tableCell{
height: auto !important;
}
UPDATE
Now fullpage.js provides a way to create smaller sections than the viewport (or even bigger ones when using autoScrolling:false or scrollBar:true.
Adding the class fp-auto-height on each section will do it as stated in the documentation.
UPDATE 2
fp-auto-height won't allow you to use percentages, but there's an extension that gives you that possibility. Offset Sections.
It also allows you to show the section in the middle of the view-port showing parts of both the previous and the next one.

This is what I came up with I changed
$(window).height();
to
var windowsHeight = $('.universal-container').height();
so lets say we have 4 divs
<div class="main-container">
<div class= "1st-div-holder">
</div>
<div class= "2nd-div-holder">
<div class= "section">
<div class= "universal-container">
</div>
</div>
</div>
</div>
now on our css we can do something like this
.main-comtainer{
width:100%;
height:100%;
}
.1st-div-holder{
height:10%;
width:100%;
position:fixed;
}
.2nd-div-holder{
height: 90%;
position: absolute;
bottom: 0;
}
this way the height is automatically picked up without taking up the whole window.

Related

How is it possible to make a horizontal bar (fixed position, always at the top of screen) while its height is unknown?

I want a horizontal bar at the top of HTML page. It should always be at the top of the screen, So I made this:
<body>
<div id="message_bar" style="position: fixed; top: 0px; width: 100%; z-index: 1000;">
</div>
<div class="other_divs" style="width: 100%; float: left;">
</div>
</body>
Now, this bar should not cover the rest of the body. If I knew the height of it, let's be 50px for example, I would do it by:
<body style="padding-top: 50px;">
But unfortunately, the height of this message_bar is variable and unknown (It's contents are set dynamically at server-side).
Is there any way to solve this problem purely by CSS?
Thank you very much.
P.S.
This message_bar would display like menu bars in windows applications: they are always at the top, and they never cover the main body. In fact, vertical scroll bar starts from "other_divs".
UPDATE 2:
Hey, Unbelievable! I guess I've managed to create the potential layout for a horizontal menu bar, purely with CSS. Here is my solution thanks to the power of vh:
<body>
<div style="display:block; width:100%; height:95vh !important; overflow:hidden;">
<div id="message_bar" style="float:left; width:100%; display:block;" >
this text appears always on top
</div>
<div style="float:left; width:100%; height:100%; display:block; overflow:auto;">
<div id="main_content" style="background:blue;">
Here lies the main content of the page.
<br />The below line is a set of 40 list items added to occupy space
<ol><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li><li>i</li></ol>
</div>
</div>
</div>
</body>
I checked it in Chrome,IE, and FireFox, and it worked neatly!
Anyway, I must thank the community here; Even when no answer is provided, the discussion and different viewpoints stimulate thinking process and eases solution finding.
The only way to solve this with purely CSS is adding a duplicate of the bar at the top of the page with position: relative and a lower z-index. This duplicate bar would always be hidden behind the fixed one (you could use opacity: 0; pointer-events: none if needed) and would push the rest of the page down. However this solution is very ugly as it adds a lot of HTML.
I recommend using JavaScript with jQuery for a pretty easy solution.
$(document).ready(function() {
$('.wrapper').css('padding-top', $('.message_bar').outerHeight());
});
And create a wrapper div around the content of the page (<div class="wrapper">Content...</div>). Alternatively, you could apply the padding to the body.
I am interested in your question, thanks for your information of the value of vh and vw. When I read your UPDATE 2. I found there is still something can be improved. The following is:
I change overflow:scroll; to overflow:auto. Because when your page haven't enough height. The value overflow:scroll will create a gray scroll bar. That is unfriendly for user.
I remove the most outer layer <div style="display:block; width:100%; height:95vh !important; overflow:hidden;">...</div> and retain the others. In other word, not to use vh also can be resolved your question.
There is my JSFIDDLE. (NOTICE: the JSFIDDLE is not achieve the effect that the above following. Copy these code on your native browser. I think this reason is about virtual circumstance compatibility. It worked in chorme & Firefox & IE 10)
You can have a class where are no scrollbars and then the position property will be position:absolute;
but if you want to keep this topHeader fixed in case of scrolling you have to use .fixed class
.topHeader {
background:#345;
color:#FFF;
height:50px;
padding:.5em;
position:absolute;
top:50px;
width:100%;
}
.fixed {
position:fixed;
top:0;
}
...and you some javascipt to bind scrol event:
var pixels= 50; //in pixels
$(window).bind('scroll', function () {
if ($(window).scrollTop() > pixels) {
$('.topHeader ').addClass('fixed');
} else {
$('.topHeader ').removeClass('fixed');
}
});
Why don't you just use relative positions? Remove position: fixed;. That's how it looks like:
http://jsfiddle.net/darekkay/8ab6uw7n/1/
Edit: I don't think, you can achieve this with pure CSS, if you don't know the height of the message. But you can use jQuery:
$("#message_bar").show(function() {
$( ".other_divs" ).css("margin-top", $(this).height() + "px");
});
http://jsfiddle.net/darekkay/8ab6uw7n/2/

How can I make my web page look good in browser windows of different sizes?

I've got a question about optimizing webpages... hmm, let me start over from the beginning.
HTML Code:
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css">
<title></title>
</head>
<body>
<div id="header"> Text... </div>
<div id="body"> </div>
</body>
</html>
CSS Code:
#header
{
background-color: green;
width: 50%;
height: 25%;
left: 25%;
position: absolute;
}
#body
{
background-color: red;
width: 50%;
height: 55%;
left: 25%;
top: 25%;
position: absolute;
}
The problem is that whenever I minimize the window a bit, my divs shrinks together. That's not how I want it to appear. After figuring out a while how to solve this problem I came up with this "great" idea to make a div wrap that cover all the other divs.
So then my divs need a wrap right?
<div id="wrap">
<div id="header"> </div>
<div id="body"> </div>
</div>
#wrap {
width: 600px;
height: 800px;
position: absolute;
}
Now in my css code I need to set the px of height and width of the wrap div, right? Now this will work but the problem is. How do I get to optimize this then on another computer screen? I mean this wouldn't work on all the users right?
Anyway.. Let me repeat the question once again...
How do I my webpages to optimize to minimizing windows in the browsers and to work on all screens? I mean everything has to relate to pixels right? Now how the ** is that suppose to work If all the screen has different size's? I mean then you need to use the % to make it work. I don't want you guys to mainly sort of this exactly problem but give me some advice how to generally optimize a webpage in the best way.
Ok here is what I usally do:
Whenever I want to create a website that doesn't fill 100% of the page I create a wrapper around ALL the content, like you did. You can either do this with fixed values or with % values. In case you want to use % values it's often smart to use min-width or max-width for your wrapper. This way you only need to define fixed values once and all the inner content can be defined by using %. This helps especially if you want to resize the whole content later on, if your realize that it might look better with a little bit more width.
Height values rarely use % values, only use % values for the height if you are using a fixed height for your container. If you want to create different layouts for different screen resolutions you can always have a look at the #media tag which allows you to create resolution specific css code. This however is only recommended for a small set of resolutions, let's say, 2 different resolutions for desktop computer and maybe 2 different resolutions for mobile phones (4 different css definitions).
I usually try to use min-width and max-width with % values, and if that isn't possible for example for popup windows or fixed elements like a sidebar I use px values. And if I for example want to support multiple columns for my content if the user has larger screens I make use of #media
I also don't get why you're using absolute positioning. If you just want to center content use margin: 0 auto; on your container. Btw in html5 you can also use the <header> tag if you want to specify a header. Using a div and giving it a class/id isn't wrong but I think you should know that there is some new stuff out there in the world of html5/css3
EIDT:
Your title is a little bit confusing, since your question is totally different. For website optimization I strongly recommend http://developer.yahoo.com/performance/rules.html or for advanced optimization you can use https://developers.google.com/closure/ and https://code.google.com/p/closure-stylesheets/
Four your above code:
you can use:
#wrap {
margin:0 auto;
width: 600px;
height: 800px;
position: absolute;
}
instead of
#wrap {
width: 600px;
height: 800px;
position: absolute;
}
And to make make your webpage look same when window is re-size or you have to learn abut Responsive Web Development. Start using media queries in you pages.
For responsive design use media queries: Here is good example of media queries . Also learn how to use it.

Setting up a container to be of an exact width with twitter bootstrap

I have a header image for a layout that I'm working on that is 1200px wide. The layout is fixed.
I'd like the container that wraps this image (and any container that wraps it up in the DOM hierarchy) to adapt to the 1200px. First thing I thought on doing was to just:
.container {
width:1200px;
}
It works, but then what's the point of using bootstrap? And also, I'd probably be messing with the grid by forcing a width this way, right?
So, I tried to setup the grid to add up to 1200px, but still keep 12 columns, like this (I'm using sass):
$grid-column-width: 70px;
$grid-gutter-width: 32px;
However, I could only approximate (or go way above) 1200px, while keeping 12 columns. In this case, I got 1192px, which works, but is not optimal.
Here's the markup I'm using:
<div class="container">
<div class="row-fluid">
<div class="header-photo text-center span12"></div>
<div class="row-fluid">
...
</div>
...
</div>
</div>
And here's the SCSS that setups the header div:
div.header-photo {
background-image: url(/images/header-photo.png);
width: 1200px;
height: 368px;
h2,h3 {
text-indent: -99999px;
}
}
So, if I use span12, the other divs adapt to the size of the header-photo div, but only up to 1192px.
What would be the best approach to get the container to be of exactly 1200px?
force it with a CSS rule (like I tried doing) ?
A combo of the grid conf that I'm clueless about?
Tell the designer to make the header photo smaller/bigger so it adapts to another value?
... ?
Any hints highly appreciated!
Thanks in advance!
you should fix the container value by opening the bootsrap gem

CSS & HTML book for print

Okay, so hypothetically, let's say I wanted to write a book using HTML and CSS only. How would I go about defining a page header and footer (and have page numbers in the footer)? And how would I make it so that page breaks and margins show up in the browser (like a preview mode)?
I know it sounds like I'm asking for someone to just write the code for me, but I really just need direction to resources for something like this. I'm just completely stuck on how I would even begin to do something like this.
To explain what I want to show in the browser; I want to be able to see small versions of each page like you would in a PDF viewer, basically the text overflow would create a page-break:
I have looked into #media print, but that doesn't have any hooks for creating headers and footers.
and I can't get this to work (from w3.org):
title { position: running(header) }
#page { #top-center {
content: element(header) }
}
I have looked at the code from Boom!, and It's nice for printing, but it doesn't display in browser the same.
So... does anyone now where I could/should look for a good starting point for this?
This was my solution:
<div id='document'>
<div class='page'>
<div class='header'></div>
<div class='footer'></div>
<div class='content'></div>
</div>
</div>
Everything went in <div id='document'>. For each .page, the .header, .footer, and .content had the right height and width for a page.
After that, I used JavaScript to cut out everything that was overflowing outside the div.content. I then cloned div.page, updated the page number inside of the new page's header <div>, and filled the new page's content <div>.
This was repeated until I had like 100 pages and nothing was sticking out of the last page's content <div>.
I am assuming that you are using pure HTML and there is no code behind.
Because if there is any code behind then its a different story.
Define a main div having class="page". Inside that define 3 divs for header, content and
footer.
.page {
display: block;
height: 800px;
width: 100%;
/*Give margin as per your requirement.*/
}
.header {
display: block;
height: 50px;
}
.content {
display: block:
height: 700px;
}
.footer {
display: block;
height: 50px;
}
Add additional style as per your requirement.
create another style sheet with media type ="print"
There add the following style for page.
.page {
display: block;
height: 800px;
width: 100%;
/*Give margin as per your requirement.*/
/* this will print the page in new paper*/
page-break-after: always;
}
and the HTML for one page will look like this
<div class="page">
<div class="header">HEADER CONTENT</div>
<div class="content"> MAIN PAGE'S CONTENT</div>
<div class="footer"></div>
</div>
Repeat the above code an per the number of page you need.
You can also use table layout for this purpose.
And if you use code behind, then the content can be generated dynamically.
Hope this helps.
Well, it could be done by pure HTML and CSS but definitely not the way to go as it would become very frustrating to repeat blocks of code, almost the same, every time you wanted to start a new page. For the PDF like left panel you could use Iframes, more info here
basically, you would make a .htm page for every page of your book, strictly linked together by links, and when you would be finished, you could take a screenshot of every page you made, save the thumbnails, and make another html page that would be the panel, which would be eventually included (as the tutorial in my link shows) in all the other pages for the book.
UPDATE
Regarding page breaks, you could make div-s with the same class, and styled as pages, as shown here

Simple html/css layout? (two column)

I'm having a very hard time trying to come up with html/css for a layout to suite the following:
Where the left area is a static menu. The right area is dynamic content, generated using a call to ASP.Net's RenderBody method. You may not believe it, but I have been trying to figure this out for hours. I keep getting either the right section ending up underneath the left section taking 100% of the width or not displaying at all, with Chrome's object inspector saying its 0 pixels wide.
I feel like a complete idiot as this seems as if it should be easy as pie. Could I please get some help?
There's several ways to go about this. Here's one not particularly fancy but straight-up way to go about it:
<body>
<div id="menu">MENU</div>
<div id="content"> content <br /> content <br /> content </div>
</body>
CSS:
div { border: 2px solid black; } /* demo purposes */
#menu {
float: left;
width: 150px;
}
#content {
margin-left: 154px; /* menu width + (2 x menu.border-width) */
}
See this jsfiddle for a working sample.
This solution has the added benefit that your content region will take up exactly 100% of the remaining width of its parent:
<div class="parent">
<div class="content">blah...</div>
<div class="left-menu">blah...</div>
</div>
CSS:
.parent { padding-left:200px;width:100%; }
.content { position:relative;float:left;width:100%; }
.left-menu { position:relative;float:left;width:200px;right:200px;margin-left:-100%; }
Excellent tutorial on fluid layouts: http://www.alistapart.com/articles/holygrail
Works in IE7 and newer, Safari/Chrome/Opera/Firefox...
The best way to do this is by using the already considered safe to use box-sizing property.
Take a look at the tinkerbin -> http://tinkerbin.com/AcJjYk0r
It works as you want it to. Fixed width for the menu, percentage based width for the content area.
Then...
...if you want the background-colors to expand to the highest of the heights between the two boxes (remember, one times the menu can be higher than the content box, and vice-versa), then the only way to go about it (no javascript) is to use a background image and place it below the two boxes. With css3 gradients (safe to use too) it's pretty easy. Take a look:
http://tinkerbin.com/3ETH28Oq