Extra space under page footer - html

I'm remaking an article I found on The Economist (here) and I ran into an issue with my footer where it showed a very thin line of white space under the footer.
I actually resolved the issue but I'm not sure why what I did worked.. Here's the pen for it (here), and here's the footer and HTML code.
/****************
Footer
****************/
/*
The footer is organized into three rows with columns in each row.
*/
footer {
height: 400px;
border-top: 5px red solid;
margin-top: 50px;
background-color: #c1c1c1;
color: white;
background-color: #161616;
}
.footer-container {
width: 80%;
height: 100%;
margin: 0 auto;
}
footer ul {
list-style: none;
}
a:link {
text-decoration: none;
color: #b6b6b6;
font-weight: bold;
font-size: .9em;
}
a:link:hover {
color: white;
}
.footer-link {
padding: 10px 0;
color: #b6b6b6;
font-weight: bold;
}
.footer-link:hover {
color: white;
cursor: pointer;
}
.row-1 {
display: flex;
height: 50%;
}
.row-1-col-1 {
width: 10%;
text-align: left;
display: flex;
flex-direction: column;
justify-content: center;
}
.row-1-col-1 ul {
display: flex;
flex-direction: column;
justify-content: space-around;
margin: 0;
padding: 0 15px;
height: 70%;
}
.row-1-col-2 {
width: 60%;
display: flex;
flex-direction: column;
justify-content: center;
}
/* "Keep updated */
.row-1-col-2 div p {
font-weight: bold;
color: #7a7a7a;
}
.row-1-col-2 > div {
height: 70%;
margin-left: 30px;
padding-left: 30px;
border-left: 1px #7a7a7a solid;
border-right: 1px #7a7a7a solid;
}
.row-1-col-2 ul {
padding: 0;
display: flex;
}
.footer-s-media-icon {
width: 25px;
padding: 0 15px;
filter: grayscale(100%);
}
.row-1-col-3 {
display: flex;
flex-direction: column;
justify-content: center;
width: 30%;
}
.row-1-col-3 ul {
height: 70%;
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.row-2 {
height: 40%;
border-top: 1px #7a7a7a solid;
border-bottom: 1px #7a7a7a solid;
}
.row-2-col-1 {
height: 100%;
}
.row-2-col-1 > div {
margin: 0 auto;
width: 35%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
}
.row-2-col-1 > div p {
margin: 0;
text-align: center;
}
/* Published since Sept...to take part in... */
.row-2-col-1 > div p:first-child {
font-weight: bold;
}
/* "a severe contest between intellegence... */
.row-2-col-1 > div p:nth-child(2) {
font-style: italic;
}
.row-3 {
height: 9%;
width: 100%;
display: flex;
}
.row-3-col-1 {
display: flex;
width: 100%;
}
.row-3-col-1 ul {
display: flex;
padding: 0;
margin-bottom: 0;
}
.row-3-col-1 li {
padding: 0 8px;
font-size: .8em;
}
.row-3-col-1 p {
margin-bottom: 0;
margin-top 0;
margin-left: auto;
font-size: .8em;
}
<footer>
<div class="footer-container">
<div class="row-1">
<div class="row-1-col-1">
<ul>
<li class="footer-link">Subscribe</li>
<li class="footer-link">Contact us</li>
<li class="footer-link">Help</li>
</ul>
</div>
<div class="row-1-col-2">
<div>
<p>Keep updated</p>
<ul>
<li><img src="https://www.celestionplus.com/wp-content/themes/celestion-impulse-response-2017/img/icon-facebook.png" class="footer-s-media-icon"></li>
<li><img src="http://www.vonmaur.com/Images/Social/twitter-logo-blue.png" class="footer-s-media-icon"></li>
<li><img src="https://www.carpetone.com/~/media/CarpetOne/Modules/Global/Footer/SocialLinks/google.png?h=30&w=30&la=en" class="footer-s-media-icon"></li>
<li><img src="http://www.shoetastic.ie/skin/frontend/default/theme054/images/linkedin-logo.png" class="footer-s-media-icon"></li>
<li><img src="https://2.bp.blogspot.com/-GEyWc6EEApk/VYCEOt34T-I/AAAAAAAAAmw/slVlbI1gy_c/s1600/tumblr%2Blogo%2B30x30.png" class="footer-s-media-icon"></li>
<li><img src="http://www.oacsd.org/sysimages/iconIG.png" class="footer-s-media-icon"></li>
<li><img src="http://www.sunyjefferson.edu/sites/default/files/images/YouTube-icon.png" class="footer-s-media-icon"></li>
<li><img src="http://theriveratranchomirage.com/wp-content/uploads/2015/11/favicon.png" class="footer-s-media-icon"></li>
</ul>
Subscribe to The Economist newsletters
</div>
</div>
<div class="row-1-col-3">
<ul>
<li class="footer-link">Advertise</li>
<li class="footer-link">Careers</li>
<li class="footer-link">Site Map</li>
<li class="footer-link">Reprints</li>
<li class="footer-link">Media Centre</li>
</ul>
</div>
</div>
<div class="row-2">
<div class="row-2-col-1">
<div>
<p>Published since September 1843 to take part in</p>
<p> “a severe contest between intelligence, which presses forward, and an unworthy, timid ignorance obstructing our progress.”</p>
</div>
</div>
</div>
<div class="row-3">
<div class="row-3-col-1">
<ul>
<li>Terms of Use</li>
<li>Privacy</li>
<li>Cookies</li>
<li>Accessibility</li>
</ul>
<p>Copyright © The Economist Newspaper Limited 2017. All rights reserved.</p>
</div>
</div>
</div>
</footer>
The footer is made of three rows all of which fall within a container. The columns have heights of 50%, 40%, and 9%. The issue was caused due to the 3rd row having a height of 10% which should have summed up to the full 100% of the footer container.
My question is, why did changing the 3rd row's height fix this issue? Does anyone have any background knowledge that would fill in this information for me?

It's because of the borders that you have applied with .row-2 are not calculated as part of the height of the element. They're in addition to it's height. In the end .row-2 is 2px larger than 40%.
You can fix this with box-sizing: border-box;.
border-box
This is the box model used by Internet Explorer when the document is in Quirks mode. Note that padding and border will be inside of the box e.g. .box {width: 350px; border: 10px solid black;} leads to a box rendered in the browser of width: 350px. The content box can't be negative and is floored to 0, making it impossible to use border-box to make the element disappear.
Here the dimension is calculated as, width = border + padding + width of the content, and height = border + padding + height of the content.
.footer-container > .row-2 {
box-sizing: border-box;
}
You could also use calc() for height.
.row-2 {
height: calc( 40% - 2px );
border-top: 1px #7a7a7a solid;
border-bottom: 1px #7a7a7a solid;
}
The one issue I have with calc() is if you change the thickness of your borders at all you also have to update the value for height. With box-sizing: border-box; it's automatic.

Related

Why does my second div element overlap my first?

When I create a new div, the second one, whether it be an image or text. It overlaps the first div container. I figured it may be something to do with the display: flex;, but I'm not sure. Also I am super new so sorry if this is elementary.
* {
font-family: Helvetica;
font-size: 22px;
color: seashell;
background-color: black;
opacity: 0.9;
}
.container {
height: 69px;
border-bottom: 1px solid seashell;
position: fixed;
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
}
.container li {
display: inline;
text-decoration: underline;
justify-content: flex-end;
margin-right: 20px;
}
.header-image {
height: 50px;
margin-left: 10px;
}
.container li:hover {
text-decoration: none;
cursor: pointer;
color: darkgray;
}
<div class="container">
<img class="header-image"
src="https://content.codecademy.com/courses/freelance-1/unit-4/img-tea-cozy-logo.png">
<ul>
<li>Mission</li>
<li>Featured Tea</li>
<li>Locations</li>
</ul>
</div>
<div>
<p>Hello</p>
</div>
Thank you.
It's because your container has positioned: fixed; assigned to it. If you add a margin to your second div and apply top: 0 to your container you can push it down without affecting your container element like below:
* {
font-family: Helvetica;
font-size: 22px;
color: seashell;
background-color: black;
opacity: 0.9;
}
.container {
height: 69px;
border-bottom: 1px solid seashell;
position: fixed;
top: 0rem; /* force container to the top of the page */
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
}
.container li {
display: inline;
text-decoration: underline;
justify-content: flex-end;
margin-right: 20px;
}
.header-image {
height: 50px;
margin-left: 10px;
}
.container li:hover {
text-decoration: none;
cursor: pointer;
color: darkgray;
}
div:nth-of-type( 2 ) {
margin-top: 4rem; /*give the second div top margin to push it down */
}
<div class="container">
<img class="header-image"
src="https://content.codecademy.com/courses/freelance-1/unit-4/img-tea-cozy-logo.png">
<ul>
<li>Mission</li>
<li>Featured Tea</li>
<li>Locations</li>
</ul>
</div>
<div>
<p>Hello</p>
</div>
just remove position: fixed form .container or if you wants it to be fixed you can add z-index: 1
Your second div ('Hello' block) overlaps first div(header container), because first div has position: fixed style.
When you apply position: fixed or position: absolute to element, the element is become removed from the normal document flow, and no space is created for the element in the page layout(https://developer.mozilla.org/en-US/docs/Web/CSS/position).
Since div is removed from document flow it doesn't take any space in document, imagine that div is flying on another separate layer.
If you want to keep position: fixed property you need to compensate it's height by applying:
padding-top: 69px to div's parent -> body.
and
top: 0 to .container to make header stick to the top of the screen;
This way all next elements will have right position from beginning and you will not need to offset each of them.
* {
font-family: Helvetica;
font-size: 22px;
color: seashell;
background-color: black;
opacity: 0.9;
}
/* HERE */
body {
padding-top: 69px;
}
.container {
height: 69px;
border-bottom: 1px solid seashell;
/* HERE */
top: 0;
position: fixed;
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
}
.container li {
display: inline;
text-decoration: underline;
justify-content: flex-end;
margin-right: 20px;
}
.header-image {
height: 50px;
margin-left: 10px;
}
.container li:hover {
text-decoration: none;
cursor: pointer;
color: darkgray;
}
<div class="container">
<img class="header-image"
src="https://content.codecademy.com/courses/freelance-1/unit-4/img-tea-cozy-logo.png">
<ul>
<li>Mission</li>
<li>Featured Tea</li>
<li>Locations</li>
</ul>
</div>
<div>
<p>Hello</p>
</div>
<div>
<p>Second Hello</p>
</div>

Expand child height based on taller sibling (parent height set to auto)

Simple question (snippet below):
<ul> with display: flex
each <li> should have the same size and together must occupy the full width of the <ul>
each <li> has a <a> which the content may have 1 or 2 lines of text.
each <li> has height set to auto to adjust to the <a> content
My problem:
I need the "one-line" links to auto expand to the height of the "two-line" links. Setting height: 100% doesn't work because their parent height it's intentionally set to auto to adjust for content.
But in some cases I'll get two-line links, and some cases all will be one-line. So I need the one-line links to auto-expand when that happens.
How is this possible?
#root {
width: 140px;
box-sizing: border-box;
}
ul {
display: flex;
justify-content: space-between;
margin: auto;
padding: 0;
}
li {
flex-grow: 1;
flex-basis: 30px;
list-style-type: none;
display: inline-block;
border: 1px dotted blue;
height: auto;
}
a {
cursor: pointer;
border: 1px dotted green;
display: inline-block;
background-color: lightblue;
padding: 8px 0px;
}
<div id="root">
<ul>
<li><a>Link 1</a></li>
<li><a>Long Link 2</a></li>
</ul>
</div>
You don't need to use inline-block with flex. Just use display: flex for li and display: block for a. Finally, add the width: 100% for a. It seems match your requirement.
#root {
width: 140px;
box-sizing: border-box;
}
ul {
display: flex;
justify-content: space-between;
margin: auto;
padding: 0;
}
li {
flex-grow: 1;
flex-basis: 30px;
list-style-type: none;
display: flex;
border: 1px dotted blue;
height: auto;
}
a {
cursor: pointer;
border: 1px dotted green;
display: block;
background-color: lightblue;
padding: 8px 0px;
width: 100%;
}
<div id="root">
<ul>
<li><a>Link 1</a></li>
<li><a>Long Link 2</a></li>
</ul>
</div>
you can omit padding from top and bottom of the anchor and use height 100% a{height: 100%;}
#root {
width: 140px;
box-sizing: border-box;
}
ul {
display: flex;
justify-content: space-between;
margin: auto;
padding: 0;
}
li {
flex-grow: 1;
flex-basis: 30px;
list-style-type: none;
display: inline-block;
border: 1px dotted blue;
height: auto;
}
a {
cursor: pointer;
border: 1px dotted green;
display: inline-block;
background-color: lightblue;
height: 100%;
}
<div id="root">
<ul>
<li><a>Link 1</a></li>
<li><a>Long Link 2</a></li>
</ul>
</div>

Cannot assign css rules for div element

I try to add some css rules to a div element using an ID SELECTOR
But it does nothing..
This is the result of my code:
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
}
#header {
background: #DEDEDE;
}
.flex-container {
display: flex;
}
#header .flex-container {
flex-flow: row nowrap;
justify-content: center;
align-items: center;
width: 1028px;
margin: 0 auto;
/* put the container on the middle */
}
#header .flex-container #logoPicture {
width: 50%;
border: solid;
margin-top: 10px;
margin-bottom: 10px;
}
#tal {
border: solid;
}
#header .flex-container img {
vertical-align: middle;
border-radius: 20%;
}
#header .flex-container #logo {
font-family: "Bauhaus 93";
font-size: 350%;
color: #E83303;
}
#header .flex-container ul {
padding-left: 0;
/* avoud the default padding to the left */
font-family: "Franklin Gothic", Tahoma;
}
#header .flex-container ul li {
display: inline-block;
padding: 11px 25px;
margin: 3px;
background: #E83303;
border-radius: 10px;
font-weight: bold;
}
<div id="header">
<div class="flex-container">
<div id="logoPicture">
<img src="https://i.imgur.com/cvO9xwB.png">
</div>
<div id="logo">RAPITEC</div>
<div id="tal">
<ul>
<li>Home</li>
<li>About</li>
<li>Shop</li>
<li>Contact us</li>
</ul>
</div>
</div>
</div>
Instead of:
#tal {
border: solid;
}
Try:
#tal {
border: 1px solid black;
}
You could also write this like:
#tal {
border-width: 1px;
border-style: solid;
border-color: black;
}
When putting your code into Codepen, I am seeing a border (Chrome and Firefox on Mac). It appears that our default border-width and/or border-color values are different. It's best to be specific about those two things.

getting images and Divs to be the same size with flexbox

I know this is probably a basic question but so far I have not been able to resolve it via google:
I want to have a navbar with an Image (a logo) and 3 links on its right. I want them all to have the same height and to be on the same height, a little bit like this:
however all I manage is to make it look like this:
#nav-bar {
position: fixed;
top: 0px;
width: 100%;
background: #b7b7b7;
border: 1px #4c4c4c solid;
padding: 1em;
}
#flex {
display: flex;
justify-content: start;
flex-wrap: wrap;
align-content: center;
}
img {
margin-top: 20px;
height: auto;
width: 15%;
}
.nav-link {
border: 1px solid #4c4c4c;
padding: 0.5em;
background-color: #b7b7b7;
color: black;
text-decoration: none;
}
<nav id="nav-bar">
<div id="flex">
<div><img src="https://i.pinimg.com/originals/58/c8/82/58c88275c1a3389a7260baf05bf34e9a.jpg" alt="violin logo" id="header-img"></div>
Products
Demo
Newsletter
</div>
</nav>
Maybe something like this:
#nav-bar {
position: fixed;
top: 0px;
width: 100%;
background: #b7b7b7;
border: 1px #4c4c4c solid;
padding: 1em;
}
#flex{
display: flex;
justify-content: space-between;
flex-wrap: wrap;
align-content: center;
}
img {
height: 50px;
width: auto;
}
.nav-links {
padding-right: 50px;
}
.nav-links .nav-link {
border: 1px solid #4c4c4c;
background-color: #b7b7b7;
color: black;
height: 50px;
display: inline-block;
text-decoration: none;
}
<nav id="nav-bar">
<div id="flex">
<img src="https://i.pinimg.com/originals/58/c8/82/58c88275c1a3389a7260baf05bf34e9a.jpg" alt="violin logo" id="header-img">
<div class="nav-links">
Products
Demo
Newsletter
</div>
</div>
</nav>
Just wrap links into a div, then set justify-content to 'space-between' and set the same height of both image and div with links. Hope it will help
You almost did it, the only thing you needed was basically to size the <div> around the <img> appropriately, so the <img> could just fill it:
#nav-bar {
position: fixed;
top: 0;
left: 0;
width: 100%;
background: #b7b7b7;
border: 1px #4c4c4c solid;
padding: 1em;
box-sizing: border-box; /* to exclude paddings&borders from width instead of adding them */
}
#flex{
display: flex;
justify-content: start;
align-items: stretch;
}
/* sizing the div with the img */
#flex > div {
width: 15%;
flex: 1 0 auto;
}
/* making the img filling this div */
img{
display: block;
width: 100%;
}
.nav-link{
border: 1px solid #4c4c4c;
padding: 0.5em;
background-color: #b7b7b7;
color: black;
text-decoration: none;
/* making links fill all the space, except some gaps between them */
flex: 1 1 auto;
margin-left: .5em;
/* centering the text in the links and making it responsive */
display: flex;
justify-content: center;
align-items: center;
font-size: calc(10px + 2vw);
}
<nav id="nav-bar">
<div id="flex">
<div>
<img src="https://i.pinimg.com/originals/58/c8/82/58c88275c1a3389a7260baf05bf34e9a.jpg" alt="violin logo" id="header-img">
</div>
Products
Demo
Newsletter
</div>
</nav>

Make list of inline nav items the full height of the container

I am using an inline list as a nav menu, and I would like the hyperlink/list item to take up the full height of the container with the label vertically positioned in the center of the container. Here is what I have:
#top-nav-container {
font-size: 14px;
width: 100%;
height: 50px;
overflow: hidden;
top: 0;
left: 0;
position: fixed;
z-index: 500;
background: #3498db;
}
#top-nav-container .nav-contents {
height: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
}
#top-nav-container .nav-left {
width: 175px;
}
#top-nav-container .nav-mid {} #top-nav-container .nav-right {
margin-left: auto;
text-align: right;
width: 250px;
}
#top-nav-container .top-nav-logo {
max-height: 35px;
float: left;
}
#top-nav-container ul {
margin: 0 0 0 30px;
padding: 0;
float: left;
list-style: none;
display: flex;
/* Removes whitespace between li elements */
flex-direction: row;
align-items: center;
}
#top-nav-container ul li {} #top-nav-container li a {
text-decoration: none;
background: red;
border-right: 1px solid #fff;
color: #fff;
padding: 0 12px;
}
<header id="top-nav-container">
<div class="container nav-contents">
<div class="nav-left">
<a href="#" title="Home">
<img src="http://coneyislandpark.com/imgUploader/logos/Pepsi_logo_2008.png" alt="Home" class="top-nav-logo" />
</a>
</div>
<div class="nav-mid">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
<div class="nav-right">
Stuff here...
</div>
</div>
</header>
Any other suggestions you have with any of this is greatly appreciated.
You need to add both height and line-height to the links, and also make sure they are either display: block or display: inline-block. Note that inline-block would be preferred:
#top-nav-container li a {
height: 50px;
line-height: 50px;
display: inline-block;
}
Note that on small screens, the Stuff Here... div would get cut off due to having a current width of 250px. Simply turn this down to say 50px (or however wide your container would actually be):
#top-nav-container .nav-right {
width: 50px;
}
I've created a fiddle showing this here.
Hope this helps! :)
You need to modify your CSS a little, see the following snippet:
#top-nav-container {
font-size: 14px;
width: 100%;
height: 50px;
overflow: hidden;
top: 0;
left: 0;
position: fixed;
z-index: 500;
background: #3498db;
}
#top-nav-container .nav-contents {
height: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
}
#top-nav-container .nav-left {
width: 175px;
}
#top-nav-container .nav-mid {
/* all below rules were added*/
position: absolute;
line-height: 50px;
height: 100%;
left: 50%;
transform: translateX(-50%);
}
#top-nav-container .nav-right {
margin-left: auto;
text-align: right;
width: 250px;
}
#top-nav-container .top-nav-logo {
max-height: 35px;
float: left;
}
#top-nav-container ul {
margin: 0 0 0 30px;
padding: 0;
float: left;
list-style: none;
display: flex;
/* Removes whitespace between li elements */
flex-direction: row;
align-items: center;
}
#top-nav-container ul li {} #top-nav-container li a {
text-decoration: none;
background: red;
border-right: 1px solid #fff;
color: #fff;
padding: 0 12px;
/* all below rules were added*/
height: 50px;
line-height: 50px;
display: inline-block;
}
<header id="top-nav-container">
<div class="container nav-contents">
<div class="nav-left">
<a href="#" title="Home">
<img src="http://coneyislandpark.com/imgUploader/logos/Pepsi_logo_2008.png" alt="Home" class="top-nav-logo" />
</a>
</div>
<div class="nav-mid">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
<div class="nav-right">
Stuff here...
</div>
</div>
</header>