I feel like this should be much easier than I am making it...I'm looking for a solution to have 1 solid color extend from the left and end at a logo, then have a second solid color extend all the way to the right. I want the wrapper divs to extend 100%. So something like:
<div id="header-wrap"><!--100% page width-->
<div id="header"><!--1000px centered fixed width-->
<div id="logo"></div><!-- align left-->
<div id="nav"></div><!-- align right-->
</div>
<div id="sub-header-wrap">
...
</div>
</div>
Here's an image showing what I mean:
There is a lot that goes into this.
Let me start of with a link to a working fiddle: JSFiddle
How can I explain this?
Basically I have the two full-width divs that have the full background color. Inside those two divs I have a div classified as .inner that has 80% of the width (which can be whatever you want) that is aligned to the center with margins.
Inside .inner I have a left div and a right div of the proper sizes to contain the logo/navigation. Inside the left divs, I have another div, .shade that will darken the left side of the header.
The .left divs are relatively positioned and the .shade divs are absolutely positioned.
CSS:
body{
margin: 0;
}
header
{
display:block;
width: 100%;
}
header .top
{
background: #00a;
text-align: center;
color: white;
}
header .inner
{
width: 80%;
margin: 0 10%;
text-align: left;
}
header .inner .logo, header .inner .left
{
display: inline-block;
width: 20%;
margin: 0;
text-align: center;
height: 100%;
padding: 10px 0px;
position: relative;
z-index: 1;
}
header .inner .right
{
display: inline-block;
width: 78%;
margin: 0;
text-align: right;
}
header li
{
display: inline-block;
list-style: none;
}
header .bottom
{
background: #ca0;
}
header .shade
{
width: 1000%;
height: 100%;
position: absolute;
top: 0px;
right: 0px;
background: rgba(0, 0, 0, .3);
z-index: -1;
}
HTML:
<header>
<div class="top" align="center">
<div class="inner">
<div class="logo">
Logo
<div class="shade"></div>
</div>
<div class="right">
<li>Nav 1</li>
<li>Nav 2</li>
</div>
</div>
</div>
<div class="bottom">
<div class="inner">
<div class="left">
Subtext
<div class="shade"></div>
</div>
<div class="right">
<li>Link</li>
</div>
</div>
</div>
</header>
Full JSFiddle
If I understand you correctly, try something like this in a separate CSS file, or within a <style> block. It's not tested though, sorry.
#header {
margin: 0 auto; /* for centering */
width: 1000px;
}
#logo {
float: left;
width: 250px; /* for example */
background-color: red; /* for example */
}
#nav {
float: right;
width: 750px; /* for example */
background-color: blue; /* for example */
}
UPDATE:
If you can afford CSS3, this post can be intresting for you as well.
Related
I will explain my problem.
For school I have to make a website, but it is not working how it should be.
I have a border made of divs around the screen, and the page in the middle. When I first open the page, everything is in place, but when I click on one of the nav items (#link) the page suddenly loses its margin top and left. So it goes outside of the borders. I pasted all the code in the snippet, as I believe it will be too much for a post.
To see the full page and problem, please copy the code in a file to open it in the browser itself. I used vw and vh because it want it to be the same on different screens. I will do the inside elements mostly with percentages
So my questions:
How do I prevent this from happening, and an example?
Is there a way to set #Home as the usual landing space? without adding #Home in the link (and without changing its position)?
And my last question regarding CSS animation, how do I add a transition so it looks like the page is scrolling to the #div.
body{
top: 0;
margin: 0;
padding: 0;
left: 0;
}
.wrapper{
width: 100vw;
height: 100vh;
overflow: hidden;
}
.container{
width: 300vw;
height: 200vh;
background-image: url("../img/background.png");
background-size: cover;
}
/* simple nav*/
ul{
display: inline;
z-index: 99;
position: fixed;
}
ul li{
list-style-type: none;
display: inline;
}
ul li a{
text-decoration: none;
}
/*pages*/
.page{
margin: 10vh 10vw;
width: 80vw;
height: 80vh;
transition: 2s;
}
#Interactive{
background: blue;
float: left;
}
#Graphical{
float: left;
}
#Company{
float: left;
}
#Conclusion{
float: left;
}
#Home{
float: left;
}
/*header borders*/
.borders{
position: fixed;
z-index: 30;
}
.border-top{
height: 10vh;
width: 100vw;
top:0;
background: #007CFF;
}
.border-left{
height: 100vh;
width: 10vw;
top: 0;
background: #007CFF;
position: absolute;
}
.border-right{
height: 100vh;
width: 10vw;
top: 0;
background: #007CFF;
float: right;
margin-top: -10vh;
}
.border-bottom{
height: 10vh;
width: 100vw;
bottom: 0;
background: #007CFF;
position: absolute;
}
<div class="header">
<ul>
<li>Home</li>
<li>Interactive</li>
<li>Graphical</li>
<li>Company</li>
<li>Conclusion</li>
</ul>
</div>
<div class="borders">
<div class="border-top">
</div>
<div class="border-left">
</div>
<div class="border-right">
</div>
<div class="border-bottom">
</div>
</div>
<div class="wrapper">
<div class="container">
<div id="Interactive" class="page">
</div>
<div id="Graphical"class="page">
</div>
<div id="Company"class="page">
</div>
<div id="conclusion"class="page">
</div>
<div id="home"class="page">
</div>
</div>
</div>
Thanks for thinking with me, any help is appreciated.
I didn't really know how to call this post, so the search for it was difficult.
Please remove this div
#Interactive{
background: blue;
float: left;}
I think this only you are expecting.
I have made changes to your HTML code and CSS code on the basis of what i thought you wanted to achieve. Below is the code.
* {
padding: 0;
margin: 0;
}
body{
display: flex;
flex-direction: column;
}
.header {
padding: 10px 50px;
}
ul li{
list-style-type: none;
display: inline-block;
padding: 10px;
}
.wrapper {
flex-grow: 1;
padding: 50px 150px;
}
.page{
transition: 2s;
width: 100%;
height: 100%;
}
#Home{
background-color: pink;
}
#Interactive{
background: blue;
}
#Graphical{
background-color: green;
}
#Company{
background-color: yellow;
}
#Conclusion{
background-color: orange;
}
<div class="header">
<ul>
<li>Home</li>
<li>Interactive</li>
<li>Graphical</li>
<li>Company</li>
<li>Conclusion</li>
</ul>
</div>
<div class="wrapper">
<div id="Home" class="page">
</div>
<div id="Interactive" class="page">
</div>
<div id="Graphical" class="page">
</div>
<div id="Company" class="page">
</div>
<div id="Conclusion" class="page">
</div>
</div>
If you want to use transition for smooth scrolling. Refer to
this
article, you will have to use jQuery.
Also do not use fixed width or height until necessarily required.
Use document.getElementById('Home').focus() in document.ready() of js to bydefault show the Home Page.
Always focus on making responsive solutions with relative content rather than absolute content.
Let me know if you need more help :)
I have a web page with a header, content and footer.
There is a background image in the content. I would like the image to fill the remaining space between the header and footer. There are divs that are children of the content div with the image that will sometimes have content and other times will not.
HTML:
<body>
<div id='main'>
<div id='header'>
<div id='logoCompany'>
<img class='headerGraphics' src='Graphics\logo smaller.jpg'><img class='headerGraphics' src='Graphics\Marvelous Header3 small.png'>
</div>
</div>
<div id='contentParent' class='floatClear'>
<div id='content' style = "text-align: center;">
<div id='leftPane'>
Left Col
</div>
<div id='rightPane'>
Right Col
</div>
</div>
</div>
<div id='footer'>
Footer
</div>
</div>
</body>
CSS:
* {
margin: 0px;
}
.floatClear {
clear: both;
}
.headerGraphics {
display: inline;
}
#header {
background: #023489;
text-align: center;
}
#logoCompany {
display: inline;
}
#contentParent {
height: 373px;
width: 100%;
background-image: url(../Graphics/background.jpg);
}
#leftPane {
background: yellow;
float: left;
margin: 100px 0 0 10%;
opacity: .5;
width:40%;
}
#rightPane {
background: green;
float: right;
margin: 100px 10% 0 0;
opacity: .5;
width:40%;
}
#footer {
width:100%;
}
I tried height: 100% but I suspect this fails without content. In fact I think that's why everything fails except when I hard code a height. But that is not a good solution for obvious reasons.
Here's an example
Anyone have any ideas how to make this work?
EDIT:
I tried changing this:
#contentParent {
height: 373px;
width: 100%;
background-image: url(../Graphics/background.jpg);
}
to this:
#contentParent {
flex: 1;
background-image: url(../Graphics/background.jpg);
}
But it shrunk the div to the size of the child div, making things worse..
Here is a solution which defines header, footer and #contentParent as position: fixed and gives #contentParent 100% height minus the height of header and footer (= 80px in this example - this depends on your own settings).
Any additional content has to be added inside #contentParent - this element will then scroll since it has overflow-y:auto;. The header and footer will always remain on the screen due to their absolute position and won't cover any part of the content since #contentParent has according margins at top and bottom which equal the height of the header and footer.
The background image will cover #contentParent completely and won't scroll diue to background-attachment: fixed (integrated in the shortcut background property)
html,
body,
#main {
height: 100%;
margin: 0px;
}
.floatClear {
clear: both;
}
.headerGraphics {
display: inline;
}
#header {
position: fixed;
top: 0;
width: 100%;
height: 40px;
background: #023489;
text-align: center;
}
#logoCompany {
display: inline;
}
#contentParent {
position: fixed;
height: calc(100% - 80px);
width: 100%;
overflow-Y: auto;
margin: 40px 0;
background: url(http://placehold.it/1500x800/fc7) center center no-repeat;
background-position: fixed;
background-size: cover;
}
#leftPane {
background: yellow;
float: left;
margin: 100px 0 0 10%;
opacity: .5;
width: 40%;
}
#rightPane {
background: green;
float: right;
margin: 100px 10% 0 0;
opacity: .5;
width: 40%;
}
#footer {
position: fixed;
bottom: 0;
width: 100%;
height: 40px;
width: 100%;
background: lightblue;
}
<body>
<div id='main'>
<div id='header'>
<div id='logoCompany'>
<img class='headerGraphics' src='Graphics\logo smaller.jpg'><img class='headerGraphics' src='Graphics\Marvelous Header3 small.png'>
</div>
</div>
<div id='contentParent' class='floatClear'>
<div id='content' style="text-align: center;">
<div id='leftPane'>
Left Col
</div>
<div id='rightPane'>
Right Col
</div>
</div>
</div>
<div id='footer'>
Footer
</div>
</div>
</body>
You can do that using flexbox,
here is a simplified version from your code.
body {
margin: 0
}
#main {
display: flex;
flex-direction: column;
height: 100vh
}
#header,
#footer {
background: green;
padding: 10px;
}
#contentParent {
flex: 1;
background: red;
}
#content {
display: flex;
justify-content:center;
align-items:center;
height:100%
}
<div id='main'>
<div id='header'>
<div id='logoCompany'>
Logo Name
</div>
</div>
<div id='contentParent'>
<div id='content'>
<div id='leftPane'>
Left Col
</div>
<div id='rightPane'>
Right Col
</div>
</div>
</div>
<div id='footer'>
Footer
</div>
</div>
Not sure if I understood your question correctly, but if you want to display stretch the image over the whole screen you can use the css tag:
background-size: cover;
You can read more here about the css tag
I'm new to CSS, and am having some problems with my footer. I have really tried to find an answer, but nothing seems to work.
I need to have the footer at the very bottom of the page, but in the same time have a minimum distance to the other content of 150px.
So far I have managed to get the footer at the bottom, but I can't get the minimum distance to work.
<body>
<div class="wrapper">
<div class="header">
<div class="banner">
<h1></h1>
</div>
<div class="navbar">
<ul>
<li><a id="home" class="active" href="home.html">Hjem</a></li>
<li><a id="billeder" href="billeder.html">Billeder</a></li>
<li><a id="video" href="video.html">Video</a></li>
<li><a id="kontakt" href="kontakt.html">Kontakt</a></li>
</ul>
</div>
</div>
<div class="bodybill">
<div class="content">
<p class="welcome">Some text.</p>
</div>
<div class="leftpic">
</div>
<div class="rightpic">
</div>
</div>
<div class="footer">
<footer>Some text</footer>
</div>
</div>
</body>
html,body {
background-image: url("image.png");
height: 100%;
margin: 0;
padding: 0;
top: 0;
}
div.wrapper {
min-height: 100%;
min-width: 100%;
position: relative;
width:100%;
margin-top: 0px;
padding-top: 0px;
margin-left: auto;
margin-right: auto;
}
div.header {
padding: 0px;
top: 0px;
}
div.bodybill {
padding:0px;
height: 600px;
padding-bottom: 100px;
}
div.footer {
position: absolute;
width: 100%;
height: 100px;
background: black;
border-style: solid;
border-width: 1px 0px 1px 0px;
border-color: #141953;
background-image: url("image.png");
bottom: 0;
}
footer {
margin-left: 20px;
margin-top: 30px;
color: white;
font-size: 14px;
It can be done simply, but I noticed that you're doing it the hard way.
You can create a new div and name it .wrap and wrap it to the whole body content, except the .footer
and in your CSS, do this:
.wrap {
min-height: calc(100vh - 150px);
}
Since your footer is inside of your wrapper and your wrapper is set to 100% height. Add
div.wrapper{
display:block;
}
to the wrapper div. Everything else can stay the same. And to your footer div you could change your position property to:
div.footer{
position: relative;
margin-top: 150px;
}
The rest could stay the same. This will position the footer div relative to the wrapper div which it is in. The margin-top pushes all content above the footer div 150 pixels away.
How can i get my two div's to take up all the page together (10% AND 90%) and sit next to each other.
HTML:
<body>
<div class="header" id= "headerxx">
</div>
<div class="mainbody">
</div>
CSS:
body {
background-color: #F0F0F0;
margin-top: 0px;
width: 100%;
margin-left: 0px;
}
.header {
width: 10%;
margin-top: 0px;
float: left;
}
Here you go (jsFiddle)
HTML
<div class="main">
<div class="header" id= "headerxx">
</div>
<div class="mainbody">
</div>
<div class="clear">
</div>
</div>
CSS
body {
background-color: #F0F0F0;
margin-top: 0px;
width: 100%;
margin-left: 0px;
}
.header {
width: 10%;
height: 200px;
margin-top: 0px;
float: left;
background-color: #000000;
}
.mainbody {
width: 90%;
height: 200px;
float: right;
background-color: #666666;
}
.clear {
clear: both;
}
I have put the heights in for demo purposes, so you can see what is going on. In practice, you don't need these.
If yo are targeting the latest browser you can align 2 div next to each-other using display:table and display:table-cell;.. Have a look at DEMO.
In this layout I give display:table to body element in your case you've to give this property to parent element.
CSS is
body{width:100%; display:table;}
.header, .mainbody {
display:table-cell;
height:200px;
border:1px solid gray;
}
.header{width:10%; background:rgba(34%, 63%, 23%, 1);}
.mainbody{width:90%; background:rgba(55%, 67%, 19%, 1);}
<div class="header" id="headerxx">
</div>
<div class="mainbody">
</div>
Try This.
CSS
.container{
position: relative;
min-height: 100%;
}
.leftDiv{
float: left;
min-height: 100%;
background: #f0f0f0;
width: 10%;
}
.rightDiv{
float: left;
background: blue;
color: white;
width:90%;
height: 100%;
}
HTML
<div class="container">
<div class="leftDiv">
<p>This is the left div</p>
</div>
<div class="rightDiv">
<p>This is the Right Div</p>
</div>
Can't understand your coding. The best interpretation I could come up is that you want 2 divs lie next to each other, so I made a parent div .container here, position it to relative so that all its children divs will rely on it for positioning and dimensions, I also give it min height of 100% for demo purposes.
Then the divs that lie next to each other are the .leftDiv and the .rightDiv, each floated left so that the element next to it will take the remaining space of the parent it didn't cover. Also I gave it widths 10% and 90%, and a height of 100% again for demo purposes.
So I'm working on some html/css stuff
I can't seem to get these two floating div's and the footer to be correctly sized inside the parent div.
the content div is positioned absolutely to get header and footer to show respectively.
HTML:
<div id="Content">
<div id="Header">header</div>
<div id="Container">
<div id="leftTable">
<div>left content</div>
</div>
<div id="rightTable">
<div>right content</div>
</div>
</div>
<div id="Footer">
<div>footer</div>
</div>
</div>
CSS:
html, body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
#Content {
padding: 0 15px;
height: 100%;
background-color: honeydew;
position: relative;
height: 100%;
}
#Header {
height: 60px;
background-color: aliceblue;
}
#Footer {
position: absolute;
bottom: 0;
background-color: purple;
height: 70px;
}
#Container {
background-color: green;
position: absolute;
top: 60px;
bottom: 70px;
margin-right: 15px;
}
#Container:after {
clear:both;
}
#leftTable {
float: left;
width: 50%;
height: 100%;
background-color: grey;
}
#rightTable {
float: left;
width: 50%;
background-color: blue;
}
http://jsfiddle.net/4CabB/12/
I was hoping to no position the Container div or footer div on the left and right sides and just have it take up the remaining space.
I'm a bit unclear as to what needs to be achieved, but perhaps this solves your issue: JSFiddle.
Essentially, I just needed to add
width: 100%;
to your container to allow its children to take up the space. Parent containers, when absolutely positioned, must have their widths specified.