Dividing HTML page into horizontal sections, without vertical scrollbars - html

I'm trying to create something like this:
http://jsfiddle.net/S6FUQ/
HTML is:
<div id="container">
<header></header>
<main>
<section class="half"></section>
<section class="half"></section>
</main>
</div>
And CSS is:
* {
margin: 0; padding: 0;
}
html, body, #container {
height: 100%;
}
header {
height: 50px;
background: gray;
}
main {
height: 100%;
background: green;
}
.half {
height: 50%;
}
.half:first-child {
background: blue;
}
.half:last-child {
background: yellow;
}
In it, I have a thin ribbon at the top, and I want to divide the rest of the screen into two equal sections, but I don't want vertical scrollbar to appear.
I tried margin-bottom: 50px; for main, but it didn't work. What should I do?

Height of "main" should be 100% - 50px. Here is the fiddle.
main{height: calc(100% - 50px);}

To make it work on old browsers, you could use absolute positioning.
Demo
#container {
position: relative;
}
main {
position: absolute;
width: 100%;
top: 50px;
bottom: 0;
background: green;
}

You are already using % to set height... Why don't you use it again to solve your problem?
header {
height: 10%;
background: gray;
max-height:50px; //this will ensure your header will never go bigger than 50px
}
main {
height: 90%;
background: green;
}
PS: The only time your header is going to be smaller than 50px is when the browser is smaller than 500px (which will be only in some landscape mobile devices)
EXAMPLE

Related

Alignment of iframe

Using this question as a starting point I've changed things a little to match my purpose. Unfortunately I don't seem to be able to save this in jsfiddle as after saving the result always is "404 That page doesn't exist."
So here's the original code:
http://jsfiddle.net/JP3zW/
/* In a Reset CSS */
body, div {
margin: 0;
padding: 0;
}
/* Style CSS */
html, body { height: 100%; }
body {
position: relative;
background: #F4F4F4;
}
iframe#iframe {
width: calc(100% - 200px);
height: calc(100% - 100px);
overflow: hidden;
}
div#sidebar {
top: 0;
right: 0;
position: fixed !important;
height: 100%;
width: 200px;
background: gray;
}
div#bottombar {
bottom: 0;
height: 100px;
width: 100%;
background: black;
z-index: -1;
}
<iframe id="iframe" name="iframe1" frameborder="0" height="100%" width="100%" src="http://someurl.com"></iframe>
<div id="bars">
<div id="bottombar"></div>
<div id="sidebar"></div>
</div>
The result is, that the iframe somehow is displayed centered. However I'd like to have it aligned with the top left corner so that the left part of the embedded contents is visible.
I've tried align="left" and other in the HTML iframe definition but to no avail.
What do I need to do to have the contents of the iframe aligned top left?
As I see it, your iframe displays correct, but the sidebar is just overlapping the iframe because of the position: fixed.
I have changed a bit in the CSS, and used percentage instead of pixels, for it to be responsive.
Let me know if it works for you.
/* In a Reset CSS */
body,
div {
margin: 0;
padding: 0;
}
/* Style CSS */
html,
body {
height: 100%;
}
body {
position: relative;
background: #F4F4F4;
}
iframe#id_iframe {
width: 70%;
float:right;
height: 100%;
overflow: hidden;
}
div#id_sidebar {
float:left;
height: 100%;
width: 30%;
background: lightgray;
}

Content Scrolling / Overflowing Horizontally

i am Currently working on a Angular 2 Website.
I wanted to have a Landing section which covers the Full screen, a content Section, which is as large as the Content inside and a Footer at the Bottom as well as a navbar that stays always on top.
I'm more of a Backend-Developer, so CSS is not my biggest Strength.
My Current code for Testing is:
Global CSS:
html, body {
margin: 0px;
padding: 0px;
width: 100vw;
height: 100vh;
}
App-Component HTML and CSS:
<app-home></app-home>
<header>
Test
</header>
.
header {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 50px;
color: white;
background-color: rgba(0, 0, 0, 0.8);
}
And my Home-Component HTML / CSS:
<header></header>
<div class="content"></div>
<footer></footer>
.
header {
position: relative;
width: 100%;
height: 100%;
background: blue;
}
.content {
position: relative;
width: 100%;
height: 500px;
background: red;
}
footer {
position: relative;
width: 100%;
height: 50px;
background-color: yellow;
}
The Problem i Currently have is, that all my Containers are about 10px wider that the screen. Because of this there is a Horizontal Scrollbar at the bottom.
The weird thing is that this Problem only occurs when i add the content or footer section. When i only have the header Everything is fine.
Also the Navbar stays in the correct size.
Image of the Problem
Probalby it's just a stupid small mistake, but even with other solutions from Stack Overflow i tried it is still not working.
I appreciate all your Help!
just change width to 100% from width: 100vw for body; Like below:
html, body {
margin: 0px;
padding: 0px;
width: 100%;
height: 100vh;
}

How to set an html element's height as { 100% - 10em from bottom }

Let's consider one element #top. I want it's height to be 100% of the page, but diminished by 10em from the bottom. I'm unable to figure out how to do it. Please help.
HTML
<div id="top"></div>
<div id="bottom"></div>
CSS
html, body {
height: 100%;
padding: 0;
margin: 0;
font-size: 100%;
}
#top {
width: 100%;
height: 70%;
background-color: red;
}
#bottom {
position: absolute;
bottom: 0;
margin-left: 10%;
width: 100%;
height: 10em;
background-color: #000000;
}
See http://codepen.io/anon/pen/jEqYMK (for illustration, i have shown one more element, #bottom).
Your demo is lil weird but anyways, if you want to deduct 10em from 100% then use calc() property like
#top {
width: 100%; /* You won't need this */
height: calc(100% - 10em);
background-color: red;
}
Demo
Note : I've removed position: absolute;, margin-left like properties from your demo because I have no idea why you were using them at first place but if you want you can still use them.

100% height center section using CSS only

Here is the JS fiddle I made: http://jsfiddle.net/K6CFU/
The structure is the exact same I'm using for my website but the problem is that I'm not getting the middle section of my site to be 100% high. Right now it's the content that determines how tall it is.
<body>
<div id="page-container">
<header></header>
<div id="page-wrapper">
<div id="page-content">
</div>
</div>
<footer></footer>
</div>
</body>
html, body { height: 100%; padding: 0; margin: 0; }
header { width: 100%; height: 50px; background-color: red; }
footer { width: 100%; height: 50px; position: absolute; bottom: 0; background-color: green; }
#page-wrapper { width: 1024px; margin: 0px auto; background-color: yellow; }
#page-content { height: 100%; background-color: pink; }
Not 100% sure I know what you mean but have you tried adding height:100% to the page-wrapper div?
#page-wrapper{
height:100%;
width: 1024px;
margin: 0px auto;
background-color: yellow;
}
I've ran into this problem in the past. The way that I see it is that when you specify height: 100%;, it fills to 100% of the div (or whatever element) - but not to the screen size. I've always had to use min-height somewhere to get similar results that you're seeking.
For the body or probably for your page-wrapper div, try specifying min-height: 500px; (or whatever you feel is an appropriate size.
Make the page-container
height: 100%;
so that the object inside know the size of the box.
than you can make the page-wrapper
position: absolute;
bottom: 50px;
top: 50px;
height: auto; /*can also be left away*/
now the middle part will be between the footer and the header
http://jsfiddle.net/K6CFU/5/
you can make the page-content
height: 100%;
or you can leave it away, like you want.

HTML5 Layout Issues

I've been working on a layout for some time. I decided to whip up an example in jsFiddle.
http://jsfiddle.net/PSYgU/1/
The issues I'm running into is that the ASIDE doesn't expand to the full height of it's parent "wrapper", only to the height of the view port. The ASIDE, also needs to be able to be moved to the right or left.
I'm open to other methods of creating this layout, without tables.
/* PHP option to control the width of all content by wrapper via style */
/* PHP option to control which side to float the sidebar to via style */
<div id="wrapper" style="width:100%;">
<aside style="float: right;">This Sidebar</aside>
<header>The Header</header>
<section>The Main Content Area</section>
<footer>The Footer</footer>
</div>
html, body {
min-height: 100%;
height: 100%;
}
#wrapper {
margin: 0;
padding: 0;
background: brown;
height: 100%;
}
aside {
width: 200px;
background: yellow;
height: 100%;
}
header {
height: 150px;
background: blue;
width: 100%;
}
section {
background: red;
width: 100%;
height: 100%;
}
footer {
height: 50px;
background: green;
width: 100%;
}
Because you have section also on height 100% and also lays within the wrapper it wil take the complete height of the wrapper just like sidebar.
example:
when body/html and wrapper have a height of 200px anything within the element wrapper that has height on 100% will have a height of 200px if you add a header within wrapper with height 150px you need to add this to the 200 from before.
this wil result that the height of sidebar never reach the bottom of the wrapper because its missing the height of the header.
a solution to this is to make the header and section together 100% height like header 15% and section 85%.
this will mean that both of them scale but that the sidebar will always be the same height.
<div id="wrapper">
<aside style="float: right;">This Sidebar</aside>
<header>The Header</header>
<section>The Main Content Area</section>
</div>
<footer>The Footer</footer>
html, body {
min-height: 100%;
height: 100%;
}
#wrapper {
margin: 0;
padding: 0;
background: brown;
height: 100%;
width:100%
}
aside {
width: 200px;
background: yellow;
height: 100%;
}
header {
height: 15%;
background: blue;
width: 100%;
}
section {
background: red;
width: 100%;
height: 85%;
}
footer {
height: 50px;
background: green;
width: 100%;
}