The sidebyside nav now displays something but shortens the original menu-text to only text-length (it should take the whole line). The links in the top line should be displayed next to each other but w/o boxes. I've tried everything w/o success. I want to do my code with as little scripting as possible, only HTML and CSS if possible.
body {
font-family: "Lato", sans-serif;
}
h1 {
font-size: xxx-large;
text-align: center;
text-decoration: underline;
}
h4 {
font-size: large;
text-align: center;
text-decoration: underline;
background-color: cyan;
border-width: 1px;
border-style: solid;
border-color: #f00000;
margin-top: 0;
margin-bottom: 0;
}
.sidenav {
height: 100%;
<!-- width: 20%;
-->position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: transparent;
overflow-x: hidden;
}
.sidenav a {
padding: 5px;
text-decoration: none;
border-width: 1px;
border-style: solid;
border-color: #f00000;
font-size: medium;
padding: 1 em 2 em;
color: #000000;
display: block;
}
.sidenav a:hover {
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
margin-top: 0;
right: 0px;
font-size: medium;
margin-left: 50px;
border: none;
}
#media screen and (max-height: 450px) {
.sidenav {
padding-top: 15px;
}
.sidenav a {
font-size: 18px;
}
}
/* Dropdown Button */
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
#wrapper {
width: 100%;
height: 100%;
overflow-y: hidden;
overflow-x: visible;
}
.menu {
background-color: #a0a0a0;
width: 20%;
height: 100%;
float: left;
overflow: hidden;
}
#main {
background-color: #00a000;
width: 80%;
height: 100%;
float: left;
overflow: hidden;
border: none;
}
#elf {
background-color: #0000c0;
color: #a0a0a0;
font-weight: bold;
}
#elf:hover {
background-color: #0000e0;
color: #c0c0c0;
font-weight: bold;
}
#divine {
background-color: #a000a0;
color: #c0c000;
font-weight: bold;
width;
100%;
min-width: 100%;
}
#divine:hover {
background-color: #c000c0;
color: #f0f000;
font-weight: bold;
width: 100%;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
border-width: 1px;
border-style: solid;
border-color: #0000f0;
min-width: 300px;
margin-left: 100%;
z-index: 3;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
border-width: 1px;
border-style: solid;
border-color: #000000;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
/* Change color of dropdown links on hover */
.divine-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.divine:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.divine:hover .dropbtn {
background-color: #3e8e41;
}
.divine-content {
display: none;
position: absolute;
background-color: #f1f1f1;
border-width: 1px;
border-style: solid;
border-color: #0000f0;
min-width: 300px;
margin-left: 100%;
z-index: 3;
}
.divine-content+a {
color: black;
border-width: 1px;
border-style: solid;
border-color: #000000;
padding: 12px 16px;
text-decoration: none;
z-index: 3;
}
.size {
display: inline;
color: black;
background-color: red;
text-align: center;
}
/* Change color of dropdown links on hover */
#divine-content+a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
#divine:hover+.divine-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
#divine:hover .dropbtn {
background-color: #3e8e41;
}
<h1>Thyra Kristin Lang<br></h1>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<!-- </div> -->
<div id="wrapper">
<div class="menu" background-color="005000">
<div id="mySidenav" class="sidenav">
<h4>Hauptmenü</h4>
<table class="size">
<tr>
<td><a style="text-size:normal padding-right: 2 em" onclick="javascript:normal()" border="0">A </a>
<td><a style="text-size:large padding-right: 2 em border-style: none;" onclick="javascript:large()">A</a></td>
<td><a style="text-size:x-large padding-right: 2 em" onclick="javascript:xlarge()">A</a></td>
</tr>
</table>
<div>Lebenslauf</div>
<div>Werkeverzeichnis</div>
<div class="dropdown">Divine
<div class="divine-content">
Link 1
Link 2
Link 3
</div>
</div>
Elfenblut
Gedichte
<br>
</div>
</div>
<iframe id="main" name="main" src="willkommen.html" background-color="005000">blub</iframe>
</div>
Try using display:inline-block it will make all elements displayed on a block and use margin or padding to separate them.
A couple things: Only one element should have an specific value for id. The id is unique per element. Styling element inline and externally can sometimes make it difficult to troubleshoot a problem. My personal preference is one or the other except in certain cases.
The question may need more details. Here's what I think you want using flex I was able to position the links next to each other and the take up the whole line without boxes.
body {
font-family: "Lato", sans-serif;
}
h1 {
font-size: xxx-large; text-align: center; text-decoration: underline; }
h4 {
font-size: large; text-align: center; text-decoration: underline; background-color: cyan;
border-width: 1px;
border-style: solid;
border-color: #f00000;
margin-top: 0;
margin-bottom: 0;
}
.sidenav {
height: 100%;
<!-- width: 20%; -->
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: transparent;
overflow-x: hidden;
}
#mySidenav1 {
display: flex;
flex-direction: row;
justify-content: space-evenly;
}
.sidenav a {
padding: 5px;
text-decoration: none;
border-width: 1px;
border-style: solid;
border-color: #f00000;
font-size: medium;
padding: 1 em 2 em;
color: #000000;
display: block;
}
.sidenav a:hover {
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
margin-top: 0;
right: 0px;
font-size: medium;
margin-left: 50px;
border: none;
}
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
/* Dropdown Button */
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
#wrapper {
width: 100%;
height: 100%;
overflow-y: hidden;
overflow-x: visible;
}
.menu {
background-color: #a0a0a0; width: 20%; height: 100%; float:left; overflow:hidden;
}
#main {
background-color: #00a000; width: 80%; height: 100%; float:left; overflow:hidden; border: none;
}
#elf {
font-weight: bold;
}
#elf:hover {
background-color: #0000e0;
color: #c0c0c0;
font-weight: bold;
}
#divine {
font-weight: bold;
}
#divine:hover {
background-color: #c000c0;
color: #f0f000;
font-weight: bold;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
border-width: 1px;
border-style: solid;
border-color: #0000f0;
min-width: 300px;
margin-left: 100%;
z-index: 3;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
border-width: 1px;
border-style: solid;
border-color: #000000;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {background-color: #3e8e41;}
/* Change color of dropdown links on hover */
.divine-content a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
.divine:hover .dropdown-content {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
.divine:hover .dropbtn {background-color: #3e8e41;}
.divine-content {
display: none;
position: absolute;
background-color: #f1f1f1;
border-width: 1px;
border-style: solid;
border-color: #0000f0;
min-width: 300px;
margin-left: 100%;
z-index: 3;
}
.divine-content + a {
color: black;
border-width: 1px;
border-style: solid;
border-color: #000000;
padding: 12px 16px;
text-decoration: none;
z-index: 3;
}
.size {
display: inline;
color: black;
background-color: red;
text-align: center;
}
/* Change color of dropdown links on hover */
#divine-content + a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
#divine:hover + .divine-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
#divine:hover .dropbtn {background-color: #3e8e41;}
<h1>Thyra Kristin Lang<br></h1>
<div id="mySidenav1" class="sidenav1">
x
Lebenslauf
Werkeverzeichnis
Divine
Elfenblut
Gedichte
<br>
</div>
<br>
<!-- <h2>Sidenav Example</h2>
<p>Click on the element below to open the side navigation menu.</p> -->
<!-- <span id="MyButton" style="font-size:medium; cursor:pointer;" onclick="openNav()">Hauptmenü öffnen</span> -->
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<!-- </div> -->
<div id="wrapper">
<div class="menu" background-color="005000">
<div id="mySidenav" class="sidenav">
<h4>Hauptmenü</h4>
<table class="size">
<tr>
<td><a style="text-size:normal padding-right: 2 em" onclick="javascript:normal()" border="0">A </a></td>
<td><a style="text-size:large padding-right: 2 em border-style: none;" onclick="javascript:large()">A</a></td>
<td><a style="text-size:x-large padding-right: 2 em" onclick="javascript:xlarge()">A</a></td>
</tr>
</table>
<div>Lebenslauf</div>
<div>Werkeverzeichnis</div>
<div class="dropdown">Divine
<div class="divine-content">
Link 1
Link 2
Link 3
</div>
</div>
Elfenblut
Gedichte
<br>
</div>
</div>
<iframe id="main" name="main" src="willkommen.html" background-color="005000">blub</iframe>
</div>
Related
I'm working on a website for my friend. If you're interested in the full source code, you can see it here. Currently, our div dropdown navbar elements are a different height and y position than our a hyperlink navbar elements, despite having nearly identical CSS applied to them.
Here's my code (appears to have messier spacing than our actual code because I just copied parts of it):
/* formatting of links */
p, a {
color: #5e2800;
font-family: courier;
font-size: 15px;
}
a {
color: brown;
text-decoration: none;
}
li {
color: #5e2800;
font-family: courier;
font-size: 13px;
}
.nav {
color: brown;
font-family: courier;
font-size: 15px;
overflow: hidden;
white-space: nowrap;
display: inline-block;
}
/* search bar */
.topnav input[type="text"] {
float: right;
padding: 6px;
margin-top: 8px;
margin-right: 16px;
border: none;
font-size: 10px;
}
/* dropdown */
.dropdown {
overflow: hidden;
white-space: nowrap;
display: inline-block;
}
.dropdown .dropbtn {
color: brown;
font-family: courier;
font-size: 15px;
border: none;
outline: none;
color: inherit;
margin: 0;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="nav">
Information
Gallery
<div class="dropdown">
<button class="dropbtn">
Members
</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<div class="dropdown">
<button class="dropbtn">
Events
</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
Contact
<div class="topnav">
<input type="text" placeholder="Search">
</div>
</div>
So far, we've tried to make the dropdown elements convert to also be a tags, but this had no effect.
The little bit of Googling I did seems to indicate that using overflow: hidden "can" change the baseline of an element, so removing overflow: hidden; from .dropdown fixes that if your overall design will tolerate that.
/* formatting of links */
p, a {
color: #5e2800;
font-family: courier;
font-size: 15px;
}
a {
color: brown;
text-decoration: none;
}
li {
color: #5e2800;
font-family: courier;
font-size: 13px;
}
.nav {
color: brown;
font-family: courier;
font-size: 15px;
overflow: hidden;
white-space: nowrap;
display: inline-block;
}
/* search bar */
.topnav input[type="text"] {
float: right;
padding: 6px;
margin-top: 8px;
margin-right: 16px;
border: none;
font-size: 10px;
}
/* dropdown */
.dropdown {
/* overflow: hidden; <--------- Remove this */
white-space: nowrap;
display: inline-block;
}
.dropdown .dropbtn {
color: brown;
font-family: courier;
font-size: 15px;
border: none;
outline: none;
color: inherit;
margin: 0;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="nav">
Information
Gallery
<div class="dropdown">
<button class="dropbtn">
Members
</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<div class="dropdown">
<button class="dropbtn">
Events
</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
Contact
<div class="topnav">
<input type="text" placeholder="Search">
</div>
</div>
I am trying to get a side dropdown menu on hover, but nothing I tried thus far had any effect apart from shortening the containing div to just text.length. What am I doing wrong? Besides, I want to use as little scripting as possible, possibly only HTML and CSS.
Here comes the code...
<html>
<head>
<title>Thyra Kristin Lang</title>
<style>
body {
font-family: "Lato", sans-serif;
}
h1 {
font-size: xxx-large; text-align: center; text-decoration: underline; }
h4 {
font-size: large; text-align: center; text-decoration: underline; background-color: cyan;
border-width: 1px;
border-style: solid;
border-color: #f00000;
margin-top: 0;
margin-bottom: 0;
}
.sidenav {
height: 100%;
<!-- width: 20%; -->
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: transparent;
overflow-x: hidden;
}
.sidenav a {
padding: 5px;
text-decoration: none;
border-width: 1px;
border-style: solid;
border-color: #f00000;
font-size: medium;
padding: 1 em 2 em;
color: #000000;
display: block;
}
.sidenav a:hover {
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
margin-top: 0;
right: 0px;
font-size: medium;
margin-left: 50px;
border: none;
}
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
/* Dropdown Button */
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
#wrapper {
width: 100%;
height: 100%;
overflow-y: hidden;
overflow-x: visible;
}
.menu {
background-color: #a0a0a0; width: 20%; height: 100%; float:left; overflow:hidden;
}
#main {
background-color: #00a000; width: 80%; height: 100%; float:left; overflow:hidden; border: none;
}
#elf {
background-color: #0000c0;
color: #a0a0a0;
font-weight: bold;
}
#elf:hover {
background-color: #0000e0;
color: #c0c0c0;
font-weight: bold;
}
#divine {
background-color: #a000a0;
color: #c0c000;
font-weight: bold;
width;100%;
min-width: 100%
}
#divine:hover {
background-color: #c000c0;
color: #f0f000;
font-weight: bold;
width: 100%;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
border-width: 1px;
border-style: solid;
border-color: #0000f0;
min-width: 300px;
margin-left: 100%;
z-index: 3;
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
border-width: 1px;
border-style: solid;
border-color: #000000;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {background-color: #3e8e41;}
/* Change color of dropdown links on hover */
.divine-content a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
.divine:hover .dropdown-content {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
.divine:hover .dropbtn {background-color: #3e8e41;}
.divine-content {
display: none;
position: absolute;
background-color: #f1f1f1;
border-width: 1px;
border-style: solid;
border-color: #0000f0;
min-width: 300px;
margin-left: 100%;
z-index: 3;
}
.divine-content + a {
color: black;
border-width: 1px;
border-style: solid;
border-color: #000000;
padding: 12px 16px;
text-decoration: none;
display: inline; important!;
}
/* Change color of dropdown links on hover */
#divine-content a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
#divine:hover .divine-content {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
#divine:hover .dropbtn {background-color: #3e8e41;}
</style>
</head>
<body>
<h1>Thyra Kristin Lang<br></h1>
<!-- <div width="20%">
<div id="mySidenav" class="sidenav">
x
Lebenslauf
Werkeverzeichnis
Divine
Elfenblut
Gedichte
<br>
</div> -->
<!-- <h2>Sidenav Example</h2>
<p>Click on the element below to open the side navigation menu.</p> -->
<!-- <span id="MyButton" style="font-size:medium; cursor:pointer;" onclick="openNav()">Hauptmenü öffnen</span> -->
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<!-- </div> -->
<div id="wrapper">
<div class="menu" background-color="005000">
<div id="mySidenav" class="sidenav">
<h4>Hauptmenü</h4>
<div>Lebenslauf</div>
<div>Werkeverzeichnis</div>
<div class="dropdown">Divine
<div class="divine-content">
Link 1
Link 2
Link 3
</div>
</div>
Elfenblut
Gedichte
<br>
</div>
</div>
<iframe id="main" name="main" src="willkommen.html" background-color="005000">blub</iframe>
</div>
</body>
</html>
Hey there and welcome to StackOverflow, I wrote some code that seems to answer your question. Essentially what you're aiming to do is display a container on hover of a separate container. Try using the :hover event and the adjacent selector via css, this snippet achieves what you are looking for:
CSS
[name="divine"]:hover + .divine-content {
display: block;
}
notice the :hover event is being placed on your dropdown element and the + sign selector is used because the container you are attempting to show is adjacent to the element you are hovering over.
Codepen
I have tried to follow this tutorial, but I can't seem to find out why the dropdown menu won't show up at all when hovering over the dropdown button in the nav bar.
This is the HTML part of the code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css'>
</head>
<body>
<div id="main-container">
<div id="navbar" class="navbar">
New
Sales
Account
<div class="dropdown">
<button class="dropbtn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</div>
<h3>Dropdown Menu inside a Navigation Bar</h3>
<p>Hover over the "Dropdown" link to see the dropdown menu.</p>
</div>
</body>
</html>
This is the CSS part of the code:
html {
height: 100%;
}
body {
margin: 0;
height: 100%;
font-family: "Poppins", sans-serif;
background-color: #00ff00;
}
#main-container {
padding: 16px;
margin-top: 30px;
}
#navbar {
overflow: hidden;
background-color: #333;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 30px;
z-index: 9999;
}
#navbar a.active {
text-decoration: underline;
}
.navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.new_sale {
background-color: green;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
.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;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
The problem is that you are hiding the content which goes over the boundaries of your navbar and dropdown.
You need to remove
overflow: hidden;
from your #navbar and .dropdown class, check this fiddle
I have a drop-down cart button in my application with the following html, in which I control the fact that it is displayed by a class variable in javascript. I'd like it to also display when the mouse passes the button, and looking for information I've only found a couple of examples that do it in css as I show below.
<div class="action-wrapper">
<button class='cart d-flex justify-content-center align-items-center p-0 m-0' (click)='toggleCart()'>
<i class='icon-addcart'></i>
<p *ngIf='itemsQuantity !== 0'>{{itemsQuantity}}</p>
</button>
<div class="dropdown" [ngClass]="{'disable': toggle}">
<div class='empty' *ngIf='itemsQuantity === 0'>
<a class='empty-title p-0 m-0'>No items</a>
</div>
<div class='group' *ngFor='let item of cart'>
<div class='first-row' *ngIf='itemsQuantity !== 0'>
<a class='title-group'>{{item.title}</a>
<i class='icon-trash-o' (click)='deleteItem(item)'></i>
</div>
<div class='last-row' *ngIf='itemsQuantity !== 0'>
<a class='quantity'>{{item.quantity | digitsFormat}}</a>
<span class='price-group' [innerHTML]='item.price | currencyFormat'></span>
</div>
</div>
<div class='action' *ngIf='itemsQuantity !== 0'>
<ciev-button label='shop' (click)='viewDetails()'></ciev-button>
</div>
</div>
</div>
on my css I'm trying to access the dropdown with the button class but I don't see a way to do it
.cart {
background-color: $quinaryColor;
border: none;
border-radius: 5px;
color: $primaryColor;
font-size: 16px;
width: 233px;
height: 53px;
line-height: 0px;
cursor: pointer;
margin-left: 10px;
.icon-addcart {
color: $primaryColor;
font-size: 30px;
}
p {
display: flex;
justify-content: center;
align-items: center;
font-size: 9px;
// font-weight: 600;
background-color: $duodenaryColor;
width: 17px;
height: 17px;
border-radius: 10px;
border: 1px solid $primaryColor;
margin-top: -4px;
margin-left: -14px;
}
span {
margin-left: 10px;
}
&:hover{
background-color: $duodenaryColor;
cursor: pointer;
.dropdown {
display: block;
}
}
&:focus {
outline: none;
}
&:disabled {
background: $secondaryColor;
cursor: not-allowed;
}
}
.dropdown {
list-style: none;
position: absolute;
background-color: $primaryColor;
border: 1px solid $secondaryColor;
box-sizing: border-box;
box-shadow: 1px 1px 4px rgba(35, 50, 64, 0.2);
border-radius: 5px;
padding: 20px;
width: 281px;
max-height: 450px;
overflow: auto;
margin: 0.6% 0 0 -2%;
&::-webkit-scrollbar {
width: 1px;
}
&.disable {
display: none;
}
.group {
border-bottom: 1px solid $uiFooterColor;
padding: 8px;
}
.empty {
display: flex;
justify-content: center;
.empty-title {
font-weight: 600;
font-size: 12px;
line-height: 19px;
color: $quaternaryColor;
margin-bottom: 10px;
}
}
.first-row {
display: flex;
justify-content: space-between;
margin: 0 0 5px 0;
}
.last-row {
display: flex;
justify-content: space-between;
margin-bottom: -20px;
}
.title-group {
font-weight: 600;
font-size: 13px;
line-height: 19px;
color: $quaternaryColor;
}
.name {
font-weight: 600;
font-size: 13px;
line-height: 19px;
color: $quaternaryColor;
}
.quantity {
font-size: 13px;
line-height: 19px;
color: $octonaryColor;
border: none;
margin-left: -60px;
}
.price-group {
font-size: 12px;
line-height: 19px;
text-align: right;
color: $octonaryColor;
.ordinal {
color: $octonaryColor !important;
}
}
.icon-trash-o {
color: $quinaryColor;
cursor: pointer;
}
.action {
margin-top: 5px;
// position: sticky;
// bottom: 0;
}
}
is it possible to make it deploy with the css having it already controlled with javascript?
HTML
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
CSS
/* Dropdown Button */
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
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 {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd;}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {display: block;}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {background-color: #3e8e41;}
I've been working on a very simple navbar for the last two days, just a with a few buttons inside, one of which is supposed to show a dropdown menu. I've set all my paddings with % and for the most part they work, except for the div containing the button that shows the dropdown menu.
/* all fonts are using vw units as it makes it easier to spot the phantom top-padding */
header {
background-color: #101010;
}
header h1 {
color: #ffffff;
margin: 0px;
text-align: center;
font-family: "Barlow Condensed";
font-size: 7vw;
padding: 1%;
}
body {
margin: 0px;
background-color: #f0f0f0
}
ul, ol {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
content {
width: 100%;
clear: both;
}
nav {
background-color: #999999;
overflow: hidden;
font-family: "Barlow condensed";
outline: none;
border: 0px;
}
.dropdown:hover, .dropbtn {
background-color: red;
}
/* This contains the dropdown */
.dropdown {
float: left;
overflow: hidden;
padding: 1.5%;
}
/* This is the button */
.dropdown .dropbtn {
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
padding: 1.5%;
background-color: inherit;
font-family: inherit;
margin: 0%;
}
/* Dropdown contents */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 10%;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
margin-top: 1.5%;
margin-left: -1.5%;
}
/* links inside the dropdown */
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
float: none;
font-size: 1.1vw;
padding: 2%;
}
/* background color for links inside the dropdown (hover) */
.dropdown-content a:hover {
background-color: #ddd;
}
/* shows the dropdown on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Other buttons in the nav bar, working as intended. */
.botons {
float: left;
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
padding: 1.5%;
background-color: inherit;
font-family: inherit;
margin: 0;
text-decoration: none;
}
.botons a {
float: left;
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
background-color: inherit;
font-family: inherit;
margin: 0;
text-decoration: none;
}
.botons:hover {
float: left;
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
padding: 1.5%;
background-color: red;
font-family: inherit;
margin: 0;
text-decoration: none;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="estil-index.css">
<link href='https://fonts.googleapis.com/css?family=Barlow Condensed' rel='stylesheet'>
<link rel="icon" type="image/png" href="logo.png"
<meta charset="UTF-8">
<meta name="viewport" content="widht=devide-width, initial-scale=1">
</head>
<body>
<header><h1>Big header text</h1></header>
<content>
<nav>
<button class="botons">Home</button>
<div class="dropdown">
<button class="dropbtn">Dropdown
<div class="dropdown-content">
Link 1
Link 2
Link 3
Link 4
</div>
</button>
</div>
<button class="botons">Regular button</button>
<button class="botons">Button</button>
<button class="botons">Button</button>
</nav>
</body>
As you can see, the .dropdown div (or maybe the button inside) is behaving erratically and instead of having a % padding like I specified everywhere, it sems to have a px padding, only on top, that grows in size as the screen becomes smaller or if zoomed in.
I've sent the code to several peers and friends who are as stumped as I am, especially by the fact that the phantom padding only appears on the top side.
A bit tricky to explain but basically it's due to the fact the button is not made float as the a elements and there is the default line-height that define the height of the line box which will be bigger when the font-size get smaller. So the phatom padding is the height of the line box defined by the line-height.
An easy fix it to make the button floating like the links thus it will be a block level element and no more an inline level element.
/* all fonts are using vw units as it makes it easier to spot the phantom top-padding */
header {
background-color: #101010;
}
header h1 {
color: #ffffff;
margin: 0px;
text-align: center;
font-family: "Barlow Condensed";
font-size: 7vw;
padding: 1%;
}
body {
margin: 0px;
background-color: #f0f0f0
}
ul,
ol {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
content {
width: 100%;
clear: both;
}
nav {
background-color: #999999;
overflow: hidden;
font-family: "Barlow condensed";
outline: none;
border: 0px;
}
.dropdown:hover,
.dropbtn {
background-color: red;
}
/* This contains the dropdown */
.dropdown {
float: left;
overflow: hidden;
padding: 1.5%;
}
/* This is the button */
.dropdown .dropbtn {
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
padding: 1.5%;
background-color: inherit;
font-family: inherit;
margin: 0%;
float: left;
}
/* Dropdown contents */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 10%;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
margin-top: 1.5%;
margin-left: -1.5%;
}
/* links inside the dropdown */
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
float: none;
font-size: 1.1vw;
padding: 2%;
}
/* background color for links inside the dropdown (hover) */
.dropdown-content a:hover {
background-color: #ddd;
}
/* shows the dropdown on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Other buttons in the nav bar, working as intended. */
.botons {
float: left;
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
padding: 1.5%;
background-color: inherit;
font-family: inherit;
margin: 0;
text-decoration: none;
}
.botons a {
float: left;
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
background-color: inherit;
font-family: inherit;
margin: 0;
text-decoration: none;
}
.botons:hover {
float: left;
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
padding: 1.5%;
background-color: red;
font-family: inherit;
margin: 0;
text-decoration: none;
}
<link href='https://fonts.googleapis.com/css?family=Barlow Condensed' rel='stylesheet'>
<header>
<h1>Big header text</h1>
</header>
<content>
<nav>
<button class="botons">Home</button>
<div class="dropdown">
<button class="dropbtn">Dropdown
<div class="dropdown-content">
Link 1
Link 2
Link 3
Link 4
</div>
</button>
</div>
<button class="botons">Regular button</button>
<button class="botons">Button</button>
<button class="botons">Button</button>
Or reduce the line-height and adjust vertical-align to top:
/* all fonts are using vw units as it makes it easier to spot the phantom top-padding */
header {
background-color: #101010;
}
header h1 {
color: #ffffff;
margin: 0px;
text-align: center;
font-family: "Barlow Condensed";
font-size: 7vw;
padding: 1%;
}
body {
margin: 0px;
background-color: #f0f0f0
}
ul,
ol {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
content {
width: 100%;
clear: both;
}
nav {
background-color: #999999;
overflow: hidden;
font-family: "Barlow condensed";
outline: none;
border: 0px;
}
.dropdown:hover,
.dropbtn {
background-color: red;
}
/* This contains the dropdown */
.dropdown {
float: left;
overflow: hidden;
padding: 1.5%;
line-height: 0;
}
/* This is the button */
.dropdown .dropbtn {
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
padding: 1.5%;
background-color: inherit;
font-family: inherit;
margin: 0%;
vertical-align:top;
}
/* Dropdown contents */
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 10%;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
margin-top: 1.5%;
margin-left: -1.5%;
}
/* links inside the dropdown */
.dropdown-content a {
color: black;
text-decoration: none;
display: block;
float: none;
font-size: 1.1vw;
padding: 2%;
}
/* background color for links inside the dropdown (hover) */
.dropdown-content a:hover {
background-color: #ddd;
}
/* shows the dropdown on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Other buttons in the nav bar, working as intended. */
.botons {
float: left;
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
padding: 1.5%;
background-color: inherit;
font-family: inherit;
margin: 0;
text-decoration: none;
}
.botons a {
float: left;
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
background-color: inherit;
font-family: inherit;
margin: 0;
text-decoration: none;
}
.botons:hover {
float: left;
font-size: 1.2vw;
border-style: none;
border-width: 0px;
outline: none;
color: white;
padding: 1.5%;
background-color: red;
font-family: inherit;
margin: 0;
text-decoration: none;
}
<link href='https://fonts.googleapis.com/css?family=Barlow Condensed' rel='stylesheet'>
<header>
<h1>Big header text</h1>
</header>
<content>
<nav>
<button class="botons">Home</button>
<div class="dropdown">
<button class="dropbtn">Dropdown
<div class="dropdown-content">
Link 1
Link 2
Link 3
Link 4
</div>
</button>
</div>
<button class="botons">Regular button</button>
<button class="botons">Button</button>
<button class="botons">Button</button>
</nav>