CSS dropdown cropped by topnav - css

I've a simple page containing: a header, a topnav and a body.
The topnav would contain a link (variable width since it will be the name of the logged user) to open a dropdown menu.
Problem: The dropdown menu is "cropped" by the topnav.
I've tried the z-index solution, but no success.
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
font-size: 16pt;
}
.header {
background-color: #F1F1F1;
text-align: center;
padding: 20px;
font-size: 18pt;
font-weight: bold;
}
.topnav {
position: relative;
top:0;
overflow: hidden;
background-color: #333;
font-weight: bold;
z-index: 1;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
cursor:pointer
}
.topnav a:hover {
transition-delay: 70ms;
background-color: #ddd;
color: black;
}
.active {
background-color: #4CAF50;
color: white;
}
.dropdown {
position: absolute;
display: inline-block;
float: right;
overflow: hidden;
margin: 0;
z-index: 100;
}
.dropdown-content {
display: none;
position: absolute;
top: 70%;
padding-top: 0px;
color: #f2f2f2;
background-color: blue;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 200;
}
.dropdown:hover .dropdown-content {
display: block;
}
#media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
#media screen and (max-width: 600px) {
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
/* Finestra modal */
.container {
padding: 30px;
}
span.psw {
float: right;
padding-top: 16px;
}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
padding-top: 60px;
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 5% auto 15% auto; /* 5% from the top, 15% from the bottom and centered */
border: 1px solid #888;
width: 30%; /* Could be more or less, depending on screen size */
}
/* Full-width input fields */
.modal input[type=text], .modal input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
/* Set a style for all buttons */
.modal button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
font-weight: bold;
}
.imgcontainer {
font-weight: bold;
text-align: center;
margin: 24px 0 12px 0;
position: relative;
}
/* The Close Button (x) */
.close {
position: absolute;
right: 9px;
top: -20px;
color: #000;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: red;
cursor: pointer;
}
/* Add Zoom Animation */
.animate {
-webkit-animation: animatezoom 0.6s;
animation: animatezoom 0.6s
}
#-webkit-keyframes animatezoom {
from {-webkit-transform: scale(0)}
to {-webkit-transform: scale(1)}
}
#keyframes animatezoom {
from {transform: scale(0)}
to {transform: scale(1)}
}
/* Change styles for span and cancel button on extra small screens */
#media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
.cancelbtn {
width: 100%;
}
}
<link rel="stylesheet" href="css/topnav.css">
<!-- HEADER -->
<div class="header">
Sistema di Gestione
</div>
<!-- BARRA MENU -->
<div class="topnav" id="navbar">
<a class="active" href="index.php">Home</a>
Segnalazioni
<div class="dropdown"><a>Dropdown></a>
<div class="dropdown-content"><a>BANANA</a></div>
</div>
</div>
<!-- Form di Login -->
<div id="finestra" class="modal">
<div class="modal-content">
<form class="login" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="imgcontainer">
<span onclick="document.getElementById('finestra').style.display='none'" class="close" title="Chiudi finestra">×</span>
</div>
<div class="container">
<input type="text" placeholder="Username" name="username" required>
<input type="password" placeholder="Password" name="password" required>
<button type="submit" name="login" value="login">Login</button>
</div>
</form>
</div>
</div>
<!-- Script per chiudere il modal -->
<script>
// Get the modal
var modal = document.getElementById('finestra');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>

Your issue with overflow:hidden given in parent divs of dropdown.
Changed below css
.topnav {
position: relative;
top: 0;
/* overflow: hidden; */ // Removed
background-color: #333;
font-weight: bold;
z-index: 1;
display: block;
width: 100%; // Added
height: 48px; // Added
}
.dropdown {
position: absolute;
display: inline-block;
float: right;
/* overflow: hidden; */ // Removed
margin: 0;
z-index: 100;
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
font-size: 16pt;
}
.header {
background-color: #F1F1F1;
text-align: center;
padding: 20px;
font-size: 18pt;
font-weight: bold;
}
.topnav {
position: relative;
top:0;
/* overflow: hidden; */
background-color: #333;
font-weight: bold;
z-index: 1;
width: 100%;
height: 48px;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
cursor:pointer
}
.topnav a:hover {
transition-delay: 70ms;
background-color: #ddd;
color: black;
}
.active {
background-color: #4CAF50;
color: white;
}
.dropdown {
position: absolute;
display: inline-block;
float: right;
/*overflow: hidden;*/
margin: 0;
z-index: 100;
}
.dropdown-content {
display: none;
position: absolute;
top: 70%;
padding-top: 0px;
color: #f2f2f2;
background-color: blue;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 200;
}
.dropdown:hover .dropdown-content {
display: block;
}
#media screen and (max-width: 600px) {
.topnav a:not(:first-child) {display: none;}
.topnav a.icon {
float: right;
display: block;
}
}
#media screen and (max-width: 600px) {
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
/* Finestra modal */
.container {
padding: 30px;
}
span.psw {
float: right;
padding-top: 16px;
}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
padding-top: 60px;
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 5% auto 15% auto; /* 5% from the top, 15% from the bottom and centered */
border: 1px solid #888;
width: 30%; /* Could be more or less, depending on screen size */
}
/* Full-width input fields */
.modal input[type=text], .modal input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
/* Set a style for all buttons */
.modal button {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
font-weight: bold;
}
.imgcontainer {
font-weight: bold;
text-align: center;
margin: 24px 0 12px 0;
position: relative;
}
/* The Close Button (x) */
.close {
position: absolute;
right: 9px;
top: -20px;
color: #000;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: red;
cursor: pointer;
}
/* Add Zoom Animation */
.animate {
-webkit-animation: animatezoom 0.6s;
animation: animatezoom 0.6s
}
#-webkit-keyframes animatezoom {
from {-webkit-transform: scale(0)}
to {-webkit-transform: scale(1)}
}
#keyframes animatezoom {
from {transform: scale(0)}
to {transform: scale(1)}
}
/* Change styles for span and cancel button on extra small screens */
#media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
.cancelbtn {
width: 100%;
}
}
<link rel="stylesheet" href="css/topnav.css">
<!-- HEADER -->
<div class="header">
Sistema di Gestione
</div>
<!-- BARRA MENU -->
<div class="topnav" id="navbar">
<a class="active" href="index.php">Home</a>
Segnalazioni
<div class="dropdown"><a>Dropdown></a>
<div class="dropdown-content"><a>BANANA</a></div>
</div>
</div>
<!-- Form di Login -->
<div id="finestra" class="modal">
<div class="modal-content">
<form class="login" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="imgcontainer">
<span onclick="document.getElementById('finestra').style.display='none'" class="close" title="Chiudi finestra">×</span>
</div>
<div class="container">
<input type="text" placeholder="Username" name="username" required>
<input type="password" placeholder="Password" name="password" required>
<button type="submit" name="login" value="login">Login</button>
</div>
</form>
</div>
</div>
<!-- Script per chiudere il modal -->
<script>
// Get the modal
var modal = document.getElementById('finestra');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>

Related

Why the burger menu does not pop out?

I tried building a burger-menu that will pop out some items when clicked. I managed to create and style everything but when I click it the menu does not come out. I do not understand why, what suppose to make this happen is clicking on the check-box and it expanding the max-height of the .menu class to a specific height. I am trying to achieve this with pure css.
Here is the relevant code:
The react component I am trying to style:
...
const TopBar = () => {
...
return (
<header className="header">
<input className="menu-btn" type="checkbox" id="menu-btn" />
<label className="menu-icon" htmlFor="menu-btn"><span className="nav-icon"></span></label>
<div className="logo">Sort Visualizer</div>
<section className="menu">
<div className="algorithm-select">
<select name="Sorting Algorithm"
id="algorithm"
onChange={(e) => handleAlgorithmSelect(e)}
value={data.sortingAlgorithm}>
{sortManager.getAllAlgorithms().map((value) =>
<option value={value}
key={shortid.generate()}
>{value}</option>)}
</select>
</div>
<div className="array-size">
<div className="slider-container">
5
<input type="range"
min="5"
max="100"
value={data.length}
onChange={(e) => handleLength(e)}
className="slider"
id="myRange"
/>
100
</div>
</div>
<div>
<button className="randomize-btn" onClick={() => generateArray()}>Randomize</button>
</div>
</section>
</header>
);
}
export default TopBar;
Here is the whole stylesheet:
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
font-size: 62.5%;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
/* TopBar */
.header {
background-color: #222;
color: #fff;
box-shadow: 1px 3px 10px 0 rgba(0, 0, 0, .4);
position: fixed;
width: 100%;
height: 8%;
z-index: 3;
}
.header .menu {
clear: both;
max-height: 0;
transition: max-height .2s ease-out;
overflow: hidden;
}
.header .menu div {
display: block;
padding: 20px;
border-right: 1px solid #ccc;
}
.header .logo {
float: left;
display: block;
font-size: 3rem;
padding: 5px 20px;
}
.header .menu-btn {
position: absolute;
top: 0;
right: 0;
z-index: 2;
cursor: pointer;
width: 45px;
height: 45px;
opacity: 0;
}
.header .menu-icon {
position: absolute;
top: 0;
right: 0;
z-index: 1;
width: 40px;
height: 40px;
margin: 6px 5px;
display: flex;
align-items: center;
justify-content: center;
}
.header .menu-icon .nav-icon {
position: relative;
width: 75%;
height: 2px;
background: #fff;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.4s ease;
}
.header .menu-icon .nav-icon:before,
.header .menu-icon .nav-icon:after {
content: '';
position: absolute;
z-index: 1;
top: -9px;
width: 100%;
height: 2px;
background: inherit;
}
.header .menu-icon .nav-icon:after {
top: 9px;
}
.header .menu-btn:checked + .menu-icon .nav-icon {
transform: rotate(135deg);
}
.header .menu-btn:checked + .menu-icon .nav-icon:before,
.header .menu-btn:checked + .menu-icon .nav-icon:after {
top: 0;
transform: rotate(90deg);
}
.header .menu-btn:checked ~ .menu {
max-height: 240px;
}
I tried a few things but it wasn't successful. What am I missing?

How to transform/transition div without moving the text?

I created an overlay menu for the responsive menu of website. every thing is OK but when the menu will be closed, the texts (in menu) will be gathered and moved individually and then disappear but I want them to slide out without moving texts.
I tried these HTML:
<section class="overlaysection">
<div id="myoverlaynav" class="overlay">
×
<div class="overlay-content">
<li><a>num one one one one</a></li>
<li><a>num two two two two</a></li>
<li><a>num three three three three</a></li>
<li><a>num four four four four four</a></li>
</div>
</div>
<div class="overlaybtndiv" onclick="openNav()">
<button class="overlaybtn">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<h2>The Menu</h2>
</div>
</section>
CSS Codes:
#media (min-width: 631px){
.overlaysection {
display: none;
}
}
.overlaysection .overlay {
height: 100%;
width: 0;
position: fixed;
/* z-index: 1; */
z-index: 999999;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
direction:rtl;
}
.overlaysection a.closebtn {
position: absolute;
font-size: 40px;
padding: 0;
line-height: 40px;
top: 10px;
right: 10px;
color: #eee;
}
.overlaysection .overlay-content {
position: relative;
width: 100%;
text-align: center;
margin-top: 40px;
}
.overlaysection .overlay a {
display: block;
transition: 0.3s;
text-align: left;
color: #eee;
padding: 8px 8px 8px 20px;
text-decoration: none;
}
.overlaysection .overlay a:hover,
.overlaysection .overlay a:focus {
color: #f1f1f1;
}
.overlaysection .overlaybtndiv {
display: block;
padding: 6px 8px;
position: relative;
}
.overlaysection .overlaybtndiv h2 {
font-size: 14px;
color: black;
line-height: 40px;
margin-right: 10px;
}
.overlaysection .overlaybtn {
border-color: transparent !important;
float: right;
padding: 5px;
background: white;
outline: 0;
}
.overlaysection .overlaybtn .icon-bar {
display: block;
height: 2px;
border-radius: 1px;
padding: 1.5px;
width: 28px;
background-color: black !important;
margin-top: 5px;
}
.overlaysection .overlaybtn .icon-bar:first-child {
margin-top: 3px !important;
}
.
javascript codes:
function openNav() {
document.getElementById("myoverlaynav").style.width = "80%";
}
function closeNav() {
document.getElementById("myoverlaynav").style.width = "0%";
}
you can see this menu in https://end-eng.com/grammar/auxiliary-modal-verbs-in-english/ and this menu is like https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_sidenav
Add min-width and float:left to .overlay-content.
.overlaysection .overlay-content {
position: relative;
width: 100%;
text-align: center;
margin-top: 50px;
min-width: 270px;
float: left;
}
right now what happening is when close navbar its width is reduced so thus your li tag width to so, just give your li tag fixed width and your problem will be solved like.
#media (min-width: 631px){
.li {
width : 200px;
}
}
and only give this in media query for smaller devices otherwise it will replicate in whole website.
It's because you're using width's to control the display.
Instead of this, I suggest that you toggle a "shown" class to your overlay.
By default on your ".overlaysection .overlay" css, change the width to 100% and left to -100%;
Then on the "shown" class set the left to 0. Change the JS to toggle the
shown class and it should then slide out from the left without changing the text orientation.
function openNav() {
document.getElementById("myoverlaynav").classList.toggle('shown');
}
function closeNav() {
document.getElementById("myoverlaynav").classList.toggle('shown');
}
#media (min-width: 631px){
.overlaysection {
display: none;
}
}
.overlaysection .overlay {
height: 100%;
width: 100%;
position: fixed;
/* z-index: 1; */
left: -100%;
z-index: 999999;
top: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
direction:rtl;
}
.overlaysection a.closebtn {
position: absolute;
font-size: 40px;
padding: 0;
line-height: 40px;
top: 10px;
right: 10px;
color: #eee;
}
.overlaysection .overlay-content {
position: relative;
width: 100%;
text-align: center;
margin-top: 40px;
}
.overlaysection .overlay a {
display: block;
transition: 0.3s;
text-align: left;
color: #eee;
padding: 8px 8px 8px 20px;
text-decoration: none;
}
.overlaysection .overlay a:hover,
.overlaysection .overlay a:focus {
color: #f1f1f1;
}
.overlaysection .overlaybtndiv {
display: block;
padding: 6px 8px;
position: relative;
}
.overlaysection .overlaybtndiv h2 {
font-size: 14px;
color: black;
line-height: 40px;
margin-right: 10px;
}
.overlaysection .overlaybtn {
border-color: transparent !important;
float: right;
padding: 5px;
background: white;
outline: 0;
}
.overlaysection .overlaybtn .icon-bar {
display: block;
height: 2px;
border-radius: 1px;
padding: 1.5px;
width: 28px;
background-color: black !important;
margin-top: 5px;
}
.overlaysection .overlaybtn .icon-bar:first-child {
margin-top: 3px !important;
}
#myoverlaynav.shown {
left: 0;
}
<section class="overlaysection">
<div id="myoverlaynav" class="overlay">
×
<div class="overlay-content">
<li><a>num one one one one</a></li>
<li><a>num two two two two</a></li>
<li><a>num three three three three</a></li>
<li><a>num four four four four four</a></li>
</div>
</div>
<div class="overlaybtndiv" onclick="openNav()">
<button class="overlaybtn">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<h2>The Menu</h2>
</div>
</section>

Using skew on parent causes sidenav to lose position

Sorry for the wording, i'm not sure exactly how to phrase it.
I have a header and a container which contains a sidenav and button to toggle it. I am trying to skew the header while keeping the container normal by skewing in the opposite direction. However doing this causes the sidenav to lose it's height:100% and it doesn't stick to the left.
How can i skew the background without affecting the sidenave?
Here is the fiddle and code
https://jsfiddle.net/q0ddzw4v/
HTML
<body id="body">
<header class="header">
<div class="header__container">
<div id="mySidenav" class="sidenav">
×
About
Services
Clients
Contact
</div>
<div id="main">
<h2>Sidenav Push Example</h2>
<p>Click on the element below to open the side navigation menu, and push this content to the right.</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
</div>
</div>
</header>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
</body>
CSS
body {
font-family: sans-serif;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
}
.sidenav a:hover,
.offcanvas a:focus {
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
#main {
padding: 16px;
}
.header {
width: 100%;
height: 100vh;
background-color: #C18D8D;
transform: skewY(-10deg);
}
.header__container {
width: 80%;
max-width: 71.25rem;
margin: auto;
display: flex;
flex-direction: column;
height: 100%;
transform: skewY(10deg);
}
Instead of skewing the .header container, add a pseduo-element and skew it:
body {
font-family: "Lato", sans-serif;
transition: margin-left 0.5s;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
}
.sidenav a:hover,
.offcanvas a:focus {
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
#main {
transition: margin-left .5s;
padding: 16px;
}
.header {
position: relative;
width: 100%;
height: 100vh;
}
.header::before {
display: block;
position: absolute;
width: 100%;
height: 100%;
background-color: #C18D8D;
transform: skewY(-10deg);
content: '';
}
.header__container {
position: relative;
z-index: 0;
width: 80%;
max-width: 71.25rem;
margin: auto;
display: flex;
flex-direction: column;
height: 100%;
}
<header class="header">
<div class="header__container">
<div id="mySidenav" class="sidenav">
×
About
Services
Clients
Contact
</div>
<div id="main">
<h2>Sidenav Push Example</h2>
<p>Click on the element below to open the side navigation menu, and push this content to the right.</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
</div>
</div>
</header>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
// document.getElementById("body").style.marginLeft = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
// document.getElementById("body").style.marginLeft = "0";
}
</script>

Why is my footer on top of the page and is my html structure arranged correctly?

My social network , faq and where to buy's link is arrange inside footer section but it cannot stick it at bottom of my page , and i feel my HTML structure very weird can anyone help me on this ? Thank you
I want it to be like this with the FAQ and Where to Buy at the left bottom , social network logo at right bottom of the page and LOGO in the middle of 4 navigation linkOutput that i want
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}
/* Set the width of the side navigation to 0 */
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
body {
background-image: url(Images/Clean-Gray-BackGround-620x465.jpg);
background-repeat: repeat-x;
background-size: cover;
background-attachment: fixed;
margin: 0;
}
#page {
margin: 0px auto;
width: 1200px;
}
header {
height: 20px;
position: relative;
margin: 30px 0 0;
}
.mainnav {
padding-top: 50px;
position: relative;
width: 1200px;
}
button {
font-size: 20px;
font-family: 'Bungee';
text-align: center;
border: none;
background-color: transparent;
padding: 16px 16px 40px 0px;
}
.dropdown {
display: inline-block;
position: relative;
}
.divider {
margin-left: 100px;
margin-right: 260px;
}
.divider2 {
margin-left: 150px;
}
#submenu {
display: none;
background-color: transparen;
text-align: center;
min-width: 60px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
position: absolute;
}
#submenu a {
color: black;
padding: 0 0 40 0;
text-decoration: none;
display: block;
}
.dropdown:hover #submenu {
display: block;
}
.logo {
position: absolute;
left: 45%;
margin: -48px 0 0 -98px;
}
#cart a {
position: absolute;
/* Position them relative to the browser window */
right: -80px;
/* Position them outside of the screen */
transition: 0.3s;
/* Add transition on hover */
padding: 15px;
/* 15px padding */
width: 100px;
/* Set a specific width */
text-decoration: none;
/* Remove underline */
font-size: 20px;
/* Increase font size */
color: black;
/* White text color */
background-color: white;
border-radius: 15px 0px 0px 15px;
}
#cart a:hover {
right: 0;
text-decoration: none;
}
.sidenav {
height: 100%;
/* 100% Full-height */
width: 0;
/* 0 width - change this with JavaScript */
position: fixed;
/* Stay in place */
z-index: 1;
/* Stay on top */
top: 0;
left: 0;
background-color: #111;
/* Black*/
overflow-x: hidden;
/* Disable horizontal scroll */
padding-top: 60px;
/* Place content 60px from the top */
transition: 0.5s;
/* 0.5 second transition effect to slide in the sidenav */
}
/* The navigation menu links */
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s
}
/* When you mouse over the navigation links, change their color */
.sidenav a:hover,
.offcanvas a:focus {
color: blanchedalmond;
}
/* Position and style the close button (top right corner) */
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
/* Style page content - use this if you want to push the page content to the right when you open the side navigation */
#main {
transition: margin-left .5s;
padding: 20px;
}
.btmcontainer {
max-width: 1200px;
margin: 0 auto;
}
.social li {
float: right;
display: inline;
list-style: none;
}
.faqwtb a {
color: black;
padding-top: 50rem;
background-color: white;
padding: 20px;
position: relative;
float: left;
text-decoration: none;
border-radius: 25px 25px 25px 25px;
}
<!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>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="HomeCSS.css" rel="stylesheet" type="text/css" />
<link href="font.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" media="mediatype and|not|only (expressions)" href="print.css" />
<script src="GTech.js"></script>
</head>
<div id="page">
<body>
<header>
<img class="logo" src="Images/17622275_1491915637509717_1227569229_o.png" width="250" height="250" />
<div class="mainnav">
<button style="height:20px;width:120px;margin-left:90px">Notice</button>
<button class="divider" style="height:20px;width:120px">Products</button>
<div class="dropdown">
<button id="svc" style="height:20px;width:120px">Services</button>
<div id="submenu">
Help Center
<hr />
Service Center
</div>
</div>
<button class="divider2" style="height:20px;width:120px">About Us</button>
</div>
</header>
<div id="cart" class="scart">
<span onclick="openNav()">Shopping Cart</span>
</div>
<div id="mySidenav" class="sidenav">
×
About
Services
Clients
Contact
</div>
</body>
<footer>
<div class="btmcontainer">
<div class="faqwtb">
<span>FAQ</span>
<span>Where to Buy</span>
</div>
<div class="btmcol">
<ul class="social">
<li>
<img src="Images/footericon/facebook.png" />
</li>
<li>
<img src="Images/footericon/twitter.png" />
</li>
<li>
<img src="Images/footericon/google+.png" />
</li>
<li>
<img src="Images/footericon/tumblr.png" />
</li>
</ul>
</div>
</div>
</footer>
</div>
</html>
Change your CSS to this...
You have used position relative everywhere. Remove them. Get the position of footer in the correct place and then position your page components.
Check my fiddle: https://jsfiddle.net/mpriyam/s8xhr5wv/
CSS Should be...
body {
background-image: url(Images/Clean-Gray-BackGround-620x465.jpg);
background-repeat: repeat-x;
background-size: cover;
background-attachment: fixed;
margin: 0;
}
#page {
margin: 0px auto;
width: 1200px;
}
header {
height: 20px;
margin: 30px 0 0;
}
.mainnav {
padding-top: 50px;
width: 1200px;
}
button {
font-size: 20px;
font-family: 'Bungee';
text-align: center;
border: none;
background-color: transparent;
padding: 16px 16px 40px 0px;
}
.dropdown {
display: inline-block;
}
.divider {
margin-left: 100px;
margin-right: 260px;
}
.divider2 {
margin-left: 150px;
}
#submenu {
display: none;
background-color: transparen;
text-align: center;
min-width: 60px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
position: absolute;
}
#submenu a {
color: black;
padding: 0 0 40 0;
text-decoration: none;
display: block;
}
.dropdown:hover #submenu {
display: block;
}
.logo {
left: 45%;
margin: -48px 0 0 -98px;
}
#cart a {
/* Position them relative to the browser window */
right: -80px;
/* Position them outside of the screen */
transition: 0.3s;
/* Add transition on hover */
padding: 15px;
/* 15px padding */
width: 100px;
/* Set a specific width */
text-decoration: none;
/* Remove underline */
font-size: 20px;
/* Increase font size */
color: black;
/* White text color */
background-color: white;
border-radius: 15px 0px 0px 15px;
}
#cart a:hover {
right: 0;
text-decoration: none;
}
.sidenav {
height: 100%;
/* 100% Full-height */
width: 0;
/* 0 width - change this with JavaScript */
/* Stay in place */
z-index: 1;
/* Stay on top */
top: 0;
left: 0;
background-color: #111;
/* Black*/
overflow-x: hidden;
/* Disable horizontal scroll */
padding-top: 60px;
/* Place content 60px from the top */
transition: 0.5s;
/* 0.5 second transition effect to slide in the sidenav */
}
/* The navigation menu links */
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s
}
/* When you mouse over the navigation links, change their color */
.sidenav a:hover,
.offcanvas a:focus {
color: blanchedalmond;
}
/* Position and style the close button (top right corner) */
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
/* Style page content - use this if you want to push the page content to the right when you open the side navigation */
#main {
transition: margin-left .5s;
padding: 20px;
}
.btmcontainer {
max-width: 1200px;
clear:both;
margin: 0 auto;
}
.social li {
float: right;
display: inline;
list-style: none;
}
.faqwtb a {
color: black;
padding-top: 50rem;
background-color: white;
padding: 20px;
text-decoration: none;
border-radius: 25px 25px 25px 25px;
}

Why does background flicker on hover

I have the HTML and CSS below. When I hover the image it's opacity goes to zero and a background colour appears while the text goes from display:none to block. But why is there flickering when hovering the text? I have tried setting backface-visibility:hidden on all elements but it does not remove the flicker.
It happens in current Firefox & Chrome and IE11.
Here is codepen demo of the problem
<div class="project-card">
<img src="http://s13.postimg.org/tiwekrks7/dummy_small_1.jpg" height="250" width="380">
<div class="project-caption">
<div class="pc-name">Absolut Vodka</div>
<div class="pc-type">Bottle</div>
<div class="pc-task">Fancy text</div>
</div>
</div>
.project-card {
position: relative;
display: inline-block;
text-align: center;
max-width: 32%;
background-color: #0a3837;
}
.project-card p,
.project-card a,
.project-card img {
margin: 0;
}
.project-card a {
max-width: 100%;
line-height: 0;
}
.project-card a:hover {
opacity: 0.1;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.project-card a:hover + .project-caption {
display: block;
}
.project-caption {
display: none;
color: white;
font-size: 0.9rem;
padding: 0 3rem;
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.pc-name {
text-transform: uppercase;
padding-bottom: 5px;
margin-bottom: 5px;
border-bottom: 2px solid white;
}
.pc-type,
.pc-task {
font-style: italic;
}
Here a solution based on what Zeta said :
HTML
<div class="project-card">
<img src="http://s13.postimg.org/tiwekrks7/dummy_small_1.jpg" height="250" width="380">
<div class="project-caption">
<div class="pc-name">Absolut Vodka</div>
<div class="pc-type">Bottle</div>
<div class="pc-task">Fancy text</div>
</div>
</div>
CSS
.project-card {
position: relative;
display: inline-block;
text-align: center;
max-width: 32%;
background-color: #0a3837;
}
.project-card p,
.project-card a,
.project-card img {
margin: 0;
}
.project-card a {
max-width: 100%;
line-height: 0;
}
.project-card:hover > a{
opacity: 0.1;
}
.project-card:hover > a + .project-caption {
display: block;
}
.project-caption {
display: none;
color: white;
font-size: 0.9rem;
padding: 0 3rem;
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.pc-name {
text-transform: uppercase;
padding-bottom: 5px;
margin-bottom: 5px;
border-bottom: 2px solid white;
}
.pc-type,
.pc-task {
font-style: italic;
}
And the fiddle : https://jsfiddle.net/rf09bsse/

Resources