Use CSS to make <a> full height of container <div> in footer - html

I have a footer with my navigation list contained. On hover, I would like to change the background color of the entire height of the div. As it is right now, only the background around the text is changing color. I have tried adding top and bottom padding to the text, but that's not having the right effect I'm looking for. Is there a way to make the <a> 100% of the height of the containing footer div?
Code below:
footer {
width: 100%;
background: #222;
color: #fff;
margin: 0;
position:fixed;
left:0px;
bottom:0px;
}
.footer-navigation {
width: 60%;
display: flex;
align-items: center;
}
.footer-links-holder {
width: 25%;
position: relative;
float: left;
margin: 0;
}
.footer-links-holder:hover {
background-color: #444;
transition: 0.5s;
}
<div class="footer-navigation">
<a class="footer-links-holder" href=""><h3>About Me</h3></a>
<a class="footer-links-holder" href=""><h3>Photography</h3></a>
<a class="footer-links-holder" href=""><h3>Portfolio</h3></a>
<a class="footer-links-holder" href=""><h3>Back to Top</h3></a>
</div>
Can anyone help? I've searched around and can't seem to find a simple solution.
EDIT: Here's a jfiddle link
https://jsfiddle.net/adamdrover/qe2d318L/

You need to make your footer-links "display: block" and then it will accept the width and height values.
.footer-links {
display: block;
margin: 0;
padding: 0;
list-style: none;
}

https://jsfiddle.net/qe2d318L/1/
I removed flex rules from .footer-contact and .footer-navigation, set them in the a instead, the link has become full height:
.footer-contact a,
.footer-navigation a {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
body {
background: #348F50; /* fallback for old browsers */
background: -webkit-linear-gradient(to left, #348F50 , #56B4D3); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to left, #348F50 , #56B4D3); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
margin: 0;
}
.clearfix:before, .clearfix:after {
clear: both;
}
footer {
width: 100%;
background: #222;
color: #fff;
margin: 0;
position:fixed;
left:0px;
bottom:0px;
}
.centered {
max-width: 1200px;
margin: 0 auto;
display: flex;
justify-content: space-between;
}
.footer-logo {
width: 20%;
}
.logo {
padding: 30px 20px 10px 20px;
max-width: 100%;
}
.footer-contact {
width: 15%;
/*align-items: center;
justify-content: center;
display: flex;*/
}
h3 {
margin: 0;
text-align: center;
}
.footer-contact a,
.footer-navigation a {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
.footer-navigation {
width: 60%;
/*display: flex;
align-items: center;*/
}
.footer-links-holder {
display: block;
width: 25%;
position: relative;
float: left;
margin: 0;
}
.footer-links-holder:hover {
background-color: #444;
transition: 0.5s;
}
.bottom-bar {
position: relative;
text-align: center;
font-size: .8em;
text-transform: uppercase;
background: #000;
padding: 15px 0;
}
<footer>
<!-- include slogan, contact me form on web, contact button on mobile. Social media links on right. -->
<div class="centered clearfix">
<div class="footer-logo">
<img class="logo" src="images/laptop-logo.png">
<div class="social">
<a href="https://www.facebook.com/" class="facebook">
</a>
<a href="https://twitter.com/" class="twitter">
</a>
<a href="https://www.linkedin.com/" class="linkedin">
</a>
</div>
</div>
<div class="footer-contact">
<h3>Contact Me</h3>
</div>
<div class="footer-navigation">
<a class="footer-links-holder" href=""><h3>About Me</h3></a>
<a class="footer-links-holder" href=""><h3>Photography</h3></a>
<a class="footer-links-holder" href=""><h3>Portfolio</h3></a>
<a class="footer-links-holder" href=""><h3>Back to Top</h3></a>
</div>
</div>
<div class="bottom-bar">
All Rights Reserved © 2016 | Privacy Policy
</div>
</footer>

Related

CSS - Border stretched to whole height of navbar

I am trying to make a border on the right of most of my LIs (that are also anchor tags) fill the entirety of the div vertically, with a width of 1em like this (my figma mockup):
However, all I am getting currently is this:
Here is my (S)CSS:
.navbar-main {
margin-top: 2em;
display: flex;
background-color: hsl(206, 97%, 13%);
color: hsl(0, 0%, 100%);
border-radius: 34px;
width: 90vw;
height: 3em;
margin-left: auto;
margin-right: auto;
justify-content: space-between;
text-align: center;
.links {
display: flex;
justify-content: flex-start;
margin-left: 2em;
align-items: center;
}
ul {
display: inherit;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
gap: 1em;
height: 100%;
}
/* Add a vertical border to the right of all of the lis that stretches to the whole of the div vertically */
li {
border-right: 1px solid hsl(0, 0%, 100%);
}
.langselect {
margin-right: 2em;
display: inherit;
justify-content: flex-end;
align-items: center;
}
.icon {
margin-right: 0.5em;
height: 1em;
width: 1em;
font-size: inherit;
text-align: center;
display: inline-block;
vertical-align: middle;
}
}
And here is my HTML (REACT):
<div className="navbar-main">
<div className="links">
<ul> {/*TODO: Remember to put icons before the a tags! (USE BOOTSTRAP ICONS!) */}
<li>
<a href="#">
<FaHome className="home icon"/>
Portfolio/CV
</a>
</li>
<li>
<a href="#">
<FaBookOpen className="book icon"/>
Portfolio/CV
</a>
</li>
<li>
<a href="#">
<FaPuzzlePiece className="puzzle icon"/>
!?#!#*$%
</a>
</li>
</ul>
</div>
<div className="langselect">
<FaGlobe className="world icon"/>
<p>Language Select</p>
</div>
</div>
All help is appreciated, thanks a lot.
Turns out after a bit of back and forth debugging and writing code, I found out that I could do this:
li {
display: inherit;
height: 100%;
border-right: 1px solid hsl(206, 94%, 20%);
padding-right: 1em;
a {
margin-top: auto;
margin-bottom: auto;
}
}
li:last-child {
border-right: none;
padding-right: 0;
}
This works flawlessly too, as seen here:
Thanks anyway for your guys' help!

How to hide Font-Awesome icons using CSS

I cannot seem to successfully use display: none !important; nor visibility: hidden; to hide the menu bars and close icons on a desktop. I have tried applying the code to other objects on my website as well (like the hero button) but it also didn't work on that.
You will however see the below code is only applied to the class for the close icon fa fa-times
HTML code:
<!--homepage header -->
<section class="header">
<nav>
<a href="index.html"> <!--add logo-->
<img src="" alt=""><!--add links-->
</a>
<div class="nav-links">
<div class="close-icon">
<!--menu close icon-->
<i class="fas fa-times"></i>
</div>
<ul>
<li>HOME</li><!--add links-->
<li>ABOUT</li><!--add links-->
<li>SOFTWARE</li><!--add links-->
<li>BLOG</li><!--add links-->
<li>CONTACT</li><!--add links-->
</ul>
</div>
<div class="menu-bars">
<!--menu icon-->
<i class="fas fa-bars"></i>
</div>
</nav>
CSS Code
#import url("https://kit.fontawesome.com/d68c6a086c.js")
*{
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
.header{
min-height: 100vh;
width: 100%;
/* change image below */
background-image: linear-gradient(rgba(4,9,30,0.7),rgba(4,9,30,0.7)),url(images/ft-870l-500x500.jpg);
background-position: center;
background-size: cover;
position: relative;
}
nav {
display: flex;
padding: 2% 6%;
justify-content: space-between;
align-items: center;
}
/* nav bar comapny logo*/
nav img{
width: 150px;
}
.nav-links{
flex: 1;
text-align: right;
}
/* list style */
.nav-links ul li {
list-style: none;
display: inline-block;
padding: 8px 12px;
position: relative;
}
/* each link */
.nav-links ul li a{
color: #fff;
text-decoration: none;
font-size: 13px;
}
.nav-links ul li::after{
content: '';
width: 100%;
height: 2px;
background: #f44336;
display: block;
margin: auto;
transition: 0.5s;
}
.nav-links ul li:hover::after{
width: 100%;
}
/* Hide Menu Items for Desktop */
.close-icon {
display: none !important;
visibility: hidden;
}
#media (max-width: 700px) {
.text-box h1{
font-size: 20px;
}
.nav-links ul li {
display: block;
}
.nav-links{
position: absolute;
background: #f44336;
height: 100vh;
width: 200px;
top: 0;
right: 0;
text-align: left;
z-index: 2;
}
.close-icon {
display: block;
color: #fff;
margins: 10px;
font-size: 22px;
cursor: pointer;
}
}
```
Please try
nav {
display: none;
/*padding: 2% 6%;
justify-content: space-between;
align-items: center;*/
}
#media (max-width: 700px) {
nav {
display: flex;
padding: 2% 6%;
justify-content: space-between;
align-items: center;
}
}
In head section where you added CSS file add
src="folder/stye.css?v=1.1"
Change v=1.1 to 1.2 or 1.3.1 etc.. whenever you make changes in CSS file.

Why does my main context go over the header?

When I put in my header (i have already put in my context) it just puts the header underneath what the context is so you can't see the header.
I have already tried changing the padding and the other sizes but none work
https://jsfiddle.net/L30trdfn/1/This is the full code of my website
What should happen is that the description and avatar ECT should go under the navbar and fit
Change your CSS code Like this
.split {
width: 100%;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.col {
width:50%;
height:50%;
flex: 0 0 50%;
max-width: 50%;
padding-top: 50px;
overflow-x: hidden;
}
.black{background-color: #f5f5f5;}
.red{background-color: #f00;}
.centered {
text-align: center;
}
Corresponding html like this
<div class="split">
<div class="col black">
<div class="centered">
<img src="avatar1.png" alt="Avatar woman">
<h2>Fortnitewinner21</h2>
<p>Co-Owner of FSX/XP11 and is the Head Website devolper</p>
</div>
</div>
<div class="col red">
<div class="centered">
<img src="avatar2.png" alt="Avatar man">
<h2>MasterPilot</h2>
<p>Owner of FSX/XP11, He plays a big part in making the server run smoothley</p>
</div>
</div>
</div>
Change the img src according to your sources
{
font-family: Arial;
color: white;
}
* {
box-sizing: border-box;
}
body {
font-family: Arial;
padding: 10px;
background: #9099A2;
}
/* Header/Blog Title */
.header {
padding: 30px;
text-align: center;
color: white;
background: #6D7993;
}
.header h1 {
font-size: 50px;
}
/* Navbar container */
.navbar {
overflow: hidden;
background-color: #333;
font-family: Arial;
}
/* Links inside the navbar */
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The dropdown container */
.dropdown {
float: left;
overflow: hidden;
}
/* Dropdown button */
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit; /* Important for vertical align on mobile phones */
margin: 0; /* Important for vertical align on mobile phones */
}
/* Add a red background color to navbar links on hover */
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: indianred;
}
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a grey background color to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Left column */
.leftcolumn {
float: left;
width: 75%;
}
/* Right column */
.rightcolumn {
float: left;
width: 25%;
background-color: #9099A2;
padding-left: 20px;
}
/* Fake image */
.fakeimg {
width: 100%;
}
/* Add a card effect for articles */
.card {
background-color: #D5D5D5;
padding: 20px;
margin-top: 20px;
box-shadow: 10px 10px 5px grey;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
.split {
width: 100%;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.col {
width:50%;
height:50%;
flex: 0 0 50%;
max-width: 50%;
padding-top: 50px;
overflow-x: hidden;
}
.black{background-color: #f5f5f5;}
.red{background-color: #f00;}
.centered {
text-align: center;
}
.centered img {
width: 150px;
border-radius: 50%;
}
<div class="header">
<h1>Welcome To FSX/XP11</h1>
<p>The Home of Flight Sim</p>
</div>
<div class="navbar">
Home
Gallery
<div class="dropdown">
<button class="dropbtn">Flight Planner
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Flight Strips
Login
Register
</div>
</div>
</div>
<div class="split">
<div class="col black">
<div class="centered">
<img src="https://mail.google.com/mail/u/0?ui=2&ik=61315df9c6&attid=0.1&permmsgid=msg-f:1648390313577802256&th=16e04241b3ffea10&view=fimg&sz=s0-l75-ft&attbid=ANGjdJ8KWZCU9VW1k7NdYrm1ZoOE30R5M9Aoeokzr0KSjzE53wP1UvEZhJkACRl5RpKmGQs8W9TlWHfQME7CgcCB3TKlJ8lpdJYRU7dwfDfGHHHJvD455hCYQa4OAos&disp=emb&realattid=ii_k26gkdq90" alt="Avatar woman">
<h2>Fortnitewinner21</h2>
<p>Co-Owner of FSX/XP11 and is the Head Website devolper</p>
</div>
</div>
<div class="col red">
<div class="centered">
<img src="img_avatar.png" alt="Avatar man">
<h2>MasterPilot</h2>
<p>Owner of FSX/XP11, He plays a big part in making the server run smoothley</p>
</div>
</div>
</div>
Use the following CSS : \
you had given fixed position in .split and also used absolute position in .centered. I hope you got your answer
.split {
height: 50%;
width: 50%;
overflow-x: hidden;
padding-top: 50px;
}
.centered {
text-align: center;
}

Creating a responsive image for a section

I'm sure I have made some kind of really obvious stupid mistake here but it's been bugging me for a while now and I just cannot figure it out no matter where I look.. I am just practicing with a very basic, boring site and I need the image to be responsive in the section underneath the header, but for some reason no matter what I do, I just can't get it to work.
Sorry if this has been answered, I had a look and couldn't find anything exactly the same. If anyone could shed some light on this for me I would be very appreciative. Thanks in advance.
HTML:
<html>
<body>
<header>
<div class="container">
<div class="brand">
<img class="brandImg" src="https://photos-1.dropbox.com/t/2/AACo_XuN80WW6m3RltLuUDD-Koivyw205OCV55h43hevVQ/12/184045382/png/32x32/1/_/1/2/network.png/EKPi4YsBGMICIAIoAg/u6N5dEYvNDRNysVhT6Arx-eKOa64tOkilzRp8K3e93Y?preserve_transparency=1&size=1600x1200&size_mode=3" alt="Brand Image">
<h3 class="mainTitle">Network Solutions</h3>
</div>
<nav>
<ul class="navBar">
<li>About |</li>
<li>Portfolio |</li>
<li>Contact</li>
</ul>
</nav>
</div>
</header>
<section id="showcase">
<div class="heroImg">
<div class="container">
</div>
</div>
</section>
</body>
</html>
CSS:
/* MAIN STYLES */
.container {
max-width: 60%;
margin: 0 auto;
}
/* HEADER */
header {
height: 100px;
border-bottom: 2px solid black;
border-top: 2px solid black;
}
.brand {
float: left;
display: inline;
margin-top: 20px;
}
.brandImg {
height: 4em;
width: 4em;
float: left;
margin-bottom: 5px;
}
.mainTitle {
font-family: 'IBM Plex Mono', monospace;
line-height: 1.2em;
position: relative;
left:8px;
top: -5px;
}
/* MAIN NAVIGATION */
ul {
float: right;
}
li {
margin-top: 15px;
float: left;
display: inline;
font-size: 40px;
padding-left: 15px;
}
a {
color: #000;
text-decoration: none;
}
a:hover {
color: gray;
}
/* HERO SECTION */
#showcase {
width: 100%;
height: 100%;
}
.heroImg {
background-image: url("https://photos-1.dropbox.com/t/2/AADgiVKPX---q_yzz3R6QXjMuvUF9x1suRGMjLMV8QkZVQ/12/184045382/jpeg/32x32/1/_/1/2/hero.jpeg/EKPi4YsBGMICIAIoAg/-UTK8zUqda_wA3F-VrZAdIZvo84OHHGWCbLEcdCi1K8?size=1600x1200&size_mode=3");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
Codepen link
The logo image in your pen is throwing a 403 error. Generally speaking, you can make an image responsive with the following CSS:
img {
display: inline-block;
max-width: 50px; /* Width of your image */
max-height: 50px; /* Height of your image */
width: 100%;
height: auto;
}
Here is a JSFiddle example. Drag the window to see how the image reacts.
img {
display: inline-block;
max-width: 650px;
max-height: 250px;
width: 100%;
height: auto;
}
<img src="http://via.placeholder.com/650x250" alt="Stack Overflow Test Image" />
Here's another example using Flexbox making the image responsive relative to another element:
#test {
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
img {
display: inline-block;
max-width: 250px;
max-height: 150px;
width: 100%;
height: auto;
}
h1 {
margin-left: 15px;
-webkit-flex: none;
-ms-flex: none;
flex: none;
}
<div id="test">
<div id="logo">
<img src="http://via.placeholder.com/250x150" alt="Stack Overflow Test Image" />
</div>
<h1>This is a Test Title</h1>
</div>

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>