How to set scroll height? - html

+-------------+ +---------------------------------+
| | | |
| 1 | | |
| left-nav | | |
| | | |
+-------------+ | 3 |
| | | |
| | | |
| 2 | | very long contents here |
| | | which causes to scroll |
| other | | vertical bar. Setting |
| remaining | | this content to 100% height? |
+-------------+ +---------------------------------+
What is height: 100%; actually? Is it applied to a page window or till the scroll ends?
I have following html...
<div id="wrapper">
<div id="left-nav">
<!--contents of 1-->
</div>
<div id="yourad">
<!--contents of 2--->
</div>
<div id="main-contents">
<!--contents of 3-->
</div>
</div>
My css is as follows....
#wrapper{position: relative; width: 1007px; margin: 0 auto;}
#left-nav{width: 329px; height: 100%; background: grey;float: left;}
#yourad{height: 100%; background: blue;}
#main-contents{margin-left: 329px; padding: 10px; background: pink;}
****Note: ****
First see my demo to understand my problem Here
Contents of 1 actual height: I don't know.
Contents of 2 actual height: I dont't know.
Contents of 3 actual height: I don't know.
Because I may need for some pages less contents and some pages more contents.
I've tried by using height: 100%; in html, body, wrapper, left-nav, yourad, but could not success.

Height 100%, when applied to a child element, will make the element stretch to the full height of its parent.
For instance, if you set your #wrapper {height:600px} and your #content{height:100%} the content div will now have a height of 600px.
The confusion comes in because the default overflow property is: overflow:visible - will not be clipped by contrainsts of containing element. So without explicitly setting an overflow of hidden or scroll, the content will flow outside of the container.
You can see this being demonstrated in your example (http://jsfiddle.net/RrmK3/) by setting a background color on the parent div.
<div id="wrapper" class="wrap">
<div id="left-nav">
<h4>Menu Title</h4>
<ul>
<li>Menu Item</li>
</ul>
<div id="yourad">
You add is in your sidebar. It is not in your question :)
</div>
</div>
<div id="contents">
<h1>Indenting Code Keeps you Sane.</h1>
</div>
</div>
#contents{ margin-left: 330px; margin-top: 5px; height:100%; }
#wrapper{position: relative; width: 1007px; margin: 0 auto; height:200px; background:pink;}

Ok, this is really hard to explain in writing but I'll give it a shot.
When you set your body to 100%, it will always stay at the height that it started at, so it will cut off anything below the visible body.
The problem here is that one of your columns has to be a fixed height so your wrapper can know how to translate percents. Since you wont know what the height of left-nav is, you can cheat and use javascript to set the height of your wrapper to the height of your left-nav and the content text will overflow correctly..
Enough with the words, here's how you do it:
$('#wrapper').height($('#left-nav').height());
http://jsfiddle.net/Y7PhV/106/

Related

element to fill remaining vertical height with scrollbars if needed

What is the most modern solution to the following layout requirement:
two elements are to fit inside a container element, and not extend outside of that container.
each are 100% width of container.
And the sum of their heights added together is the same as the container height(maybe some padding or margins involved).
the header element is to expand vertically to fit its content.
the .fillNscroll element is to fill the remaining vertical space to the bottom of div.info and apply vertical scroll bars if it vertically overflows within that constraint.
can i do this with just CSS3 and HTML5 ? (not worried about compatibility with earlier browsers). If not is there a jQuery plugin ?
+------------------------+
| <section> |
| fixed width & height |
| |
| +------------------+ |
| | <header> | |
| | variable height | |
| | | |
| | | |
| +------------------+ |
| |
| +------------------+ |
| |<div.fillNscroll> | |
| | fill remaining ^ |
| | height | |
| | | |
| | with scrollbars | |
| | on overflow | |
| | | |
| | V |
| +------------------+ |
| |
+------------------------+
HTML5:
<section class="info">
<header>
<h1>Halophryne queenslandiae (and the occasional extra long name that causes the header to flow into multiple lines)</h1>
</header>
<div class="fillNscroll">
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
<p>Variable length content. may overflow the .fillNscroll div eventually</p>
</div>
</section>
CSS (LESS):
// make padding and border inside width and height for everything !
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
div, h1, h2, h3, p, .info {
border: 1px solid red;
}
section.info {
position: absolute;
left: 50px;
width: 200px;
height:300px;
padding: 10px;
header {
}
.fillNscroll{
height: 100%;
}
}
can i do this with just CSS3 and HTML5 ? (not worried about compatibility with earlier browsers)

Why the content is centered when padding-left and margin-left rules are set to zero?

In a Wordpress theme, the posts content is justified to the center of the parent layer. The problem is that I don't know how to justify it to the left. Here is an example of the relevant HTML:
<div id="content" role="main">
<div id="post-329" class="post-329 news type-news status-publish hentry category-house category-techno has-post-thumbnail">
<div class="notice-content">...</div>
</div>
</div>
and this is what I can see with Firebug:
| layer | ====> | calculated property |
| #content | => | margin-left: 121px | & | padding-left: 0 |
| #post-329 | => | margin-left: 0 | & | padding-left: 0 |
| .notice-content | => | margin-left: 0 | & | padding-left: 0 |
and no text-align property. But every post content is centered.
¿What can be doing the posts to be justified to the center and how to avoid it?
Edit:
Finally found out the issue. The hentry class had margin: 0 auto;. This causes the content to be centered. What I still don't understand is why Firebug indicate the margin-left as 0px, when actually it is auto and not zero.

How to stop divs from collapsing on page resize?

HTML:
<div id="wrapper">
<div id="tabs">
</div> <!-- tabs close !-->
<div id="verticalStack">
<div id="accordion">
</div> <!-- accordion close !-->
<div id="usersBox">
</div><!-- usersBox close !-->
<div id="displayProductButtons">
</div> <!-- displayProductButtons close !-->
</div> <!-- verticalStack !-->
</div> <!-- wrapper close !-->
CSS:
body {
margin:0;
padding:0;
font-family: Verdana, Times, serif;
font-size: 12px;
color: #333333;
background-color: #F9F9F9;
min-width: 944px;
}
#wrapper{
margin:10px;
width:90%;
}
#tabs {
float:left;
width:700px;
margin-right: 10px;
}
#verticalStack{
float:left;
width:400px;
height:500px;
}
#accordion{
float:left;
}
#usersBox{
width:100%;
margin-top:10px;
float:left;
border:1px solid #aaa;
border-radius:5px;
}
#display{
margin-top:25px;
float:left;
}
The page looks like this:
------------------------------------
| wrapper |
----- ------------------
| |tabs| |verticalStack | |
----- -------------------
| | |accordion | | |
-------------
| | |usersBox | | |
-------------
| | |display | | |
--------------
| | | |
----------------
|-------------------------------------
When I resize the page the veritcalStack div (along with the inner divs) falls under the tabs div. Can someone please explain to me why this occurs and what I can do about it?
You're floating your elements; they will remain side-by-side as long as the horizontal space is sufficient to provide for it. If you don't want them to collapse, you should put them within a container that has an explicit width; this will create a horizontal scrollbar at some point in your resizing though.
<!-- these images will not collapse -->
<div id="container">
<img src="http://placekitten.com/300/200" />
<img src="http://placekitten.com/200/200" />
</div>
<!-- these images will collapse -->
<img src="http://placekitten.com/300/200" />
<img src="http://placekitten.com/200/200" />
Working Fiddle: http://jsfiddle.net/jonathansampson/EChrr/
My suggestion would be to embrace this; check out Responsive Web Design and find how to use the natural behavior of the browser to your advantage.
Floated elements will stay side by side until there is insufficient space (i.e in your case when the browser window is less than 1110px wide). If this is how the design must be, then you should set a width, or min-width on the #wrapper to 1110px wide.
You could also try setting the widths of the floated elements relative to the other elements (i.e using percentages) so that the design works across smaller resolutions just as well.

HTML+CSS : how to move not close divs to create a right column?

I have a problem that I thought was pretty simple but that is taking me a lot of time to solve it. If there is a simple solution (and I don't know CSS enough), please point me there and I'll close this question immediately.
My problem is the following.
I have 6 divs one on top of another, something like:
<div id="header">header content</div>
<div id="sidebar1">sidebar1 content</div>
<div id="maincontent">maincontent content</div>
<div id="maincontent2">maincontent2 content</div>
<div id="sidebar2">sidebar2 content</div>
<div id="footer">footer content</div>
What I want to have is something like:
-----------------------------------------------------------
| header content |
-----------------------------------------------------------
-------------------------------------- -------------------
| maincontent content | | sidebar1 content|
| | -------------------
| | -------------------
| | | sidebar2 content|
| | -------------------
--------------------------------------
--------------------------------------
| maincontent2content |
| |
| |
| |
| |
--------------------------------------
-----------------------------------------------------------
| footer content |
-----------------------------------------------------------
In other words, is there a way to create a right column even if the divs are not one after another using only CSS and without moving the divs in the code?
I tried to use for sidebar1 the following css
position:absolute;
top:3em;
right:0;
and for sidebar2 the following css
position:absolute;
top:9.5em;
right:0;
but I have the impression that this is not the right way to do it.
A simple way could be to define the top attribute size as a function of the height of heather, but I couldn't find any way to do it only with CSS.
Thanks!
Well... as a direct answer to your question, you can use a combination of floats and % widths to accomplish this. You can also use fixed widths, but you'll have to determine what those sizes are. Here's a simple implementation:
Demo
CSS
#maincontent
{
float:left;
width:70%;
background:#ee5;
}
#sidebar2,#sidebar1
{
float:right;
width:30%;
background:#5e5;
}
#footer
{
clear:both;
background:#5ee;
}
#header
{
background:#55e;
}
HTML
<div id="header">header content</div>
<div id="sidebar1" class="side">sidebar1 content</div>
<div id="maincontent">maincontent content</div>
<div id="sidebar2" class="side">sidebar2 content</div>
<div id="footer">footer content</div>

Best way to create 100% width middle column with css

I have a pretty standard css layout where I use a container div that is 980px wide to hold everything. The only problem is that I want to have a 1900px wide banner half way down the page that is centered in the middle and is 100% width of the page. Is there any way to do this without getting rid of the container div?
so I am wanting
____________________
| | | |
| | | |
| | | |
|___| |___|
| |
| |
|___ ___|
| | | |
| | | |
| | | |
| | | |
|___|___________|___|
< 980px > container
< 100% page width >
Anyone know how to get that 1900px banner centered in the middle without deleting my container div?
THANKS!!
I didn't do 1900px for the sake of the demo, but i'm sure you'll get the idea :)
Demo
Cliff notes:
HTML:
remove containerWrapper if you want the whole banner visible (make scroll bars)
<div id="containerWrapper">
<div id="container">
<p>content</p>
<div id="banner">
someday i'll grow up to be 1900 px wide!
</div>
<p>content</p>
</div>​
</div>
CSS:
#containerWrapper {
width:100%;
overflow:hidden;
}
#container {
width:300px;
margin-left:auto;
margin-right:auto;
}
#banner {
margin-left:-200px; /* (this width - #container) / 2 */
width:700px;
}