Fixed top nav doesn't overlay page content - html

I'm trying to create a top-fixed nav, which is supposed to always be visible and overlay content if needed. However, after several attempts I've got the following result. I'd like to get rid of this "transparency" effect on the navbar.
#import url("https://fonts.googleapis.com/css?family=Montserrat+Alternates:400,800|Poppins");
.nav-title {
font-family: 'Montserrat Alternates', sans-serif;
font-weight: 800;
font-size: 1.5rem;
}
#mobile-nav {
height: 3.8rem;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 1rem;
box-shadow: 0px 1px 10px black;
}
#mobile-nav i {
font-size: 3rem;
}
#content {
margin-top: 4rem;
}
#start {
height: 50vh;
width: 100%;
font-family: 'Poppins', sans-serif;
text-align: center;
}
#start h1 {
position: relative;
top: 25%;
font-size: 2.3rem;
margin: 0 1rem;
}
#info {
height: 100vh;
width: 100%;
font-family: 'Poppins', sans-serif;
margin: 0 auto;
text-align: c;
}
#info p {
margin: 0 50px;
}
#info h2 {
text-align: center;
}
.fixed-top {
position: fixed;
top: 0;
}
<header>
<nav id="mobile-nav" class="fixed-top">
<div class="nav-title">Some logo</div>
<i class="material-icons">menu</i>
</nav>
</header>
<div id="content">
<section id="start">
<h1>This is an<br />awesome header.</h1>
</section>
<section id="info">
<h2>And this is another header.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum condimentum nibh vel eros porttitor semper. Sed sit amet porttitor velit, sed malesuada orci. Nam nec gravida quam. Proin eget tristique quam. Nam posuere massa magna. Aenean congue
sed enim id tempus. Etiam sed est in arcu facilisis auctor sit amet nec eros. Duis cursus molestie quam, quis blandit ex eleifend vitae. Quisque efficitur leo at magna ornare, vitae aliquam ante interdum. Nullam eget consectetur arcu. Suspendisse
sit amet tincidunt dui, sit amet placerat nunc. Sed posuere, lacus quis pellentesque interdum, dui nulla molestie est, vel condimentum enim quam in ex.</p>
So far I've tried z-index and adding margin-top to the content div but this didn't make a trick. What am I doing wrong and how can I fix it? Is there any specific things about position fixed?

You need to give it a background-color if you want it opaque. Also, because it's before the rest of content, when they overlap the rest will be above it. To bring it above, give it z-index: 1;
.fixed-top {
position: fixed;
top: 0;
background-color: white;
z-index: 1
}
Another way of doing it would be to move the scrollbar from body to #content, which would no longer allow them to overlap (in which case you no longer need the above). It also has the advantage of not having the scrollbar rendered on top of the menu:
#content {
margin-top: 4rem;
max-height: calc(100vh - 4rem);
overflow-y: auto;
}
Finally, you should prevent the top bar from exceeding document's width by telling it to include the padding in its total width calculation:
#mobile-nav {
box-sizing: border-box;
}
See it here: https://codepen.io/andrei-gheorghiu/pen/KbbmmG

I added a background color to your nav and set a z-index higher than your content and headers.
#import url("https://fonts.googleapis.com/css?family=Montserrat+Alternates:400,800|Poppins");
.nav-title {
font-family: 'Montserrat Alternates', sans-serif;
font-weight: 800;
font-size: 1.5rem;
}
#mobile-nav {
height: 3.8rem;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 1rem;
box-shadow: 0px 1px 10px black;
background-color:#ffffff;
}
#mobile-nav i {
font-size: 3rem;
}
#content {
margin-top: 4rem;
}
#start {
height: 50vh;
width: 100%;
font-family: 'Poppins', sans-serif;
text-align: center;
}
#start h1 {
position: relative;
top: 25%;
font-size: 2.3rem;
margin: 0 1rem;
z-index:90;
}
#info {
height: 100vh;
width: 100%;
font-family: 'Poppins', sans-serif;
margin: 0 auto;
text-align: c;
}
#info p {
margin: 0 50px;
}
#info h2 {
text-align: center;
}
.fixed-top {
position: fixed;
z-index:100;
top: 0;
}
<header>
<nav id="mobile-nav" class="fixed-top">
<div class="nav-title">Some logo</div>
<i class="material-icons">menu</i>
</nav>
</header>
<div id="content">
<section id="start">
<h1>This is an<br />awesome header.</h1>
</section>
<section id="info">
<h2>And this is another header.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum condimentum nibh vel eros porttitor semper. Sed sit amet porttitor velit, sed malesuada orci. Nam nec gravida quam. Proin eget tristique quam. Nam posuere massa magna. Aenean congue
sed enim id tempus. Etiam sed est in arcu facilisis auctor sit amet nec eros. Duis cursus molestie quam, quis blandit ex eleifend vitae. Quisque efficitur leo at magna ornare, vitae aliquam ante interdum. Nullam eget consectetur arcu. Suspendisse
sit amet tincidunt dui, sit amet placerat nunc. Sed posuere, lacus quis pellentesque interdum, dui nulla molestie est, vel condimentum enim quam in ex.</p>

I think that background-color property is what you're looking for.
You may try to add following lines into #mobile-nav:
background-color: white;
z-index: 100; // or any other huge value

Related

Ensure image, header, paragraph and button remain level, with different length size for header and paragraph

What I am trying to achieve is all images the same level, all headers and paragraphs level no matter what length they are and a button after which as all in the same level... I am also trying to make a 9x9 grid, but as soon as I add more columns they start going next to each other not by the underneath...
.flex-container {
display: flex;
flex-wrap: nowrap;
}
.flex-container .box {
width: 50%;
margin: 10px;
text-align: center;
}
.container {
padding-top: 30px;
height: 300px;
text-align: center;
min-width: 280px;
height: 100%;
margin-left: 100px;
margin-right: 100px;
display: flex;
justify-content: space-between;
}
.box h2 {
text-align: center;
font-family: "Slabo 27px", serif;
font-size: 24px;
font-weight: 700;
text-align: center;
padding-left: 25px;
padding-right: 25px;
}
.box p {
text-align: center;
font-family: "Montserrat", sans-serif;
font-size: 19px;
text-align: center;
padding-left: 25px;
padding-right: 25px;
padding-bottom: 10px;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media screen and (max-width: 800px) {
.column {
text-align: center;
float: left;
width: 50%;
}
}
.button {
border: none;
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.3s;
/* Safari */
transition-duration: 0.3s;
cursor: pointer;
}
.button {
background-color: white;
color: black;
border: 2px solid #008CBA;
text-align: center;
padding-bottom: 20px;
width: 50%;
margin: auto;
align-self: flex-end;
}
.button:hover {
background-color: #008CBA;
color: white;
}
<div class="container">
<div class="flex-container">
<div class="box">
<a href="#">
<img src="http://via.placeholder.com/600x600" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
</a>
<h2>Example Header</h2>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod eget mi at cursus. Nam aliquet dolor eros, in varius diam tincidunt et. Curabitur porta nunc arcu, sed mattis felis interdum ut. </p>
<div>
Learn more
</div>
</div>
<div class="box">
<a href="#">
<img src="http://via.placeholder.com/600x600" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
</a>
<h2>Longer example of a header blah </h2>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod eget mi at cursus. Nam aliquet dolor eros, in varius diam tincidunt et. Curabitur porta nunc arcu, sed mattis felis interdum ut. Curabitur consequat non nunc et tempus. Mauris
porta orci augue, in sagittis eros semper rutrum. Nam in elit mattis, auctor enim a, tempus arcu. In interdum eu lorem sit amet ullamcorper.</p>
<div>
Learn more
</div>
</div>
<div class="box">
<a href="#">
<img src="http://via.placeholder.com/600x600" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
</a>
<h2>another short example </h2>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod eget mi at cursus. Nam aliquet dolor eros, in varius diam tincidunt et. Curabitur porta nunc arcu, sed mattis felis interdum ut. Curabitur consequat non nunc et tempus. Mauris
porta orci augue, in sagittis eros semper rutrum. Nam in elit mattis, auctor enim a, tempus arcu. In interdum eu lorem sit amet ullamcorper. Proin est ipsum, rutrum ac est ut, mollis mollis elit. Curabitur eget dolor gravida, rhoncus arcu eget,
rhoncus ante. Nulla rhoncus in mauris et consequat. </p>
<div>
Learn more
</div>
</div>
</div>
This is currently the best I have, I've got all images and header and text to be the same level but as soon as I have the buttons in level the headers or paragraphs wont be level... Any help on this would be amazing!
If you are ok to set some heights and some overflow: hidden; you could do this:
.flex-container {
display: flex;
flex-wrap: nowrap;
}
.flex-container .box {
width: 50%;
margin: 10px;
text-align: center;
}
.container {
padding-top: 30px;
height: 300px;
text-align: center;
min-width: 280px;
height: 100%;
margin-left: 100px;
margin-right: 100px;
display: flex;
justify-content: space-between;
}
.box h2 {
text-align: center;
font-family: "Slabo 27px", serif;
font-size: 24px;
font-weight: 700;
text-align: center;
padding-left: 25px;
padding-right: 25px;
/* ! */
overflow: hidden;
height: 3.6em;
}
.box p {
text-align: center;
font-family: "Montserrat", sans-serif;
font-size: 19px;
text-align: center;
padding-left: 25px;
padding-right: 25px;
margin-bottom: 40px;
/* ! */
overflow: hidden;
height: 12.6em;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media screen and (max-width: 800px) {
.column {
text-align: center;
float: left;
width: 50%;
}
}
.button {
border: none;
color: white;
padding: 16px 32px;
text-align: center;
text-decoration: none;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.3s;
/* Safari */
transition-duration: 0.3s;
cursor: pointer;
}
.button {
background-color: white;
color: black;
border: 2px solid #008CBA;
text-align: center;
padding-bottom: 20px;
width: 50%;
margin: auto;
align-self: flex-end;
}
.button:hover {
background-color: #008CBA;
color: white;
}
/* ! */
.fade {
position: relative;
height: 3.6em;
}
/* ! */
.fade:after {
content: "";
text-align: right;
position: absolute;
bottom: 0;
right: 0;
width: 70%;
height: 1.2em;
background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 50%);
}
<div class="container">
<div class="flex-container">
<div class="box">
<a href="#">
<img src="http://via.placeholder.com/600x600" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
</a>
<div>
<h2 class="fade">Example Header</h2>
<p class="fade"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod eget mi at cursus. Nam aliquet dolor eros, in varius diam tincidunt et. Curabitur porta nunc arcu, sed mattis felis interdum ut. </p>
</div>
<div>
Learn more
</div>
</div>
<div class="box">
<a href="#">
<img src="http://via.placeholder.com/600x600" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
</a>
<h2 class="fade">Longer example of a header blah blah blah </h2>
<p class="fade"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod eget mi at cursus. Nam aliquet dolor eros, in varius diam tincidunt et. Curabitur porta nunc arcu, sed mattis felis interdum ut. Curabitur consequat non nunc et tempus. Mauris
porta orci augue, in sagittis eros semper rutrum. Nam in elit mattis, auctor enim a, tempus arcu. In interdum eu lorem sit amet ullamcorper.</p>
<div>
Learn more
</div>
</div>
<div class="box">
<a href="#">
<img src="http://via.placeholder.com/600x600" alt="" width="400" height="300" style="max-width:90%;height:auto;" />
</a>
<h2 class="fade">another short example </h2>
<p class="fade"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod eget mi at cursus. Nam aliquet dolor eros, in varius diam tincidunt et. Curabitur porta nunc arcu, sed mattis felis interdum ut. Curabitur consequat non nunc et tempus. Mauris
porta orci augue, in sagittis eros semper rutrum. Nam in elit mattis, auctor enim a, tempus arcu. In interdum eu lorem sit amet ullamcorper. Proin est ipsum, rutrum ac est ut, mollis mollis elit. Curabitur eget dolor gravida, rhoncus arcu eget,
rhoncus ante. Nulla rhoncus in mauris et consequat. </p>
<div>
Learn more
</div>
</div>
</div>
Flow fade thing is from here where you can also find some other approaches to your problem. Hope this helps.

CSS - Background color oversizing / covering paragraph text rather than just h3

I'm trying to set a background color for a h3 which is at the bottom of a paragraph however the color is covering both the heading and the paragraph text when I just want it to cover the h3. Not sure why its oversizing like that rather than just wrapping around the h3.
This is how I've done it -
section.council {
height: 350px;
max-width: 100%;
position: relative;
background-color: #F0F0F0;
}
.council h2 {
text-align: left;
margin-top: 30px;
line-height: 5px;
font-size: 20px;
color: #000000;
}
.council p {
font-size: 10px;
color: black;
float: left;
margin-top: 20px;
margin-right: 50px;
}
.readmore h3 {
color: #FFFFFF;
font-size: 15px;
text-align: center;
background-color: #00BFFF;
}
<div class="row">
<h4>LATEST CASE STUDY</h4>
<div class="six columns">
<h2>Wakefield Council</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel ex nisl. Vestibulum vitae ultricies nisl. Praesent sodales, leo at pellentesque pellentesque, nunc erat dapibus nunc, ut congue libero lorem in orci.
<br> Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor. Suspendisse nec venenatis nisi. Phasellus sodales viverra ante quis efficitur. Pellentesque quis orci mi.
</p>
<div class="readmore">
<h3>READ MORE</h3>
</div>
</div>
</div>
Is your problem just the fact that h3 as a block element by default goes over the whole width …?
Well then just make it inline or inline-block, and move text-align to the parent element to center it:
section.council {
height: 350px;
max-width: 100%;
position: relative;
background-color: #F0F0F0;
}
.council h2 {
text-align: left;
margin-top: 30px;
line-height: 5px;
font-size: 20px;
color: #000000;
}
.council p {
font-size: 10px;
color: black;
float: left;
margin-top: 20px;
margin-right: 50px;
}
.readmore {
text-align:center;
}
.readmore h3 {
display: inline-block;
color: #FFFFFF;
font-size: 15px;
background-color: #00BFFF;
}
<div class="row">
<h4>LATEST CASE STUDY</h4>
<div class="six columns">
<h2>Wakefield Council</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vel ex nisl. Vestibulum vitae ultricies nisl. Praesent sodales, leo at pellentesque pellentesque, nunc erat dapibus nunc, ut congue libero lorem in orci.
<br> Suspendisse potenti. Quisque facilisis mauris in vestibulum tempor. Suspendisse nec venenatis nisi. Phasellus sodales viverra ante quis efficitur. Pellentesque quis orci mi.
</p>
<div class="readmore">
<h3>READ MORE</h3>
</div>
</div>
</div>
If you want it to look more button-y, then add a bit of padding as well.

HTML Webpage Sidebars Acting Up

Help, have been working for hours on this HTML Page. I've been viewing it in Chrome, but when I resize the page I notice that the sidebars I've added cover up everything.
Here is what I wanted to do:
Have a scroll bar when the page is resized (Keeping the page the same)
Have one side bar one side, and to be able to slide over the page to find the other scroll bar. (I dont want the. covering everything up like they are now..)
Here is the code:
#img1 {
width: 400px;
padding-bottom: 25px;
}
#container1 {
text-align: center;
}
#heading-contain {
background-color: LightSeaGreen;
width: 650px;
margin: auto;
border-radius: 7px;
font-family: "adam", arial;
color: white;
}
#heading2 {
border-top: 1px solid white;
}
#heading1 {
position: relative;
top: 15px;
}
#heading2 h3 {
position: relative;
bottom: 6px;
color: DarkSlateGrey;
}
#main-content {
width: 650px;
margin: auto;
margin-top: 30px;
background-color: LightSlateGrey;
border-radius: 8px;
}
#text1 {
padding-bottom: 30px;
padding-top: 20px;
font-family: arial;
color: white;
margin-left: 20px;
margin-right: 20px;
line-height: 200%;
}
#name {
color: DarkSeaGreen;
font-weight: bold;
font-family: "dragon is coming";
font-size: 300%;
}
body {
background-image: url("https://lh4.ggpht.com/X5kjAhye8_5IE9Ws3Z0e05aIAsP_jCSbsh1hja0nNdF8GczkNd0aZQEe7w1V5-2B-9k=h900");
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
}
#footer {
background-color: LightSeaGreen;
color: white;
border: 1px double white;
border-bottom-right-radius: 8px;
border-bottom-left-radius: 8px;
height: 30px;
padding: 5px;
font-family: "adam";
font-weight: bold;
}
#footer p {
margin: 5px;
}
#name:hover {
color: LightCoral;
cursor: default;
}
#line1 {
text-align: center;
}
#paragraph {
text-indent: 50px;
display: inline-block;
}
#sidebar-left {
background-color: LightSeaGreen;
width: 200px;
height: 100%;
display: block;
position: absolute;
left: 0px;
top: 0px;
position: fixed;
font-family: "adam";
color: white;
}
ul {
margin: 0px;
padding: 0px;
}
ul li {
list-style: none;
}
ul li a {
background-color: LightSlateGrey;
color: white;
border-bottom: 1px solid white;
display: block;
width: 180px;
padding: 10px;
text-decoration: none;
}
li:hover {
background-color: DarkSeaGreen;
}
#sidebar-right {
background-color: LightSeaGreen;
width: 200px;
height: 100%;
position: absolute;
right: 0px;
top: 0px;
position: fixed;
font-family: "adam";
color: white;
}
#sidebar-right h4 {
width: 180px;
padding: 10px;
}
#sidebar-right img {
width: 160px;
margin-left: 20px;
margin-right: 20px;
margin-top: 10px;
}
#sidebar-right p {
font-size: 13px;
padding-right: 6px;
padding-left: 6px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML WEBPAGE 2 | Brett Carwile</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="container1">
<!-- Container1 contains all the elements on the page !-->
<div id="heading-contain">
<!-- Heading-container contains everything in the header !-->
<div id="heading1">
<!-- Heading1 is the top of the header which includes the h1 !-->
<h1>HTML Webpage 2</h1>
</div>
<div id="heading2">
<!-- Heading2 is the bottom half of the header including the h3 !-->
<h3>By Brett Carwile</h3>
</div>
</div>
<div id="sidebar-right">
<h4>About the Author</h4>
<img src="DSC00071.jpg">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ullamcorper gravida facilisis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sed dui diam. Nulla facilisi. Donec rhoncus dolor malesuada urna commodo lacinia. Sed vel nisi
venenatis, aliquet nibh at, lobortis lacus. Etiam enim lacus, venenatis a sagittis ac, rhoncus in velit. Pellentesque turpis massa, condimentum eget eleifend non, sit amet justo. Vivamus accumsan iaculis placerat. Quisque blandit diam ut risus
ultrices rutrum. Mauris pretium in augue ut lobortis. Vivamus tempor ac nisl at euismod. Maecenas laoreet a erat a varius. Curabitur consequat nunc vehicula tellus ornare, vitae aliquet sapien varius.
</P>
</div>
<div id="sidebar-left">
<ul>
<li>Link 1
</li>
<li>Link 2
</li>
<li>Link 3
</li>
<li>Link 4
</li>
<li>Link 5
</li>
</ul>
<p>Check out the awesome links above!!</p>
</div>
<div id=main-content>
<!-- This div is the main area below the header (text, img ect...) !-->
<p id="text1">
<!-- This span is to seperate the first line from the rest of the text !-->
<span id="line1"> This is an HTML webpage by <span id="name">Brett Carwile</span>.</span>
<br>
<!-- This span is so that we can indent the text !-->
<span id="paragraph">This is a text sample. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id quam nulla. Nam sollicitudin porta ligula, sit amet pharetra elit tincidunt sit amet. Suspendisse rhoncus, elit at consectetur sagittis, nisi eros molestie urna, et cursus elit sapien quis ante. Sed sit amet pulvinar neque. Pellentesque eget lorem ac lorem sodales rutrum. Nulla erat nisl, consequat non ante vitae, porttitor convallis magna. Duis pulvinar ornare nisi nec varius. Mauris tempus nisi non viverra vulputate. Interdum et malesuada fames ac ante ipsum primis in faucibus. Maecenas vestibulum viverra erat eu rhoncus.
Cras nec vulputate leo. Donec nunc mauris, varius id ligula eu, tincidunt euismod lorem. Praesent pharetra, ipsum et congue egestas, sapien augue feugiat lacus, ac tincidunt augue leo ut tortor. Mauris efficitur urna ut turpis ornare, eu consectetur lacus dapibus. Curabitur sit amet justo blandit est fermentum volutpat. Sed in gravida nunc. Integer sit amet risus in justo porttitor cursus. Mauris tortor purus, viverra a lacus et, suscipit molestie tortor. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; </span>
</p>
<img src="DSC00071.jpg" id="img1">
<div id="footer">
<p>Thank you for viewing!!! © Brett Carwile 2016</p>
</div>
</div>
</div>
</body>
</html>
You can try the HTML/CSS and resize the window to see what I mean.
Adding min-width to the body element and removing the position fixed for the sidebar-left and sidebar-right will make the trick. Please see below the modified css rules.
body {
min-width: 1200px; //Modify depending on your requirements
background-image: url("https://lh4.ggpht.com/X5kjAhye8_5IE9Ws3Z0e05aIAsP_jCSbsh1hja0nNdF8GczkNd0aZQEe7w1V5-2B-9k=h900");
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
}
#sidebar-left {
background-color: LightSeaGreen;
width: 200px;
height: 100%;
display: block;
position: absolute;
left: 0px;
top: 0px;
font-family: "adam";
color: white;
}
#sidebar-right {
background-color: LightSeaGreen;
width: 200px;
height: 100%;
position: absolute;
right: 0px;
top: 0px;
font-family: "adam";
color: white;
}
I hope it helps.

(HTML or CSS) White background color is going lower than my last part of code

Hum, hey ! I got something that I tried to fix for almost four hours, but I couldn't find it. The worst thing is that i'm almost sure that it is a stupid thing to remove or to replace, but I don't know. So Is there is a way to make my background stopping on the last image or if it's a problem in my code, is there is a way to fix it? I'm placing the code. Thanks in advance ! (my code may be horrible, sorry if that's the case ^^)
<!DOCTYPE html>
<html lang="en-fr">
<head>
<meta charset="UTF-8">
<title>RealTea</title>
<style>
body {
background-color: #FFFFFF;
background-size: cover;
background-position: center;
width: 1030px;
height: auto;
}
#Menu {
background-image: url('http://image.noelshack.com/fichiers/2015/17/1429647024-liens.png');
opacity: 0.9;
background-repeat: no-repeat;
width: 1341px;
position: relative;
bottom: auto;
}
nav {
font-size: 25px;
font-family: Verdana;
color: #FFFFFF;
text-align: center;
}
a {
color: #FFFFFF;
font-family: Verdana;
left: -80px;
}
a:hover {
color: #FFFFFF;
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: underline;
}
IMG.displayed {
position: relative;
left: auto;
width: 1340px;
}
p.newsletter {
font-family: Homizio;
font-size: 29px;
color: #339900;
position: relative;
text-align: center;
left: 520px;
bottom: -20px;
width: 314px;
height: 385px;
}
p.Communaute {
font-family: Homizio;
font-size: 29px;
color: #339900;
position: relative;
text-align: center;
left: 140px;
bottom: 393px;
width: 314px;
height: 385px;
}
p.inscription {
font-family: Homizio;
font-size: 29px;
color: #339900;
position: relative;
text-align: center;
left: 908px;
bottom: 808px;
width: 314px;
height: 385px;
}
img.Bambou {
position: relative;
bottom: 680px;
margin-left: auto;
margin-right: auto;
}
img.nouveau {
position: relative;
bottom: 1090px;
left: -600px;
opacity: 0.6;
}
p.actu {
font-family: Homizio;
font-weight: bold;
font-size: 28.5px;
color: #000000;
opacity: 0.6;
position: relative;
text-align: left;
bottom: 1100px;
right: -15px;
width: 661px;
height: 377px;
}
p.infos {
font-family: Homizio;
font-weight: bold;
font-size: 28.5px;
color: #339900;
position: relative;
bottom: 1600px;
left: 120px;
text-align: right;
}
p.plusinfos {
font-family: Homizio;
font-size: 29px;
color: #339900;
position: relative;
text-align: left;
right: -780px;
bottom: 1620px;
width: 559px;
height: 359px;
}
img.newlet {
width: 399px;
height: 68px;
position: relative;
bottom: 1750px;
right: -860px;
}
p.newletter {
width: 347px;
font-size: 24px;
font-family: Homizio;
height: 32px;
color: #000000;
position: relative;
bottom: 1821px;
left: 780px;
text-align: right;
}
img.images {
position: relative;
left: 150px;
right: 150px;
bottom: -50px;
}
</style>
</head>
<body>
<nav id="Menu">
Accueil
Forum
Contact
</nav>
<a href="file:///C:/Users/Ewan/Desktop/Travail%20Real%20Tea/Site%20entier.html#">
<img class="displayed" src="http://image.noelshack.com/fichiers/2015/17/1429658354-papierheaderfini.png" alt="jfl">
</a>
<div id="milieu">
<img class="images" src="http://image.noelshack.com/fichiers/2015/17/1429702366-thes.png" alt="tea" width="1050">
<p> </p>
<img class="images" src="http://image.noelshack.com/fichiers/2015/17/1429703603-news.png" alt="selection" width="1050">
<p class="newsletter">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi at libero in magna commodo sodales. Maecenas diam nisl, elementum ut quam nec, pharetra auctor neque. Suspendisse potenti. Mauris imperdiet purus vitae pulvinar malesuada. Aliquam sit amet ligula sit amet dui aliquam lobortis. Morbi pretium nisl non risus fringilla fringilla. Proin ac lobortis mauris.</p>
<p class="Communaute">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi at libero in magna commodo sodales. Maecenas diam nisl, elementum ut quam nec, pharetra auctor neque. Suspendisse potenti. Mauris imperdiet purus vitae pulvinar malesuada. Aliquam sit amet ligula sit amet dui aliquam lobortis. Morbi pretium nisl non risus fringilla fringilla. Proin ac lobortis mauris.</p>
<p class="inscription">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi at libero in magna commodo sodales. Maecenas diam nisl, elementum ut quam nec, pharetra auctor neque. Suspendisse potenti. Mauris imperdiet purus vitae pulvinar malesuada. Aliquam sit amet ligula sit amet dui aliquam lobortis. Morbi pretium nisl non risus fringilla fringilla. Proin ac lobortis mauris.</p>
<img class="Bambou" src="http://image.noelshack.com/fichiers/2015/17/1429706567-bambou.png" alt="lol">
<img class="nouveau" src="http://image.noelshack.com/fichiers/2015/17/1429707724-nouveau.png" alt="nouveautés">
<p class="actu">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur egestas rhoncus auctor. In sed porta nisl, sit amet vestibulum massa. Etiam vehicula, magna et elementum faucibus, leo nulla bibendum eros, nec interdum magna nibh et ipsum. Duis fermentum, augue varius efficitur tincidunt, lacus elit egestas ex, ultrices hendrerit diam velit quis elit. Integer a sem in tortor eleifend lobortis. Nam mauris libero, varius eget dignissim eu, tempor id elit. In justo elit, molestie eu augue ut, pharetra interdum ipsum. Aliquam tincidunt euismod sem id euismod. Donec dui dolor,</p>
<p class="infos"> Plus d'infos sur nous :</p>
<p class="plusinfos">Pellentesque cursus convallis risus, vitae venenatis nibh tristique at. Maecenas imperdiet varius urna et consectetur. Quisque viverra dolor arcu, eu viverra arcu aliquam ut. Nullam suscipit mi quis erat gravida aliquet. Aenean et rutrum leo. Nulla facilisi. Sed posuere.</p>
<img class="newlet" src="http://image.noelshack.com/fichiers/2015/17/1429709917-newsletter.png" alt="newlet">
<p class="newletter">Adresse mail :</p>
</div>
</body>
</html>
Your issue is with how all your elements are being positioned. For example the paragraph with class actu. It has a position: relative:
p.actu {
font-family: Homizio;
font-weight: bold;
font-size: 28.5px;
color: #000000;
opacity: 0.6;
position: relative; /* Issue */
text-align: left;
bottom: 1100px; /* Issue */
right: -15px; /* Issue */
width: 661px;
height: 377px;
}
Which actually means the element is still position "statically" on the page but you used bottom: 1100px and right: -15px to make it look like its visually not there. The browser will still recognize that the element is there along with all the element you visually moved. So if you look at the wrapper with id milieu its actual height is 3046px accounting for all the elements that's there just visually not.
The solution is as simple as removing all the position: relative, bottom, right, left, and top. Of course this will make your site look nothing like you intended. You need better practice on structuring your site.
It looks like you're using position: relative; to do things like placing images (using <img> tags) as backgrounds to some paragraphs of text. Trying to do things like that will just introduce problems.
You should use the built in functionality of HTML and CSS. A better way to do the background thing is to use the background CSS attribute on the <p> tag (or on a container element) and to avoid position: relative; completely.
For instance:
.my-text {
background: #ddd url('img/background.jpg') no-repeat;
padding: 10px;
}
<div class='my-text'>
<p>Lorem ipsum... some stuff...</p>
</div>
The real problem here is that there is no layout design on this webpage. The positions of the paragraphs are just hacked on there. I suggest going through some quick tutorials on HTML and CSS layouts. (Here is an example of one.)

CSS center site with floated elements and show full container background-color

I have simple site, with the classic elements: Container, Header, Content and Footer. The container has a background-color, which covers the whole content of the site (including header, content and footer). For some reason this won't work with floated elements within the container.
I have found a solution at StackOverflow, but it doesn't feel right. Solution is to set { display: table; } onto the container id.
The page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<style>
body
{
background-color: #999;
font-family: Tahoma;
font-size: 12px;
font-style:normal;
font-variant:normal;
font-weight:normal;
margin: 0px;
padding: 0px;
}
h1
{
color: green;
font-family:Tahoma;
font-size: 26px;
font-weight: bold;
margin: 5px 0;
text-indent: 10px;
width: 100%;
}
#container
{
background: #FFF;
margin: 0 auto;
width: 950px;
position: relative;
}
#header
{
position: relative;
height: 100px;
width: 950px;
}
#content, #content-ext
{
float: left;
margin: 0;
width: 950px;
}
#nav
{
float: left;
padding: 10px 10px 10px 0;
width: 200px;
}
ul#menu
{
cursor: pointer;
display: block;
list-style: none outside none;
margin: 0 auto;
padding: 0;
text-align: left;
width: 200px;
}
ul#menu li
{
margin: 0;
padding: 0;
}
ul#menu li a
{
color: #111;
display: inline-block;
height: 50px;
font-size: 18px;
line-height: 60px;
margin: 0 auto;
padding: 0 0 0 10px;
text-decoration: none;
width: 100%;
}
#mainImg
{
background: #111;
height: 150px;
float: right;
margin: 0 0 20px 0;
width: 710px;
}
#main-content
{
float: right;
width: 710px;
}
#extra
{
float: left;
width: 500px;
}
#contact
{
float: left;
width: 450px;
}
#footer
{
color:#999;
height:20px;
width:950px;
}
</style>
</head>
<body>
<div id="container">
<div id="header">
<h1>test</h1>
</div>
<div id="content">
<div id="nav">
<h1>Menu</h1>
<ul id="menu">
<li>Home</li>
<li>Contact</li>
</ul>
</div>
<div id="mainImg"></div>
<div id="main-content">
<h1>Welkom</h1>
<p><strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sed arcu arcu, a interdum metus. Aenean vel libero nulla. Nulla facilisi. Maecenas malesuada libero a ante vulputate vestibulum. Cras id neque vitae lectus luctus tempor non non risus. Morbi aliquam porttitor facilisis. Sed pulvinar erat sit amet est auctor tincidunt. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eget arcu lorem, non accumsan ipsum. Donec venenatis adipiscing massa, sed molestie augue ullamcorper et.</strong>
<br/><br/>
Morbi id eros vitae risus tristique bibendum. Quisque nec metus sit amet nunc tincidunt vehicula sit amet non nibh. Nullam risus orci, porttitor ut malesuada vel, volutpat eget sapien. Proin tempus nunc sit amet ligula viverra hendrerit. Donec tempus tristique risus. Fusce at semper est. Etiam ligula est, varius ut tempus at, laoreet bibendum eros. In hac habitasse platea dictumst.</p>
</div>
</div>
<div id="content-ext">
<div id="extra">
<h1>Extra</h1>
<p>Quisque nec metus sit amet nunc tincidunt vehicula sit amet non nibh. Nullam risus orci, porttitor ut malesuada vel..</p>
</div>
<div id="contact">
<h1>Contact</h1>
<p>Quisque nec metus sit amet nunc tincidunt vehicula sit amet non nibh. Nullam risus orci, porttitor ut malesuada vel..</p>
</div>
</div>
<div id="footer"></div>
</div>
</body>
</html>
Does any has a decent solution for using floated elements within a container? And showing the container as overall background?
Well, there is two classic solutions:
Set "overflow: hidden;" to #container. It will clear floats but have drawback — if you have elements with "position: absolute;" inside container that must be positioned partially outside it, they will be cut by overflow.
Use clearfix hack on #container: http://www.webtoolkit.info/css-clearfix.html it will fix it for you and don't have this drawbacks but is more complex.
Not sure is it better then "display: table;" or not, through.
Leave Display:table, it's not a good solution for a simple problem.
You are starting with a simple layout, and it's a good practice to start with a clean and tested layout.
My favorite resources are:
Little boxes
Free-css
code sucks
good luck