CSS, HTML layout: relative div inside absolute div flows outside its container - html

(Apologies in advance if this is answered elsewhere. I looked around and couldn't find anything that seemed to apply.)
I have a layout with absolute and relative positioning for divs to sit in their appropriate positions, which almost works.
http://jsfiddle.net/dex3703/TZzKN/
The #centercontainer (red) is intended to let #mainsection (orange) sit inside all the other content. I have absolute and relative positioning that I thought should work, but I have these problems:
#mainsection's bottom extends beyond #centercontainer by about 20px.
bottom, left, right, top don't have an effect. Using bottom: 20px to lift the bottom up doesn't work.
If I don't have height: 100% on #mainsection--which I sense is wrong--it and the divs inside have no height! Only a little sliver of #contentsection is visible at the top of #mainsection.
I'm only interested in this working in Chrome and IE9 as well. Hope that makes things easier.
I'm sure this is some noob problem so am grateful in advance. Thanks.

When you set width and height for #mainsection to be 100%, you are telling it to be the same width and height as #centercontainer, excluding padding. There are 60px on each side because the padding of #centercontainer is 60px left and right.
The reason #mainsection extends below #centercontainer is that #breadcrumbcontainer is pushing it down by 40px (the height of #breadcrumbcontainer). It only extends down 20px because there is also 20px bottom padding for #mainsection.
If you set the bottom padding of #centercontainer to the height of #breadcrumbcontainer (INCLUDING #breadcrumbcontainer's top and bottom margins), that should fix the problem. It's probably not the most elegant way to fix it. but it should work.

I have made some changes to your CSS. It's still no nice stylesheet, but the design is not broken anymore.
#charset "utf-8";
/*
HTML4 layout
using absolute positioning to get layout to work without HTML5/CSS flexbox
colors:
#1E242D - html frame bg
#F3F3F3 - left nav
#FFFFFF - main content, inner menu
#267EB9 - drawer bg
#DBDBDB - nav and left nav border
#4F9DD7 - selected item blue
#FFFFFF - white text
#4A4A4A - darkest text, dividers
#767676 - middle dark text
#C1C1C1 - light text
*/
html {
font-size: 62.5%;
height: 100%;
background: White;
margin: 0;
}
body
{
font-size: 1.2em;
font-family: "Segoe UI";
height: 100%;
margin: 0;
}
p
{
margin: 0;
}
/* from html5boilerplate */
nav ul, nav ol
{
list-style: none;
list-style-image: none;
margin: 0;
padding: 0;
}
#layoutdiv
{
z-index: 100;
height: 100%;
position: relative;
}
#maindiv
{
margin: 10px 60px;
position: absolute;
top: 60px;
}
header
{
position: absolute; /* change to absolute positioning */
width: 100%;
top: 0;
height: 60px;
}
header p
{
color: #FFFFFF;
}
header span
{
vertical-align: middle;
}
#logodiv
{
width: 300px;
display: inline-block;
}
#notifypanel
{
width: 40px;
position: fixed;
left: 0;
top: 110px;
bottom: 70px;
background-color: LemonChiffon;
}
#notifypanel img
{
width: 24px;
height: 24px;
}
.left
{
float: left;
}
.right
{
float: right;
}
ul
{
list-style-type:none;
list-style: none;
margin: 0;
-webkit-padding-start: 0;
-webkit-margin-before: 0;
-webkit-margin-after: 0;
}
li
{
display: inline-block; /*need inline-block or height==0! */
cursor: pointer;
vertical-align: middle;
text-align:center;
}
#topnav
{
/* position: absolute;*/
/*width: 100%;*/
/* top: 55px; with absolute positioning, move its top to the header's bottom */
display: inline-block;
vertical-align: top;
}
#topnav ul
{
/*margin-left: 15px;*/
/*height: 100%;*/
}
#topnav li
{
margin-left: 15px;
padding: 5px 10px;
font-weight: bold;
color: #767676;
height: 100%;
/*line-height: 5em; for vertical alignment */
}
#topnav li:hover
{
color: #1E242D;
background-color: #F3F3F3;
}
#topnav .selected
{
background-color: #4F9DD7;
color: White;
}
#centercontainer
{
position: absolute;
overflow:hidden;
top: 60px;
bottom: 60px;
padding: 0 60px 20px 60px;
left: 0;
right: 0;
border: 1px solid red;
}
#breadcrumbcontainer
{
top: 0;
height: 40px;
width: 100%;
margin: 0 0 10px 0;
font-family: Segoe UI Light;
font-size: 3.6em;
line-height: 0.8em;
}
#breadcrumb
{
display: inline-block;
}
#viewcontrols
{
display: inline-block;
width: 320px;
text-align: right;
}
#mainsection
{
width: 100%;
height: auto; /* mainseciton won't display unless 100%, but height is off, doesn't quite sit in containing div */
position: relative;
top:30px;
background-color: Aqua;
border: 2px solid orange;
}
#contentsection
{
position: absolute;
left: 220px;
bottom: 0;
top: 0;
padding: 5px;
box-sizing: border-box; /* makes padding, margins behave like XAML */
overflow-x: auto;
overflow-y: auto;
background-color: AliceBlue; /* remove later */
display: inline-block;
}
#leftnav
{
width: 200px;
/*position: absolute;*/
left: 0;
bottom: 0;
top: 0;
background: #F3F3F3;
overflow-y: auto;
display: inline-block;
}
#leftnav li
{
display: block;
text-align: left;
padding: 7px 0 7px 20px;
border-bottom: 1px solid #DBDBDB;
}
#leftnav img
{
display: inline-block;
vertical-align: middle;
width: 24px;
height: 22px;
}
#leftnav p
{
display: inline-block;
vertical-align: middle;
margin: 0 0 0 10px;
}
#leftnav .selected
{
background-color: #4F9DD7;
}
#leftnav .selected:hover
{
background-color: #4387B7;
}
#leftnav li:hover
{
background-color: #FdFdFd;
}
footer
{
background: #267EB9;
height: 60px;
position: absolute;
bottom: 0;
width: 100%;
line-height: 1em; /* vertically centers header content .. see http://phrogz.net/CSS/vertical-align/index.html */
text-align: center; /* centers the center button div */
}
footer img
{
margin-right: 15px;
height: 24px;
width: 24px;
}
footer p
{
display: inline-block;
margin: 0;
vertical-align: super;
color: #FFFFFF;
font-size: 0.8em;
}
.footerleft
{
margin-left: 20px;
position: relative;
top: 17px;
}
.footerright
{
margin-right: 10px;
position: relative;
top: 17px;
}
.footercenter
{
display: inline-block;
position: relative;
top: 13px;
}
.footercenter div
{
display: inline-block;
margin-right: 20px;
}
.footercenter p
{
display: block;
}
.footercenter img
{
margin: 0;
}

Related

navigation bar disappears if i add picture under

I have a strange problem.
Everything on my page went well, I had my navigation bar ready (also for my mobile phone).
Then I put a photo under the navigation bar and the bar was gone ..
I want the bar fixed so that it remains visible, but when I do it is gone.
The picture should remain relative otherwise this will not be correct anymore if you resize to mobile phone.
Someone a solution that keeps the bar back?
Image css
.header{
max-width: 100%;
margin-left: 0;
margin-top: 0;
position: relative;
letter-spacing: 4px;
margin-top: 70px;
box-sizing: inherit;
}
.header-image{
max-width: 100%;
height: auto;
border-style: none;
background-size: cover;
background-position: center center;
display: block;
position: relative;
box-sizing: inherit;
}
.header-image-tekst{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
box-sizing: inherit;
display: block;
text-align: center!important;
margin-top: 16px!important;
}
.header-image-tekst h1{
color: white;
font-size: 38px!important;
margin: 10% 0;
}
.header-image-tekst h1 .border{
padding: 8px 16px!important;
background-color: black;
opacity: 0.75;
}
Navigation bar css
.container{
margin: 0 auto;
width: 100%;
position: fixed;
}
.nav{
border-bottom: 1px solid #EAEAE8;
text-align: right;
height: 70px;
line-height: 70px;
position: fixed;
}
.menu{
margin: 0 30px 0 0;
}
.menu a{
clear: right;
text-decoration: none;
color: #000;
margin: 0 10px;
line-height: 70px;
padding: 20px;
border-radius: 40px;
}
.menu a:hover{
background-color: #03999e3b;
}
label{
margin: 0 40px 0 0;
float: right;
margin: 0 10px;
line-height: 70px;
font-size: 26px;
display: none;
width: 26px;
float: right;
}
#toggle{
display: none;
}
#media only screen and (max-width: 700px){
label{
display: block;
cursor: pointer;
position: fixed;
}
.menu{
text-align: center;
width: 100%;
display: none;
}
.menu a{
display: block;
border-bottom: 1px solid #03989E;
margin: 0;
}
#toggle:checked + .menu {
display: block;
position: fixed;
}
}
.active{
background-image: linear-gradient(315deg, #ffffff 0%, #03989E 74%);
}
From what I can tell, the image is likely over-lapping the navbar. Use z-index on the navigation bar to make it appear on top of the image. If you don't want them overlapping then you'll have to adjust some of your layout CSS but that should work. I'll usually put my z-index for my navigation at 10, that way it'll always be in front of other elements where I have a z-index set.
Here's a reference article: https://developer.mozilla.org/en-US/docs/Web/CSS/z-index

css3 after is on the text in a element

My problem is that the :after element is on the text in an element. Here is an example:
On CodePen
I want the :after to be below the text.
How can I fix this?
body {
text-align: center;
}
a {
display: inline-block;
text-decoration: none;
padding: 10px;
background: #222;
color: #f3f3f3;
font-size: 2em;
margin: 20px auto;
position: relative;
}
a:after {
content: "";
width: 100%;
height: 50%;
background: #00A3A3;
position: absolute;
left: 0;
top: 0;
}
Home page
Just change top:0 to top:50px; in after css. By keeping top:0
The top property sets the top edge of an element to a unit above/below the top edge of its nearest positioned ancestor.
you are making the element to stay on the top by keeping it 0
body {
text-align: center;
}
a {
display: inline-block;
text-decoration: none;
padding: 10px;
background: #222;
color: #f3f3f3;
font-size: 2em;
margin: 20px auto;
position: relative;
}
a:after {
content: "";
width: 100%;
height: 50%;
background: #00A3A3;
position: absolute;
left: 0;
top: 50px;
}
Home page
Use top: 100% on the :after pseudo element to place it exactly below the main element.
body {
text-align: center;
}
a {
display: inline-block;
text-decoration: none;
padding: 10px;
background: #222;
color: #f3f3f3;
font-size: 2em;
margin: 20px auto;
position: relative;
}
a:after {
content: "";
width: 100%;
height: 50%;
background: #00A3A3;
position: absolute;
left: 0;
top: 100%;
}
Home page

How do I set width to include browser scrollbar?

I have a website that I'm designing to be responsive to work on various browsers and devices, most of my content is set with widths to either auto or 100%. However my elements aren't exactly centered as the website includes the width under the scrollbar. I want the width to the available room that you can see, so that my website will center properly.
For example my navbar is correctly aligned on the left, but not the right side of the page. Here is the CSS for my navbar, I have LI bullets that make up the options in the HTML.
#header {
border: 2px solid black;
border-top: none;
background-color: #FFFFFF;
height: 2.75em;
left: 0px;
right: 0px;
width: 100%;
z-index: 1;
position: fixed;
margin-top: -2.55em;
}
#navbar {
position: relative;
text-align: center;
right: 0px;
left: 0px;
width: auto;
display: inline;
}
ul {
left: 0px;
right: 0px;
top: 0px;
}
li {
display: inline;
text-align: center;
width: auto;
padding-left: 5em;
padding-right: 5em;
}
Please try this : http://jsfiddle.net/sqp4nfg5/1/
and css :
body { margin:0; padding:0
}
#header {
background-color: #777;
color: #fff;
float: left;
width: 100%;
z-index: 1;
}
#navbar {
float: left;
width: 100%;
}
ul { margin:0; padding:0
}
li {
float: left;
padding-left: 2%;
padding-right: 2%;
text-align: center;
height:35px; line-height:35px; list-style:none;
}
.center_div{float:left; width:100%; }
.center_div div{width:90%; margin:0 auto; overflow:hidden; border:1px solid lightpink; padding:1% 2%}

How to fix my nav bar? Positioning is different on different screens

I'm kind of new to HTML and CSS. I have a nav bar that I want (the logo and links) aligned to being above the sidebar on my page. It's in different positions on different screens (and when browser is resized) and I don't know how to fix it. I made a fiddle thing and I'll link to the site so that you will know what I mean.
This is the fiddle: The Fiddle
This is the page: The page
#header {
width: 100%;
height: 91px;
margin: 0;
top: 0;
}
#menu {
float: right;
width: 100%;
height: 54px;
margin-top: 0;
background: #ffffff url(http://i1378.photobucket.com/albums/ah105/WinPhanNick/menu_bar_zps6212d723.jpg) repeat-x left top;
position: fixed;
}
#menu ul {
margin: 0;
padding: 0px 0 0;
list-style: none;
line-height: normal;
margin-left: 28%;
}
#menu li {
display: inline;
text-align: center;
}
#menu a {
display: block;
float: left;
height: 36px;
padding: 18px 20px 0px 20px;
text-decoration: none;
text-align: center;
text-transform: uppercase;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
color: #ffffff;
}
li#logo {
height: 52px;
width: 52px;
background: url(http://i1378.photobucket.com/albums/ah105/WinPhanNick/cb_logo_zpsd1b14443.png) no-repeat;
margin-top: 1px;
margin-right: 1px;
margin-left: 1px;
}
#menu a:hover,
#menu .active a {
background: #1687ef;
color: #FFFFFF;
}
#logo {
float: left;
width: 270px;
height: 76px;
margin: 0px;
padding: 15px 0px 0px;
margin-left: 27%;
}
Make your link wrapper (which is the ul) the same width as your page container (which is 892px) and set it to margin: auto to center it. You can remove the margin-left: 28% as well. That's not needed. You also have a float issue so your ul is collapsed. You need to clear your floated elements. You can add overflow:hidden.
#menu ul{
overflow: hidden; //clear float issue
width: 892px; // same width as #page
margin: 0 auto; //will center
padding: 0px 30px; //add to keep the same padding as #page-bgtop
}
FIDDLE

Div doesn't expand with text

I am trying to make a forum but the problem is that the div where the text goes doesn't expand in height when the text becomes to long for the div. Instead the text goes outside.
I also need the sidebar (with the userinformation) to expand with the text so it always has the same height as the text.
JSFiddle: http://jsfiddle.net/9stPU/1/
CSS:
.forumContent {
list-style-type: none;
background: #34495e;
letter-spacing: 1px;
width: 1170px;
margin: 0;
color: white;
margin-left: 50px;
}
.forumContent li {
padding: 5px 0 5px 10px;
margin-left: -40px;
min-height: 41px;
}
.forumContent li h3 {
margin: 0;
padding: 0;
font-size: 14px;
}
.forumContent li small {
font-size: 9px;
}
.forumContent a {
color: white;
text-decoration: none;
width: 100%;
height: 100%;
}
.forumContent li:hover {
background: #3E5368;
}
.forumContent a li {
float: left;
width: 366px;
}
.forumContent a li:first-child {
width: 100px;
}
.topicUser {
width: 150px;
float: left;
background: #000;
margin-left: -10px;
height: 100%;
}
.topicUser h3 {
margin-left: 2.5px !important;
}
.topicUser small {
position: absolute;
margin-top: -15px;
margin-left: 7.5px;
}
.topicUser p {
margin-top: 2px;
margin-left: 3px;
}
.topicContent {
width: 1060px;
float: right;
height: 100%;
}
ADD :
.forumContent {
...
overflow: hidden; /* ADD THIS */
}
This problem occurs because the height of the container element forumContent is calculated automatically (if it is not specified) as the the sum of the height of non float elements. the height of float elements is not considerate.