I have a footer at the bottom of my pages, a box ad at the top of that footer, and a form. These 3 elements are spaced out appealingly (only on my screen size) through position: absolute. Whenever I change my browser size, I've made it so that the footer stays away from my ad and doesn't overlap. My form never overlaps with my ad when resized and it is perfect for all screen sizes. On the other hand, my footer overlaps my ad on different screen sizes, and I don't want to spend time on all my pages adding media queries to fix this. If the screen size is small, the footer will either overlap or be way down at the bottom. Also, whenever a user opens a page with a screen width of greater than 500, the ad becomes a horizontal ad,leaving empty space and making the website unappealing at the bottom. This is an example of my css code:
#footer{
position: absolute;
left: 0px;
right: -2px;
bottom: -300px;
margin-bottom: -400px;
background-color: black;
width: 100%;
height: 200px;
}
Media query:
#media screen and (max-width: 1050px)
{
#footer{
margin-bottom: -500px;
}
}
I also have another footer (mobFooter) that comes out and hides the original footer. This footer is for mobile devices. I am doing the same thing with it, with media queries and it's not working out. How do I make it so that the footers are always at the bottom and have a certain amount of space between them and the ad? Also, if the ad becomes a horizontal ad (box to horizontal), how do I make the footer take up that unused space?
HTML code:
<div id="ad2">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- YC ads -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-4549632347845332"
data-ad-slot="4159114047"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<div id="footer">
<div id="mobFooter">
<p>Home</p>
<hr>
<p>Normal Submit</p>
<hr>
<p>Premium Submit</p>
<hr>
<p>Advertising | Contact us</p>
<hr>
<p>Terms | Privacy</p>
</div>
<div id="social">
<ul>
<li><img src="/submit/assets/facebook.png"/></li>
<li><img src="/submit/assets/twitter.png"/></li>
<li><img src="/submit/assets/youtube.png"/></li>
</ul>
</div>
<img src="/submit/assets/logo.png"/>
<ul>
<li>Home</li>
<li>Normal Questions</li>
<li>Premium Questions</li>
<li>Advertising</li>
</ul>
<div id="policies">
<ul>
<li>Terms of Use</li>
<li>Privacy</li>
<br>
<li id="net">Contact us</li>
</ul>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/submit/validation.js"></script>
I've included the HTML code where my ad is and where my footer, and mobFooter is. Note: mobFooter is hidden until screen size reaches 500px.
<div id="ad2">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- YC ads -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-4549632347845332"
data-ad-slot="4159114047"
data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<div id="footer">
<div id="mobFooter">
<p>Home</p>
<hr>
<p>Normal Submit</p>
<hr>
<p>Premium Submit</p>
<hr>
<p>Advertising | Contact us</p>
<hr>
<p>Terms | Privacy</p>
</div>
<div id="social">
<ul>
<li><img src="/submit/assets/facebook.png"/></li>
<li><img src="/submit/assets/twitter.png"/></li>
<li><img src="/submit/assets/youtube.png"/></li>
</ul>
</div>
<img src="/submit/assets/logo.png"/>
<ul>
<li>Home</li>
<li>Normal Questions</li>
<li>Premium Questions</li>
<li>Advertising</li>
</ul>
<div id="policies">
<ul>
<li>Terms of Use</li>
<li>Privacy</li>
<br>
<li id="net">Contact us</li>
</ul>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/submit/validation.js"></script>
$(document).ready(function(){
var footerHeight=$("#footer").height();
$("body").css("padding-bottom",footerHeight);
});
$(window).resize(function(){
var footerHeight=$("#footer").height();
$("body").css("padding-bottom",footerHeight);
});
body{position: relative;}
#footer{
position: absolute;
left: 0px;
right: -2px;
bottom: 0;
background-color: black;
width: 100%;
}
Refer Fiddle
Just used the jquery to identify the height of the footer and used padding-bottom for the body
Related
I have a web page with a navbar and map div. Everything is great but there is a scroll bar on the page and you must scroll to see the full map. I would like the full map div to show up on the screen without any scrolling. How do I accomplish this? Thank you
HTML:
<nav class="default" role="navigation">
<div class="nav-wrapper">
NTN Trails
<a href="#" data-activates="mobile-demo" class="button-collapse show-
on-large"><i class="material-icons">menu</i></a>
<ul class="right hide-on-med-and-down">
</ul>
<ul class="side-nav" id="mobile-demo">
<li>Login</li>
<li>Sign up</li>
</ul>
</div>
</nav>
<script>
$('.button-collapse').sideNav({
menuWidth: 240, // Default is 240
edge: 'left', // Choose the horizontal origin
closeOnClick: true // Closes side-nav on <a> clicks, useful for Angular/Meteor
}
);
</script>
<!--put your initial page content here-->
<div id="map"></div>
CSS:
html, body, #map {
height: 100%;
width: 100%;
}
#media only screen and (min-width: 993px){
nav a.button-collapse {
display: block;
}
}
Im trying to create a little nav that takes me to certain divs on click. It does that, but at the moment it just snaps down to the div. Instead i want a smooth transition down just like it says it should in the documentation.
Also, as i scroll down to the certain divs i want the neccessary nav li's to be highlighted. But when i inspect element on them they dont highlight as i scroll down the page at the moment.. It's definetely picking up the css cdn but the js one im not so sure.
Head (Im using a cdn)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/foundation/6.2.4-rc2/foundation.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/foundation/6.2.4-rc2/foundation.min.css">
<section id="div1_wrapper" data-magellan-target="div1_wrapper">
<div class="leftHeaders" data-sticky-container>
<ul class="sticky" data-sticky data-magellan>
<li>4th page</li>
<li>3rd page</li>
<li>2nd page</li>
<li>1st page</li>
</ul>
</div>
</section>
<section id="div2_wrapper" data-magellan-target="div2_wrapper">
</section>
<section id="div3_wrapper" data-magellan-target="div3_wrapper">
</section>
<section id="div4_wrapper" data-magellan-target="div4_wrapper">
</section>
$(document).foundation();
li {
list-style: none outside;
}
#div2_wrapper,
#div3_wrapper,
#div4_wrapper {
height:100%;
border:1px solid blue;
}
.sticky ul li {
padding: 5px;
}
.active {
border: 1px solid red;
padding: 10px
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/foundation/6.2.4-rc2/foundation.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/foundation/6.2.4-rc2/foundation.min.css">
<section id="div1_wrapper" data-magellan-target="div1_wrapper">
<div class="leftHeaders" data-sticky-container>
<div class="sticky" data-sticky-on="small" data-sticky data-margin-top="0" data-anchor="content">
<ul data-magellan>
<li>4th page</li>
<li>3rd page</li>
<li>2nd page</li>
<li>1st page</li>
</ul>
</div>
</div>
</section>
<section id="div2_wrapper" data-magellan-target="div2_wrapper">
</section>
<section id="div3_wrapper" data-magellan-target="div3_wrapper">
</section>
<section id="div4_wrapper" data-magellan-target="div4_wrapper">
</section>
I'm writing some html and css to create a webpage. On the left of the page is a nav section. At the top is a header, below which is a 'main' section containing text in various sections, and below that is a footer.
I have managed to get the header and footer to remain fixed as desired and also get the main section to scroll between the header and footer. The links in the nav are supposed to let the user jump to a section of main as required. However, when clicking on introduction, the introduction section gets positioned at the very top of the page (hidden under the header) where as I would like it to jump to its position just below the header. I've tried various combinations of setting top and position:absolute in main but without success. Can anybody help?
The html and css are below:
index.html:
<!DOCTYPE html>
<html lang="en" >
<head>
<meta http-equiv="Content-type" content="text/html;charset=utf-8" />
<title>John Doe</title>
<link type="text/css" rel="stylesheet" href="homepage.css">
<style type="text/css">
</style>
</head>
<body>
<header id="top">
<h1>
<dl>
<dt>
John Doe
</dt>
<dd>
<img src="logo.jpg" alt="Logo" >
</dd>
</dl>
</h1>
</header>
<nav class="navlist">
<ul class="menuitem">
<li>Introduction</li>
<li>Previous Experience</li>
<li>Skills</li>
<li>Courses Taken</li>
<li>Courses Being Taken</li>
<li>Useful Links</li>
<li>Contact</li>
<img src="selfie.jpg" alt="Selfie" >
</ul>
</nav>
<div id="main">
<h2><a id="introduction">Introduction</a></h2>
<p>Welcome to my home page! This page tells you a little bit about myself.</p>
<p>Blah blah blah</p>
<h2><a id="prevExp">Previous Experience</a></h2>
<p>I have worked at
Prodrive,
Lotus Engineering and
Ricardo.
</p>
<p>At Prodrive I did some stuff.</p>
<p>At Lotus I did some stuff.</p>
<p>At Ricardo I did some stuff.</p>
<h2><a id="skills">Skills</a></h2>
<ol>
<li>Awesomeness</li>
<li>Mathematics</li>
<li>Problem Solving</li>
<li>CSS?</li>
</ol>
<h2><a id="courses_taken">Courses taken</a></h2>
<ul>
<li>BEng Degree</li>
<li>Games Programming</li>
<li>Java</li>
<li>Android Programming</li>
</ul>
<!-- Created nested list to show current course and its modules -->
<h2><a id="courses_being_taken">Courses being taken</a></h2>
<ul>
<li>MSc Degree
<ul>
<li><h3>Modules</h3></li>
<li>Apps</li>
<li>Research</li>
<li>Databases</li>
<li>Internet</li>
</ul>
</li>
</ul>
<h2><a id="useful_links">Useful Links</a></h2>
<ul>
<li>
<a href="http://www.w3schools.com/html/html5_intro.asp" >HTML5 Introduction from w3schools</a>
</li>
</ul>
<h2><a id="contact">Contact</a></h2>
<ul>
<li>Address: xxxx</li>
<li>Telephone: xxxx</li>
<li>Email: <a href="mailto:xxxx#uea.ac.uk" >xxxx</a></li>
</ul>
</div>
<footer>
<!-- Horizontal rule and update comment -->
<hr />
<p>Page last updated 30/09/2016 by Stephen Whiddett</p>
</footer>
</body>
</html>
homepage.css:
body {margin:0; padding:0;}
header {border: 0px solid white;}
nav {border: 2px ;}
footer {border: 2px ;}
div#main {border: 2px ;}
h1 {font-family:Helvetica,Arial,sans-serif;
font-size:x-large;
color:blue;
font-style: italic;}
h2 {font-family:Helvetica,Arial,sans-serif;
font-size:medium;
color:#0088FF;
font-style: italic;}
header{ width: 100%;
height: 12vh;
position: fixed;
top: 0;
background: #AAAAAA;
}
#main {
left:6em;
width: 80%;
margin: 13vh 0 6vh 6em;
}
footer{ position: fixed;
width:100%;
height:6vh;
bottom:0;
text-align:center;
background: white;}
p { font-family:Helvetica,Arial;
font-size:x-small;}
a {background-color:yellow}
header a {background-color:inherit}
nav img {max-width:100%;}
ul.menuitem {font-size:small;
margin:0;
padding:1em;}
nav.navlist {width:6em;
position: fixed;
top:12%;
bottom:94%;}
header dt {float:left;}
header dd {float:right;}
header dl {padding:1%;}
header dt {
position: absolute;
top: 6vh;
transform: translateY(-50%);
}
It may be necessary for you to reduce the window size of your browser in order to see the issue I've described to ensure that main cannot fit on the screen all at once.
In my test page, at the bottom, there is a large white gap between the footer and the body, I can't figure out why.
Test page
HTML:
<div id="content">
<article>
<div class="social">
<!--Widget code-->
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!--End Widget code-->
<!--FACEBOOK BUTTON
<div class="fb-like" data-layout="button_count" data-action="like" data-show-faces="true" data-share="true"></div> -->
<!--End FACEBOOK BUTTON-->
<div class="sslbreadcrumbs">
<!--first level-->
You are here: Cancer Fighters homepage / Sweat
<!--second level-->
<!--third level-->
</div>
</div>
<div id="content-area">
<!-- Content Placeholder -->
</div>
<div>
[[S63:3]]
<!--Button will only load on Homepage, this is NOT using Luminate Conditional code, see hmpgonly.js -->
<div class="button-container" id="hmpgonly"> Start a Fundraiser
</div>
</div>
<!-- //Content Placeholder -->
</div>
</div>
</article>
</div>
<!--================================================================
FOOTER
==============================================================-->
<footer>
<div id="footer-bottom">
<div class="footer-cell-container">
<div id="footer-cell-one" class="footer-cell">
<h2>Be a Cancer Fighter</h2>
<ul>
[[S51:GEN_ON_Reus_CancerFighter_IFE_Footer]]
<br>
</ul>
</div>
<div id="footer-cell-two" class="footer-cell">
<h2>About the Program</h2>
<ul>
<li>About the Program</li>
<li>About the Society</li>
<li>Where your money goes</li>
<li>FAQs</li
</ul>
</div>
<div id="footer-cell-three" class="footer-cell">
<h2>Get Started</h2>
<ul>
<li>Create a fundraiser</li>
<li>Join a fundraiser</li>
<li>Participate as an<br />individal</li>
<li>Pledge a participant<br />or fundraiser</li>
<li>Donate now</li>
</ul>
</div>
<div id="footer-cell-four" class="footer-cell">
<h2>Canadian Cancer Society</h2>
<ul>
<li><a title="What we do" href="http://www.cancer.ca/en/?region=on"target="_blank">What we do</a></li>
<li><a title="Privacy policy" href="http://www.cancer.ca/en/about-our-site/privacy-policy/?region=on"target="_blank">Privacy policy</a></li>
<br />
<br />
</ul>
</div>
<div id="footer-cell-five" class="footer-cell">
<br>
<ul>
<li>Copyright [[S9:pattern:yyyy]] Canadian Cancer Society </li>
<li>Charitable Registration no. 118829803 RR00001</li>
<br />
</ul>
</div>
</div>
</div>
</footer>
the CMS conditional S tag you'll see there [[S63:3]] it inserts the body of text and such that you see on the test page.
The css for div id=content:
#content {
width: 100%;
max-width: 970px;
margin: 0 auto 122px auto;
overflow: auto;
overflow-y: hidden;
}
When I inspect the page it shows me that content is 970 x 1802, I don't understand where 1802 is being pulled from?
Any suggestion is greatly appreciated! thank you for your time.
Open your dev tools and look at .button-container
Remove the min-height and margin-top rules and you will see that space disappear.
Granted, now your button is not positioned properly. You may want to rethink the layout of your article body, and as Mr Lister mentioned, not set the position of the final element as relative since it is still taking up space even though it is visually in a separate place.
at first your div #content has a margin-bottom setted.
try with this code:
#content {
margin-bottom: 0
}
at second I think you have some javascript that resize some div.
try to disable some script in your test page (or provide a working plunker)
Change the margin on #content to -100px;
#content {
width: 100%;
max-width: 970px;
margin: 0 auto -100px auto;
overflow: auto;
overflow-y: hidden;
}
I made a footer with this following HTML:
<nav class="navbar navbar-inverse navbar-bottom">
<div class="container">
<p class="navbar-text pull-left">Copyright © OLShop.com 2016</p>
<ul class="nav navbar-nav navbar-right">
<li>About Us</li>
<li>Twitter</li>
<li>Facebook</li>
<li>Instagram</li>
</ul>
</div>
</nav>
Everything worked perfectly when I set it to fixed. But when I set footer to be not fixed, it wasn't located at the bottom of the page (floating) and had border radius. How to set it to the bottom of the page (not fixed) and remove the border-radius?
Any guidance will be very much appreciated.
You need to position the nav at the bottom of the page with CSS positioning. Refer to my earlier post on positioning.
Also you should override the media query from bootstrap to remove border-radius.
I have attached a code snippet but it will not work in this form.
You should copy the HTML code and a create a new external stylesheet using the CSS styles in the snippet and then add it after bootstrap.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="stylesheet.css"/>
footer {
position:absolute;
left:0;
bottom:0;
width:100%;
}
#media (min-width: 768px) {
.navbar {
border-radius: 0;
}
}
.navbar{
margin-bottom:0;
bottom:0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<footer>
<nav class="navbar navbar-inverse navbar-bottom">
<div class="container">
<p class="navbar-text pull-left">Copyright © OLShop.com 2016</p>
<ul class="nav navbar-nav navbar-right">
<li>About Us</li>
<li>Twitter</li>
<li>Facebook</li>
<li>Instagram</li>
</ul>
</div>
</nav>
</footer>
It's simple. Just try this:
<nav>
<div class="container">
<p class="navbar-text">Copyright © OLShop.com 2016</p>
<ul class="text-center inline-me">
<li>About Us</li>
<li>Twitter</li>
<li>Facebook</li>
<li>Instagram</li>
</ul>
</div>
</nav>
in Custom CSS, add this:
ul.inline-me li a {display:inline; padding-right:4px;}
Hope that helps.
How to put it down to the bottom of page (not fixed)?
You can just put it's html in the right place (probably inside a footer tag).
JsFiddle : http://jsfiddle.net/nnndfcad/1/
Or you can use an absolute positioning like #santon's answer explained.
But I highly disapprove this type of approach.
How to remove the border-radius?
According to your code, a simple
.navbar-inverse {
border-radius: 0px;
}
Should solve it.