Outer div not expaning in height with innner divs - html

In the following code the div content-container is not expanding in its height as increase in the height of the divs inside it. I want to make its height auto increment with the increase in height of inner divs
This id my css code
body{
margin:0;
padding:0;
line-height: 1.5em;
background:#f7f7f7;
}
b{font-size: 110%;}
em{color: red;}
#maincontainer{
width: 1000px; /*Width of main container*/
margin: 0 auto; /*Center container on page*/
}
#topsection{
background: #f0f0f0;
height: 90px; /*Height of top section*/
}
#topsection h1{
margin: 0;
padding-top: 15px;
}
#content-container{
float:left;
width:100%;
background:#f8f8f8;
border:1px solid #f0f0f0;
margin-top:-22px;
margin-left:-1px;
height:auto;
}
#contentwrapper{
float: left;
width: 100%;
}
#contentcolumn{
margin-right: 310px; /*Set right margin to RightColumnWidth*/
background:none;
padding:15px;
clear:both;
}
#rightcolumn{
float: left;
width: 310px; /*Width of right column*/
margin-left: -311px; /*Set left margin to -(RightColumnWidth) */
background: none;
padding-top:20px;
margin-top:1px;
border-left:1px solid #222222;
}
#rightcolumn h2{
font:18px georgia;
font-weight:bold;
border-bottom:2px solid #222222;
}
#footer{
clear: left;
width: 100%;
background: black;
color: #FFF;
text-align: center;
padding: 4px 0;
}
#footer a{
color: #FFFF80;
}
.innertube{
margin: 10px; /*Margins for inner DIV inside each column (to provide padding)*/
margin-top: 0;
}
body{
margin:0;
padding:0;
line-height: 1.5em;
background:#f7f7f7;
}
b{font-size: 110%;}
em{color: red;}
#maincontainer{
width: 1000px; /*Width of main container*/
margin: 0 auto; /*Center container on page*/
}
#topsection{
background: #f0f0f0;
height: 90px; /*Height of top section*/
}
#topsection h1{
margin: 0;
padding-top: 15px;
}
#content-container{
float:left;
width:100%;
background:#f8f8f8;
border:1px solid #f0f0f0;
margin-top:-22px;
margin-left:-1px;
height:auto;
}
#contentwrapper{
float: left;
width: 100%;
}
#contentcolumn{
margin-right: 310px; /*Set right margin to RightColumnWidth*/
background:none;
padding:15px;
clear:both;
}
#rightcolumn{
float: left;
width: 310px; /*Width of right column*/
margin-left: -311px; /*Set left margin to -(RightColumnWidth) */
background: none;
padding-top:20px;
margin-top:1px;
border-left:1px solid #222222;
}
#rightcolumn h2{
font:18px georgia;
font-weight:bold;
border-bottom:2px solid #222222;
}
#footer{
clear: left;
width: 100%;
background: black;
color: #FFF;
text-align: center;
padding: 4px 0;
}
#footer a{
color: #FFFF80;
}
.innertube{
margin: 10px; /*Margins for inner DIV inside each column (to provide padding)*/
margin-top: 0;
}
HTML code
<div id="maincontainer">
<div id="topsection"><div class="innertube"><h1>CSS Fixed Layout #2.2- (Fixed-Fixed)</h1></div>
</div>
<div id="content-container">
<div id="contentwrapper">
<div id="contentcolumn">
<div class="innertube">
content here
</div>
</div>
</div>
</div>
<div id="rightcolumn">
<div class="innertube">
content here
</div>
</div>
</div>
<div id="footer">UIasdfg</div>
</div>

Demo
Your code seems to work fine, only minor tips to work it smoothly :
give body height:100%;
In the class innertube, use a paragrap to show the content, this way, u'll achieve a better flexibilty in showing big text paras.
use word-break: break-all for para
like this
<div class="innertube">
<p style="word-break: break-all;">
content here content here content here content here content here content here content here content here content here
</p>
</div>
and clear:both to clear all floats in the end :
</div> <!-- #content-container -->
<div style="clear:both"></div>

Ok, I think I figured it out. Using the same JsFiddle I created... I added a small tweak to only one of your CSS elements, which is below. We went from:
#contentcolumn {
margin-right: 310px;
/*Set right margin to RightColumnWidth*/
background:none;
padding:15px;
clear:both;
}
and then all i added was a simple display which ended up being:
#contentcolumn {
margin-right: 310px;
/*Set right margin to RightColumnWidth*/
background:none;
padding:15px;
clear:both;
display:inline;
}
This enables whatever is inside of that div to maintain being inside of that div. Here is the demo that provides a better example of what I am saying.
A few things to note, I did add in a background color so that you could effectively see what was changing, as well as I added a height, which doesn't need to be there.. again, I added that to show you what was happening with the innermost div.
One really awesome tool that can help you understand why this works is the Almanac, which will show you many tools to help you with any CSS needs. I do want to point out that #Mr.Alien's stack question is another resource that is well beyond the Almanac's explanation. Let me know if you need anything else :)

Related

Div not expanding to fill the window

I've been trying to find a solution to this for days, but haven't found anything that works.
I thought I'd finally make an account on this great website, so here goes:
I am trying to have a div expand from left to right, with 170px of clearance on both sides.
However, when there is no content on the page, or only a few words, the div doesn't expand.
I've tried to add width: 100% in several different divs to try and have them take up the full space, but that either does nothing, or completely busts the page layout. for example, instead of filling out the page, the div that's supposed to hold the content moves off the right side of the screen, and also doesn't leave the 170px margin.
I hope you can be of help, my code is posted below:
Thanks in advance,
Chris
the html:
<html>
<body>
<div id="wrapper">
<div id="pagetopwrap">
</div>
<div id="pagemainliquid">
<div id="pagemainwrap">
<div id="content">
<div id="headerwrap">
<div id="header_left">
</div>
<div id="header_main">
<div id="logo_row">
<p id="logotext">Site Title</p>
</div>
<div id="menu_row">
<!-- irrelevant menu button code -->
</div>
</div>
<div id="header_right">
</div>
</div>
<div id="contentbody">
<div id="contenttext">
<p id="contenttextmakeup">Lorum Ipsum Dolor Sit Amet</p>
</div>
</div>
</div>
</div>
</div>
<div id="leftcolumnwrap">
<div id="leftcolumn">
</div>
</div>
<div id="rightcolumnwrap">
<div id="rightcolumn">
</div>
</div>
<div id="footerwrap">
<div id="footer">
</div>
</div>
</div>
</body>
</html>
the css:
It is not ordered too well, the uninteresting sides, top and footer are first, and the main part of the website at the bottom
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
background-color: #0f0f0f; /* is normally an image */
}
#wrapper {
width: 100%;
min-width: 960px;
max-width: 1920px;
margin: 0 auto;
height: 100%
}
#pagetopwrap {
height: 50px;
width: 100%;
float: left;
margin: 0 auto;
}
#pagemainliquid {
float: left;
}
#pagemainwrap {
margin-left: 170px;
margin-right: 170px;
float: left;
}
#leftcolumnwrap {
width: 170px;
margin-left:-100%;
float: left;
}
#leftcolumn {
margin: 5px;
}
#rightcolumnwrap {
width: 170px;
margin-left: -150px;
float: left;
}
#rightcolumn {
margin: 5px;
}
#footerwrap {
width: 100%;
float: left;
margin: 0 auto;
clear: both;
bottom:50px;
}
#footer {
height: 0px;
margin: 5px;
}
#headerwrap {
width: 100%;
margin: 0 auto;
}
#header_left {
background-color: #ff0000; /* is normally an image */
width:25px;
height:200px;
float:left;
}
#header_right {
background-color: #ff0000; /* is normally an image */
width:25px;
height:200px;
margin-left: 0px;
float:right;
position:relative; top:-200px;
}
#header_main {
background-color: #00ff00; /* is normally an image */
margin-left: 25px;
margin-right: 25px;
height:200px;
background-size: 100% 200px;
}
#contentbody {
background-color: #E2E2E2;
border-radius: 10px;
margin-top:10px;
border: 1px solid #A7A7B2;
}
#contenttext {
margin-left:10px;
margin-right:10px;
}
#logo_row {
height:150px;
width:100%;
float:left;
}
#logotext {
margin-top:20px;
margin-left:10px;
vertical-align: middle;
font-size: 55px;
font-family: "Arial Black", Arial;
}
#contenttextmakeup {
margin-top:12px;
margin-left:10px;
vertical-align: middle;
}
#menu_row {
width:100%;
}
button.menubutton {
/* irrelevant button markup */
}
http://jsfiddle.net/w9qLh6tp/ if that helps, I've seen it a lot around here :)
Instead of using !important, save yourself a headache in figuring out why important works.
CSS = cascading style sheets. You have a selector with more specificity which is why your width property isnt changing. Figuring out the route of the problem will save you time in the future when this happens again (and it will)
For example, if I styled something like so
#container .red { width: 50% }
updating the style using .red without the #container in front of it has less specificity. So if they are both modifying the same property, the one with more prevalence will take effect. This is true for media queries as well.
Fixed here http://jsfiddle.net/w9qLh6tp/1/
#pagemainwrap {
margin-left: 170px;
margin-right: 170px;
float: left;
width: 100% !important; // set it highest priority
border: 3px red solid; // border is set just for demonstration
}
set the width to be 100% with priority (!important) that will override any other css styling.

CSS Centering with nested Divs

Can anyone take a look at this and let me know what I'm doing wrong (probably something stupid)?
I would like the Text "test" to be centered.
http://fiddle.jshell.net/uteaH/3/
CSS:
.wrap {
max-width: 1139px;
margin-left: auto;
margin-right: auto; }
#screenPresentation {
border-top: 4px solid #d95936;
margin-top: 50px;
margin-bottom:10px;
background: #fff;
}
#screenPresentation h2 {
margin-top: -45px;
color: #000;
font-size: 2.4em;
font-weight: 500;
float:left;
}
.loginContainer-wrapper {
width: 99%;
height: 500px;
border: 2px solid #000;
margin:0 auto;
}
HTML:
<div class="wrap" id="screenPresentation">
<h2>Title</h2>
<div class="loginContainer-wrapper">
test
</div>
</div>
text-align:center; by any chance?
I'm going to be a mindreader here since you won't tell us exactly what needs to be centered
DEMO
For #screenPresentation h2
Remove
float:left;
Replace with
position: absolute;
width: 95%;
text-align: center;
Sorry - I updated my question. I need the text "test" centered inside the inner div.
Oh in that case
Remove width:95%;text-align:center from #screenPresentation h2
Add text-align:center to .loginContainer-wrapper
DEMO
To center the text you need two steps:
First reset margin and padding for your tags:
* {
margin:0;
padding:0;
}
Second add text-align:
.wrap {
text-align:center;
}
The demo http://fiddle.jshell.net/uteaH/9/
you can use
<center>
test
</center>
that will do it.

How to align floated elements to the bottom of their container

Simple question, but I'm struggling with solution.
Jsfiddle here.
How can I get the title and date to both align to the bottom of the container, while ensuring that:
The length of the title will push the date across (but doesn't need to wrap)
The blue button is always centrally aligned between the date and the red icon
The titleBar container is always the same fixed height
Need a CSS-only solution if possible - I already know how to do this with JS if needed
HTML:
div class="titlebar bgEarth0">
<h1 id="title">Test Title</h1>
<h2 id="date">23 October 2013</h2>
<div class="icon"></div>
<div class="buttonArea">
<div class="button"></div>
</div>
</div>
CSS:
.titlebar { height: 50px; border:1px solid #000}
#title {font-size: 20px; font-weight: normal; float: left; margin:0}
#date { font-size: 12px; font-weight: normal; float: left; margin-left: 30px; margin:0 12px}
.buttonArea {position:relative; overflow:auto; height:40px; margin-top:5px}
.button {margin:0 auto; width:60px; height:40px; background:#0000ff}
.icon {float:right; background:#ff0000; height:40px; width:60px; margin-top:5px}
http://jsfiddle.net/hC236/
You can use absolute position.
Wrap title and date with a div and set its position to absolute.
HTML:
<div class="titlebar bgEarth0">
<div class="bleh">
<h1 id="title">Test Title</h1>
<h2 id="date">23 October 2013</h2>
</div>
<div class="icon">ddd</div>
<div class="buttonArea">
<div class="button"></div>
</div>
</div>
CSS:
.titlebar {
height: 50px;
border:1px solid #000;
position: relative;
}
.bleh {
position: absolute;
bottom: 0px;
left: 0px;
}
#title {
font-size: 20px;
font-weight: normal;
float: left;
margin:0
}
#date {
font-size: 12px;
font-weight: normal;
float: left;
margin-left: 30px;
margin:0 12px
}
.buttonArea {
position: absolute;
overflow:auto;
height:40px;
top:5px;
right: 0px;
}
.button {
margin:0 auto;
width:60px;
height:40px;
background:#0000ff
}
.icon {
background:#ff0000;
height:40px;
width:60px;
margin-top: 5px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
}
OR Table Example:
http://jsfiddle.net/hjM56/
HTML:
<div class="titlebar">
<div class="col-1">
<h1 id="title">Test Title</h1>
<h2 id="date">23 October 2013</h2>
</div>
<div class="col-2">
<div class="icon"></div>
</div>
<div class="col-3">
<div class="button"></div>
</div>
</div>
CSS:
.titlebar {
display: table;
height: 50px;
border: 1px solid #000;
width: 100%;
}
.col-1,
.col-2,
.col-3 { display: table-cell; }
.col-1 {
white-space: nowrap;
vertical-align: bottom;
width: 1%;
}
.col-2 {
text-align: center;
width: auto;
}
.col-3 {
text-align: right;
width: 1%;
}
#title {
font-size: 20px;
font-weight: normal;
display: inline-block;
margin: 0px;
padding: 0px;
}
#date {
font-size: 12px;
font-weight: normal;
margin-left: 12px;
margin-top: 0px;
margin-right: 12px;
margin-bottom: 0px;
display: inline-block;
padding: 0px;
}
.button {
width: 60px;
height: 40px;
background: #0000ff;
margin-top: 5;
display: inline-block;
}
.icon {
background: #ff0000;
height: 40px;
width: 60px;
margin-top: 5px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
}
Here is one way to do it but it involves some extra mark-up.
I added some wrappers around the title and date as follows:
<div class="titlebar">
<div id="titleArea">
<div id="table-wrap">
<div id="table-cell">
<h1 id="title">Test Title</h1>
<h2 id="date">23 October 2013</h2>
</div>
</div>
</div>
<div class="icon"></div>
<div class="buttonArea">
<div class="button"></div>
</div>
</div>
Apply the following CSS:
.titlebar {
height: 50px;
border:1px solid #000
}
#titleArea {
height:40px;
margin-top:5px;
float: left;
}
#table-wrap {
display: table;
height: 100%;
}
#table-cell {
display: table-cell;
height: 100%;
vertical-align: bottom;
}
#title {
font-size: 20px;
font-weight: normal;
padding:0;
display: inline;
}
#date {
font-size: 12px;
font-weight: normal;
padding-left: 12px;
display: inline;
}
.buttonArea {
position:relative;
overflow:auto;
height:40px;
margin-top:5px;
border: 1px dotted blue;
}
.button {
margin:0 auto;
width:60px;
height:40px;
background:#0000ff
}
.icon {
float:right;
background:#ff0000;
height:40px;
width:60px;
margin-top:5px;
border: 1px dotted blue; /* for demo only */
}
See demo at: http://jsfiddle.net/audetwebdesign/5NDDQ/
I created an outer wrapper #titleArea that has the same height and top margin as the #buttonArea.
Within #titleArea, I created a CSS table/table-cell (two nested div's) so that I can get the vertical alignment to be at the bottom.
Finally, I set display: inline to #title and #date.
A detail that may need adjustment involves the base line of the title and time. The bottom leading causes the text to sit slightly above the bottom edge of the button.
It seems like a lot of work for what appears to be a relatively simple requirement.
To make this a bit more bullet-proof, I would add a min-width to the .titlebar to prevent the .buttonArea to develop a horizontal scroll bar and the .icon from wrapping to a second line.
You shouldn't use floating unless necessary. See this JSFiddle Live Demo
Basically if you remove the floats and display:inline-block; instead, they will align. I also removed the overflow:auto, as that would limit the icon area.
Also, adding left:15%; will align the blue area between the date and the red area.
EDIT: Example with max-width specifications to contain the div inside the title bar. Live Demo

Center logo and menu on repetitive or 100% header?

I have HTML
<div class="mainwraper" style="width:100%;">
<div class="header1">
div logo left <img src="logo"> // - it sends it pasted to the left sidebar
div class right // it send it pasted to the right sidebar
</div> // need to center them in the page and keep the repeative effect
<div class="header2" style="width:100%;">
<div class="headbar">
<ul class="menu" style="background:#0099CC;"> … </ul>
</div>
</div>
</div>
CSS
.mainwraper {
margin:0 auto;
}
.header1 {
float:left; width:100%; height:78px; margin-top: 10px;
}
.header2 {
float:left;
width:100%;
position:relative;
z-index:auto;
height:52px;
margin-top:20px;
background: #000;
opacity: 0.65;
border-radius: 10px;
}
.headbar {
background-color: inherit;
float: left;
list-style-type: none;
margin: 0 auto;
padding: 0;
position: relative;
width: 100%;
border-radius: 10px;
}
.menu {
background-color: inherit;
background-image:url(images/menugradient.png);
float: left;
list-style-type: none;
margin: 0 auto;
padding: 0;
position: relative;
width: 100%;
}
I want it to look like this [1]: http://postimg.org/image/hi7knv1tp/ "tooltip"
but it looks something like this [2]: http://postimg.org/image/ptqdhlfyv/ |tooltip".
I also want to mention that after i have another Div class main wrapper of 972px that is centered correctly.
you can use margin:0 auto; to center your navigation

Why aren't these styles resulting in a single-line header and centered page contents?

I am not that bad at this, but somehow i am not able to center the contents of the page.
Also, the logo and tbar-right divs are not aligning properly (I'd like them to be arranged in a single line).
This is my markup:
<body>
<div class = "container">
<div id="topbar" >
<div class="logo">
<img src="images/rg-logo.jpg"/>
</div>
<div class="tbar-right">
<div id="User"><!--the script will feed this div--></div>
<!--Dummy Text-->Jasdeep, you have 24 routemiles |
My Profile |
Logout
</div>
</div>
</div>
</body>
...and these are the styles:
* {
margin:0;
padding:0;
}
body{
-x-system-font:none;
background:#FFF;
border:0 none;
color:#555F6A;
font-family:Verdana,arial,helvetica,sans-serif;
font-size:0.7125em;
font-size-adjust:none;
font-stretch:normal;
font-style:normal;
font-variant:normal;
font-weight:normal;
line-height:1.5em;
margin:0;
padding:0;
text-align:center;
}
.container {
text-align: center;
}
#topbar {
background-color: #df3e36;
height: 32px;
width: 1004px;
}
.logo {
padding-left: 20px;
padding-top: 4px;
width: 15%;
height:27px;
}
.tbar-right {
text-align: right;
padding-right: 10px;
color: #FFF;
padding-top: 7px;
width: 85%;
}
.tbar-right a{
color: #FFF;
}
Please, help!
.container{margin:0 auto;}
As long as you have defined an explicit width. You should also probably replace
<div class = "container">
with
<div class="container">
Should center container. Make sure you don't float it.
.container{
width: /* must specify a width */
margin-left:auto;
margin-right:auto;
}
This should fix the alignment
.logo{
float:left;
padding-left: 20px;
padding-top: 4px;
width: 15%;
height:27px;
}
.tbar-right{
float: right;
padding-right: 10px;
color: #FFF;
padding-top: 7px;
width: 85%;
}
And you may need to rearrange the HTML a bit by putting the .tbar-right before the .logo
Try this:
#topbar { margin: 0 auto;}
The logo isn't aligning with the other stuff because it has a different padding-left. Change to
.logo {
padding-left: 0px; //or don't even list a padding-left,
padding-top: 4px;
width: 15%;
height:27px;
}
OH if you wanted it on the same line horizontally float them both to the left or right, and make sure there's enough space. ;D