I have tried to embed a vertical menu bar on my Blogger website. But it seems like it's not responsive and the colour is not matching my website.
I need to remove the shadow and make the website responsive in mobile.
My website's background colour is white: https://codemyquestion.blogspot.com/
This is how it is opened:
This is the expected output:
Below is the code:
<style>
.ddsmoothmenu-v ul {
margin: 0;
padding: 0;
width: 130px;
/* Main Menu Item widths */
list-style-type: none;
font: bold 12px Verdana;
border-bottom: 0px solid #ccc;
}
.ddsmoothmenu-v ul li {
position: relative;
}
.downarrowclass {
position: absolute;
top: 12px;
right: 7px;
}
.rightarrowclass {
position: absolute;
top: 10px;
right: 5px;
}
/* Top level menu links style */
.ddsmoothmenu-v ul li a {
display: block;
overflow: auto;
/*force hasLayout in IE7 */
height: 32px;
color: white;
text-decoration: none;
padding: 5px 5px 5px 25px;
border-bottom: 0px solid #778;
border-right: 0px solid #778;
}
.ddsmoothmenu-v ul li a:link, .ddsmoothmenu-v ul li a:visited, .ddsmoothmenu-v ul li a:active {
color: white;
background-image: url(http://3.bp.blogspot.com/-VCtcZunZJ2U/T9W7MM1uIXI/AAAAAAAAB9o/yVJ0Cad3Q0g/s1600/tab_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
margin-bottom: 1px;
}
.ddsmoothmenu-v ul li a.selected {
/*CSS class that's dynamically added to the currently active menu items' LI A element*/
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
.ddsmoothmenu-v ul li a:hover {
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
/*Sub level menu items */
.ddsmoothmenu-v ul li ul {
position: absolute;
width: 170px;
/*Sub Menu Items width */
height: 22px;
top: 0;
font-weight: normal;
visibility: hidden;
}
/* Holly Hack for IE \*/
* html .ddsmoothmenu-v ul li {
float: left;
height: 1%;
}
* html .ddsmoothmenu-v ul li a {
height: 1%;
}
/*======= Vertical Drop Down Menu By Helper Blogger ========= */
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="http://helperblogger.ucoz.com/code/hb-smooth-menu.js"></script>
<script type="text/javascript">
})
</script>
<script type="text/javascript">
ddsmoothmenu.init({
mainmenuid: "smoothmenu2",
//Menu DIV id
orientation: 'v',
//Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu-v',
//class added to menu's outer DIV
//customtheme: ["#804000", "#482400"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})
</script>
<div id="smoothmenu2" class="ddsmoothmenu-v">
<ul>
<li>
Home
</li>
<li>
Folder 0
<ul>
<li>
Sub Item 1.1
</li>
<li>
Sub Item 1.2
</li>
</ul>
</li>
<li>
Folder 1
<ul>
<li>
Sub Item 1.1
</li>
<li>
Sub Item 1.2
</li>
</ul>
</li>
<li>
Item 3
</li>
<li>
Folder 2
<ul>
<li>
Sub Item 2.1
</li>
</ul>
</li>
<li>
Create This
</li>
</ul>
<br style="clear: left" />
</div>
the black white nav menu:
HTML
<div class="sidenav">
<i class="fa fa-home"></i> About
<i class="fa fa-home"></i> Services
<i class="fa fa-home"></i> Clients
<i class="fa fa-home"></i> Contact
<div href="#" class="dropdown-btn">
<i class="fa fa-home"></i>
<i class="fa fa-caret-right"></i>Dropdown
<div class="dropdown-container">
Link 1
Link 2
Link 3
</div>
</div>
<i class="fa fa-home"></i> Search
</div>
CSS
.sidenav {
height: 100%;
width: 58px;
position: relative;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
padding: 20px 0;
white-space: nowrap;
overflow-x:hidden;
transition: all 0.2s ease-in-out;
}
.sidenav:hover {
width: 200px;
overflow-x:visible;
}
.sidenav .fa:not(.fa-caret-right){
margin-right:20px;
}
.sidenav a, .dropdown-btn {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
border: none;
background: none;
width: 100%;
text-align: left;
cursor: pointer;
outline: none;
}
.sidenav a:hover, .dropdown-btn:hover {
color: #f1f1f1;
position:relative;
}
.dropdown-btn:hover .dropdown-container{
display:block;
}
.dropdown-container {
display: none;
background-color: #262626;
padding-left: 8px;
position:absolute;
width:200px;
left:100%;
margin-top:-30px;
}
.fa-caret-right {
float: right;
padding-right: 8px;
display:none !important;
}
the sub-menu opens to the right side, if you want to open it from the left side use this code:
HTML
<div class="sidenav">
<i class="fa fa-home"></i> About
<i class="fa fa-home"></i> Services
<i class="fa fa-home"></i> Clients
<i class="fa fa-home"></i> Contact
<div href="#" class="dropdown-btn">
<i class="fa fa-home"></i>
Dropdown
<i class="fa fa-caret-left"></i>
<div class="dropdown-container">
Link 1
Link 2
Link 3
</div>
</div>
<i class="fa fa-home"></i> Search
</div>
CSS
.sidenav {
direction:rtl;
height: 100%;
width: 58px;
position: relative;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
padding: 20px 0;
white-space: nowrap;
overflow-x:hidden;
transition: all 0.2s ease-in-out;
}
.sidenav:hover {
width: 200px;
overflow-x:visible;
}
.sidenav .fa:not(.fa-caret-left){
margin-left:20px;
}
.sidenav a, .dropdown-btn {
padding: 6px 16px 6px 8px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
border: none;
background: none;
width: 100%;
text-align: right;
cursor: pointer;
outline: none;
}
.sidenav a:hover, .dropdown-btn:hover {
color: #f1f1f1;
position:relative;
}
.dropdown-btn:hover .dropdown-container{
display:block;
}
.dropdown-container {
display: none;
background-color: #262626;
padding-right: 8px;
position:absolute;
width:200px;
right:100%;
margin-top:-30px;
}
.fa-caret-right {
float: left;
display:none !important;
}
Funny, I recently made my online web-game mobile responsive too. I can help:
The problem is px. Don't use px for mobile websites. Instead, use percent (%) or viewport-width (vw) these will make it so the elements will resize to the browser size.
Absolute positioning. It will override the width of the page if the elements are not inside a div. If it's in a div, It'll not follow the width of that div. Instead, use position: relative because this is relative to the width or height of the viewport page.
Try resizing your browser on your laptop/desktop, and notice the elements match. Next:
Use the CSS3 max-width property so on laptop, it'll look fine. But on mobile devices it'll probably look like a smaller version of the desktop sized screen. For example:
will look the same on a mobile device but smaller.
Now, finally, you can use: <meta> HTML tag. It definitely works on texts, images, Etc. Here's how:
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
use these tricks and your website is ready for mobile devices.
Edit: I saw your website. Everything looks fine on my laptop.
What exactly is wrong?
you just need to make some changes in your style
<style>
.ddsmoothmenu-v ul {
margin: 0;
padding: 0;
width: 130px;
/* Main Menu Item widths */
list-style-type: none;
font: bold 12px Verdana;
border-bottom: 0px solid #ccc;
}
.ddsmoothmenu-v ul li {
position: relative;
}
.downarrowclass {
position: absolute;
top: 12px;
left: 7px;
transform:rotateY(180deg); /* change the right arrow to left arrow */
}
.rightarrowclass {
position: absolute;
top: 10px;
left: 5px;
transform:rotateY(180deg); /* change the right arrow to left arrow */
}
/* Top level menu links style */
.ddsmoothmenu-v ul li a {
display: block;
overflow: auto;
/*force hasLayout in IE7 */
height: 32px;
color: white;
text-decoration: none;
padding: 5px 5px 5px 25px;
border-bottom: 0px solid #778;
border-right: 0px solid #778;
}
.ddsmoothmenu-v ul li a:link, .ddsmoothmenu-v ul li a:visited, .ddsmoothmenu-v ul li a:active {
color: white;
background-image: url(http://3.bp.blogspot.com/-VCtcZunZJ2U/T9W7MM1uIXI/AAAAAAAAB9o/yVJ0Cad3Q0g/s1600/tab_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
margin-bottom: 1px;
}
.ddsmoothmenu-v ul li a.selected {
/*CSS class that's dynamically added to the currently active menu items' LI A element*/
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
.ddsmoothmenu-v ul li a:hover {
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
/*Sub level menu items */
.ddsmoothmenu-v ul li ul {
position: absolute;
width: 170px;
/*Sub Menu Items width */
height: 22px;
top: 0;
font-weight: normal;
visibility: hidden;
left:-170px !important; /* move the sub-menu to the left */
box-shadow:none !important; /* remove the shadow */
}
/* Holly Hack for IE \*/
* html .ddsmoothmenu-v ul li {
float: left;
height: 1%;
}
* html .ddsmoothmenu-v ul li a {
height: 1%;
}
/*======= Vertical Drop Down Menu By Helper Blogger ========= */
</style>
Related
I am writing a navigation bar with a dropdown option.
I have 2 problems: I can't get the dropdown to position properly under the menu, + also when I try to move the mouse to click on the elements in the dropdown submenu it closes as soon as I move.
Can anyone suggest a fix?
Thanks
On codepen:
https://codepen.io/-royqooe/pen/GRxaVbm
/* CSS section for home */
.navtop {
position: relative;
background-color: #333333;
height: 50px;
width: 100%;
border: 0;
}
.navtop div {
display: flex;
margin: 0 auto;
height: 100%;
}
.navtop div h1,
.navtop div a {
display: inline-flex;
align-items: center;
}
.navtop div h1 {
flex: 1;
font-size: 24px;
padding: 0;
margin: 0;
margin-left: 2%;
color: #f5f8ff;
font-weight: normal;
}
.navtop div a {
padding: 0 12px;
text-decoration: none;
color: #c1c4c8;
font-weight: bold;
}
.navtop div a i {
padding: 2px 8px 0 0;
}
.navtop div a:hover {
color: #66ccff;
}
/* sequel for home and navbar */
nav.navtop {
font-family: monospace;
}
.navtop>.navbar>ul {
list-style: none;
margin: 0;
padding-left: 0;
}
.navtop li {
display: block;
float: left;
padding: 0.5rem 0;
position: relative;
text-decoration: none;
transition-duration: 0.3s;
}
.navtop ul li ul {
background: red;
visibility: hidden;
opacity: 0;
min-width: 5rem;
position: absolute;
transition: all 0.5s ease;
margin-top: 1rem;
left: 0;
display: none;
}
.navtop ul li:hover>ul,
.navtop ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
.navtop ul li ul li {
clear: both;
width: 100%;
}
#media screen and (max-width: 760px) {
.topbar-text {
display: none;
}
}
<nav class="navlol navtop" role="navigation">
<div class="navbar">
<h1>Websitee Title</h1>
<ul>
<li><i class="fa-solid fa-file"></i><span class="topbar-text">Home</span></li>
<li>Two
<ul class="dropdownnn">
<li>Sub-1</li>
<li>Sub-2</li>
<li>Sub-3</li>
</ul>
</li>
<li class="navelements">Three</li>
<li><i class="fas fa-user-circle"></i><span class="topbar-text">Profile</span></li>
<li><i class="fas fa-sign-out-alt"></i><span class="topbar-text">Logout</span></li>
</ul>
</div>
</nav>
got an easy fix for you:
add this
.navtop li {
min-height:25px;
}
the issue is that that menu li was way shorter than the others to the sides due to the icons, even better maybe is instead adding this instead:
.navtop li {
height:100%
}
both worked for me
In the screenshot, the yellow color is the area that <li> element is covering. You can see there is a gap between <li> element and submenu. When you try to move the mouse to submenu, your cursor goes out of yellow area and the submenu hides.
The solution would be to position the submenu so it starts exactly after yellow area and make sure there is no gap. Apply margin-top of 0.5rem on submenu instead of 1rem.
I am trying to implement the step progress bar and I have done the below for the desktop version.
Photo who works on the desktop like
Desktop Version
When I try to do it horizontally on a mobile that does not work, it appears vertically
Photo who works in the mobile
Mobile Version
Code Html :
<div class="progress">
<ul1>
<li>
<i class="fa fa-check"></i>
<p>Email</p>
</li>
<li>
<i class="fa fa-refresh"></i>
<p>Register form</p>
</li>
<li>
<i class="fa fa-times"></i>
<p>Done</p>
</li>
</ul1>
</div>
CSS Code :
.progress{
margin-left: 10px auto;
}
.progress img{
width: 80px;
margin-bottom: 20px;
}
ul1{
text-align: center;
}
ul1 li{
display: inline-block;
width: 200px;
position: relative;
margin-top: 10px;
}
ul1 li .fa{
background: #ccc;
height: 26px;
color: #fff;
border-radius: 50%;
padding: 5px;
}
ul1 li .fa::after{
content: '';
background: #ccc;
height: 5px;
width: 205px;
display: block;
position: absolute;
left: 0;
top: 60px;
z-index: -1;
}
ul1 li:nth-child(2) .fa{
background: #ca261a;
}
ul1 li:nth-child(2) .fa::after{
background: #ca261a;
}
ul1 li:nth-child(1) .fa
{
background: #60aa97;
}
ul1 li:nth-child(1) .fa::after
{
background: #60aa97;
}
ul1 li:first-child .fa::after{
width: 105px;
left: 100px;
}
ul1 li:last-child .fa::after{
width: 105px;
}
You use fixed width (in px unit) while overall width from 3 li is wider than screen size.
To fix this, use fluid width such as percentage (%).
.progress {
margin-left: 10px auto;
}
.progress img {
width: 80px;
margin-bottom: 20px;
}
/* use media queries to smaller font size on small screen to prevent them push bar to vertical. */
.progress p {
font-size: 12px;
}
#media (min-width: 400px) {
.progress p {
font-size: initial;
}
}
ul {
list-style: none;
text-align: center;
}
ul li {
list-style: none;
display: inline-block;
width: 30.33%;/* make it fluid */
position: relative;
margin-top: 10px;
}
ul li .fa {
background: #ccc;
height: 26px;
color: #fff;
border-radius: 50%;
padding: 5px;
}
ul li .fa::after {
content: '';
background: #ccc;
height: 5px;
width: 100%;/* make it fluid */
display: block;
position: absolute;
left: 0;
top: 60px;
z-index: 0;/* higher than last step */
}
ul li:nth-child(2) .fa {
background: #ca261a;
}
ul li:nth-child(2) .fa::after {
background: #ca261a;
}
ul li:nth-child(1) .fa {
background: #60aa97;
}
ul li:nth-child(1) .fa::after {
background: #60aa97;
}
ul li:first-child .fa::after {
width: 100%;
left: 50%;
}
ul li:last-child .fa::after {
width: 60%;/* +10 for -10 in left property */
left: -10%;/* for remove empty space on left */
z-index: -1;/* put to bottom */
}
<div class="progress">
<ul>
<li>
<i class="fa fa-check"></i>
<p>Email</p>
</li>
<li>
<i class="fa fa-refresh"></i>
<p>Register form</p>
</li>
<li>
<i class="fa fa-times"></i>
<p>Done</p>
</li>
</ul>
</div>
I've changed your CSS a little, please read in code comment (/* comment */).
However, you may found that in very small screen the font maybe very small. This is for prevent the progress step push to new line. It is not good fix but it can be helped.
Smallest screen tested is 320pixels.
See it on jsfiddle.
I want to add a linkedin icon (id="linkedin") on the right of my nav bar. I figured the simplest way would be to add a new UL element to the nav but that stretches the image and I can't get the applied styles to go away.
I've tried all:initial and all:revert but they don't seem to work.
You'll want to open the snippet on full page.
.container {
position: relative;
margin: 0 auto;
width: 94%;
max-width: 1100px; /*Stops the nav from expanding too far*/
font-family: helvetica, sans-serif;
}
#nav {
position: absolute; /*Positions nav elements within black space*/
right: 0; /*Positions nav elements to right of screen*/
top: -15px; /*Positions nav elements to top of screen*/
height: 60px;
text-transform: uppercase;
font-weight: bold;
}
#header {
z-index: 2; /*Puts elements in front of other elemtns*/
position: fixed;
width: 100%; /*Makes nav stretch to screen*/
height: 60px; /*Specifies black background height*/
line-height: 60px; /*Vertically centers nav text*/
background: #222;
color: white; /*Text color*/
}
/*LOGO*/
#header img {
width: 180px;
height: 60px;
}
#header h1 {
top: 0px;
margin: 0px;
font-size: 1.75em;
}
#nav ul li {
float: left;
list-style: none;
}
#nav ul li a {
display: block;
color: white;
text-decoration: none;
padding: 0 10px;
}
/*Nav Dropdown*/
ul ul {
display: none;
position: absolute;
background: #222;
padding: 0;
white-space: nowrap; /*Prevents dropdown elements from wrapping*/
}
#nav ul ul li {
float: none;
}
> ul {
display: block;
}
#linkedin {
all: revert;
}
/**********RESPONSIVE**********/
/* unvisited link */
a:link {
color: blue;
}
/* mouse over link - Nav*/
#nav a:hover {
color: black;
background-color: gold;
}
/* mouse over link - regular*/
.back a:hover {
color: blue;
}
/* selected link */
a:active {
color: blue;
}
/*Inactive Link*/
.inactivelink {
cursor: default;
}
<header id="header">
<div class="container">
<img src="#" alt="LOGO"/>
<nav id="nav">
<ul>
<li>Portfolio
</li>
<li>
Projects
<ul>
<li>BOOK REVIEW SITE</li>
<li><a href="#" style="";>DEMO CODE (under development)</a></li>
</ul>
</li>
<li>
Contact
<ul>
<li><p style="color:#449ff4">LinkedIn</p></li>
<li>Email Me</li>
</ul>
</li>
<li>
<img id="linkedin" src="#" alt="LinkedIn icon" height="10" width="10">
</li>
</ul>
</nav>
</div>
</header>
I would first load a reset stylesheet before your own, so it will get rid of whatever you are inheriting. I imagine this will fix it.
http://meyerweb.com/eric/thoughts/2011/01/03/reset-revisited/
There's a CSS rule for `'header img' in your styles which forces all images in the header to have 180px width. To overwrite that for your linkedin icon and display it in its original size, add this CSS at the end of your stylesheet:
#header #linkedin {
width: auto;
height: auto;
vertical-align: middle;
}
If the icon is displayed too big or too small that way, just use your desired size instead of auto, but only on one of the two /width/height) - the other will adjust automatically.
.container {
position: relative;
margin: 0 auto;
width: 94%;
max-width: 1100px;
/*Stops the nav from expanding too far*/
font-family: helvetica, sans-serif;
}
#nav {
position: absolute;
/*Positions nav elements within black space*/
right: 0;
/*Positions nav elements to right of screen*/
top: -15px;
/*Positions nav elements to top of screen*/
height: 60px;
text-transform: uppercase;
font-weight: bold;
}
#header {
z-index: 2;
/*Puts elements in front of other elemtns*/
position: fixed;
width: 100%;
/*Makes nav stretch to screen*/
height: 60px;
/*Specifies black background height*/
line-height: 60px;
/*Vertically centers nav text*/
background: #222;
color: white;
/*Text color*/
}
/*LOGO*/
#header img {
width: 180px;
height: 60px;
}
#header h1 {
top: 0px;
margin: 0px;
font-size: 1.75em;
}
#nav ul li {
float: left;
list-style: none;
}
#nav ul li a {
display: block;
color: white;
text-decoration: none;
padding: 0 10px;
}
/*Nav Dropdown*/
ul ul {
display: none;
position: absolute;
background: #222;
padding: 0;
white-space: nowrap;
/*Prevents dropdown elements from wrapping*/
}
#nav ul ul li {
float: none;
}
>ul {
display: block;
}
#linkedin {
all: revert;
}
/**********RESPONSIVE**********/
/* unvisited link */
a:link {
color: blue;
}
/* mouse over link - Nav*/
#nav a:hover {
color: black;
background-color: gold;
}
/* mouse over link - regular*/
.back a:hover {
color: blue;
}
/* selected link */
a:active {
color: blue;
}
/*Inactive Link*/
.inactivelink {
cursor: default;
}
#header #linkedin {
width: auto;
height: auto;
vertical-align: middle;
}
<header id="header">
<div class="container">
<img src="#" alt="LOGO" />
<nav id="nav">
<ul>
<li>Portfolio
</li>
<li>
Projects
<ul>
<li>BOOK REVIEW SITE</li>
<li><a href="#" style="" ;>DEMO CODE (under development)</a></li>
</ul>
</li>
<li>
Contact
<ul>
<li>
<a href="#">
<p style="color:#449ff4">LinkedIn</p>
</a>
</li>
<li>Email Me</li>
</ul>
</li>
<li>
<img id="linkedin" src="http://placehold.it/30x30/0fa" alt="LinkedIn icon" height="10" width="10">
</li>
</ul>
</nav>
</div>
</header>
I have the following Html file, together with the CSS file. When I hover over the Main Navigation bar to open the drop-down menu, the parent width enlarges together with the drop-down menu. How can I fix this? If I set position: absolute to the dropdown menu, it will not work at all.(hovering doesn't trigger the dropdown). I have put my code here: https://jsfiddle.net/L67oxmqc/2/ .
Thank you!
Code:
body {
background-image: url("background.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
h1 {
color: navy;
margin-left: 20px;
}
/* SECTION WITH THE heading text */
#boldtext {
color: Black;
border-radius: 15px;
background: #a9bcba;
padding: 10px;
width: 200px;
height: 50px;
}
/* SECTION WITH BILL GATES QUOTE */
#quotetext {
color: Black;
font-size: 18px;
border-radius: 15px;
padding: 30px;
width: 400px;
height: 150px;
}
div.quote {
position: absolute;
bottom: 5px;
right: 50px;
width: 30px;
/* border: 2px solid rgb(150,245,255);
opacity: 0.8;*/
}
/* SECTION WITH THE MENU FOR THE MAIN PAGE */
div.menu ul {
border-radius: 05px;
position: relative;
list-style-type: none;
margin: 0px;
padding: 0px;
overflow: hidden;
background-color: #a9bcba;
/*z-index: -1; */
}
div.menu li {
float: left;
}
div.menu li a {
display: inline-block;
text-align: center;
margin: 0px;
padding: 10px 10px;
color: white;
}
div.menu li a:hover {
background-color: #879694;
color: blue;
}
/* SECTION WITH THE DROPDOWN CONTENT FOR THE MENU */
.dropdowncontent a:hover {
background-color: #cbd6d5
}
.dropdown:hover .dropdowncontent {
display: block;
}
div.dropdowncontent {
display: none;
/* position: absolute; */
background-color: #a9bcba;
width: 115px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
div.dropdowncontent a {
color: red;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: right;
overflow: auto;
}
<br>
<!-- Header -->
<b id="boldtext">Welcome</b>
<br>
<br>
<br>
<!-- Menu bar-->
<div class="menu">
<ul>
<li class="dropdown">Boeing Family
<div class="dropdowncontent">
Boeing 737 class
Boeing 747 class
Boeing 787 class
</div>
</li>
<li>Airbus Family
</li>
<li>Others
</li>
<li style="float:right">Contact
</li>
<!-- The Contact button is set to be on the right side of the Navigation bar-->
</ul>
</div>
<div class="quote" id="quotetext">
<p><q><cite>A generic quote.</q>
</cite>
— Author.</p>
</div>
<!-- Boeing planes image that triggers the Boeing menu-->
<a href="Boeing.htm" </a>
<img src="Boeing-777-Generic-Nice.jpg" alt="Boeing picture" style="width:350px;height:150px;">
<!-- Airbus planes image that triggers the Airbus menu-->
<a href="Airbus.htm" </a>
<img src="A320-generic.jpg" alt="Airbus picture" style="width:350px;height:150px;">
<!-- ATR planes image that triggers the ATR menu-->
<a href="https://en.wikipedia.org/wiki/ATR_(aircraft_manufacturer)" </a>
<img src="ATR_generic.jpg" alt="Airbus picture" style="width:350px;height:150px;">
<!-- Link to the Frequently asked questions page-->
<a href=#>
<img src="question.jpg" alt="question image" style="width:350px;height:150px;">
</a>
<br>
<br>
Just update in your style may it works for you
div.menu ul {
background-color: #a9bcba;
border-radius: 5px;
float: left;
list-style-type: none;
margin: 0;
padding: 0;
position: relative;
width: 100%;
}
div.dropdowncontent {
background-color: #a9bcba;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
display: none;
position: absolute;
width: 115px;
}
Here is a JSFiddle of the solution I mention below: https://jsfiddle.net/2sy0dn6w/
Fixing your solution is incredibly simple. You want to use position: absolute; for your div.dropdowncontent CSS class. You also want to make your parent li tag have position: relative; to keep your div.dropdowncontent constrained within the parent li. And then you have an issue with your primary ul tag with using overflow: hidden. This would prevent your dropdown from being seen. And I understand why you are using overflow: hidden; - you're using it as a clearfix. But in this case, it is a problem because it hides your dropdown. So instead we would want to use :before with the ul for the clearfix. The steps for applying the fixes are below.
First, remove overflow: hidden; from your css for div.menu ul {}. This will create the following:
div.menu ul {
border-radius: 05px;
position: relative;
list-style-type: none;
margin: 0px;
padding: 0px;
/* overflow: hidden; */
background-color: #a9bcba;
/*z-index: -1; */
}
Next, right after the div.menu ul {} CSS, add:
div.menu > ul::after {
clear: both;
display: table;
content: ' ';
overflow: hidden;
}
Lastly, at the very bottom of your CSS, add the following (you can even move each of the below to their designated declarations you already have in your CSS. The reason I'm adding this separate is so that it's more obvious what I included to give you the outcome you're looking for):
div.menu > ul > li {
position: relative;
}
.dropdowncontent {
position: absolute;
top: 100%;
}
li.dropdown:hover div.dropdowncontent {
display: block;
}
You have to use position absolute, you cant see it working because ul has overflow:hidden;
add this css :
.menu ul{
overflow:visible;
}
.menu ul li.dropdown{
position : relative;
}
.menu ul li.dropdown .dropdowncontent{
position : absolute;
top:38px;
left:0;
}
try this in your css:
add .menu class and remove bg-color from ul
.menu {
background-color: #a9bcba;
height: 45px;
}
div.menu ul {
border-radius: 05px;
position: relative;
list-style-type: none;
margin: 0px;
padding: 0px;
overflow: hidden;
//background-color: #a9bcba; <--- remove background
/*z-index: -1; */
}
Try this code below
Remove overflow hidden
div.menu ul{
...
overflow: hidden;
}
Add position absolute
div.dropdowncontent {
...
position: absolute;
}
replace float left
div.menu li{
/* float: left; */
display: inline-block;
}
body {
background-image: url("background.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
h1 {
color: navy;
margin-left: 20px;
}
/* SECTION WITH THE heading text */
#boldtext {
color: Black;
border-radius: 15px;
background: #a9bcba;
padding: 10px;
width: 200px;
height: 50px;
}
/* SECTION WITH BILL GATES QUOTE */
#quotetext {
color: Black;
font-size: 18px;
border-radius: 15px;
padding: 30px;
width: 400px;
height: 150px;
}
div.quote {
position: absolute;
bottom: 5px;
right: 50px;
width: 30px;
/* border: 2px solid rgb(150,245,255);
opacity: 0.8;*/
}
/* SECTION WITH THE MENU FOR THE MAIN PAGE */
div.menu ul {
border-radius: 05px;
position: relative;
list-style-type: none;
margin: 0px;
padding: 0px;
background-color: #a9bcba;
/*z-index: -1; */
}
div.menu li {
display: inline-block;
}
div.menu li a {
display: inline-block;
text-align: center;
margin: 0px;
padding: 10px 10px;
color: white;
}
div.menu li a:hover {
background-color: #879694;
color: blue;
}
/* SECTION WITH THE DROPDOWN CONTENT FOR THE MENU */
.dropdowncontent a:hover {
background-color: #cbd6d5
}
.dropdown:hover .dropdowncontent {
display: block;
}
div.dropdowncontent {
display: none;
position: absolute;
background-color: #a9bcba;
width: 115px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
div.dropdowncontent a {
color: red;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: right;
overflow: auto;
}
<br>
<!-- Header -->
<b id="boldtext">Welcome</b>
<br>
<br>
<br>
<!-- Menu bar-->
<div class="menu">
<ul>
<li class="dropdown">Boeing Family
<div class="dropdowncontent">
Boeing 737 class
Boeing 747 class
Boeing 787 class
</div>
</li>
<li>Airbus Family
</li>
<li>Others
</li>
<li style="float:right">Contact
</li>
<!-- The Contact button is set to be on the right side of the Navigation bar-->
</ul>
</div>
<div class="quote" id="quotetext">
<p><q><cite>A generic quote.</q>
</cite>
— Author.</p>
</div>
<!-- Boeing planes image that triggers the Boeing menu-->
<a href="Boeing.htm" </a>
<img src="Boeing-777-Generic-Nice.jpg" alt="Boeing picture" style="width:350px;height:150px;">
<!-- Airbus planes image that triggers the Airbus menu-->
<a href="Airbus.htm" </a>
<img src="A320-generic.jpg" alt="Airbus picture" style="width:350px;height:150px;">
<!-- ATR planes image that triggers the ATR menu-->
<a href="https://en.wikipedia.org/wiki/ATR_(aircraft_manufacturer)" </a>
<img src="ATR_generic.jpg" alt="Airbus picture" style="width:350px;height:150px;">
<!-- Link to the Frequently asked questions page-->
<a href=#>
<img src="question.jpg" alt="question image" style="width:350px;height:150px;">
</a>
<br>
<br>
When I place the width of by web page as 100% it fits to the browser. But when I re-adjust the size of the browser the navigation bar I used overlaps and all the positions go wrong. I can't figure out the mistake yet. I will post the css and the html code below. Please someone help me to fix my web page.
HTML:
<div class="main">
<div class="header">
<div class="logo12">
<h2 style="position:absolute; left:20px; top:2px; color:#FFFFFF;">
<a>
<font face="verdana">PHIS</font>
<small>Public Health Information System-Sri Lanka</small>
</a>
</h2>
</div>
<div>
</div>
<div id="menu">
<ul>
<li>Home</li>
<li>
Services
<ul id="SubNav">
<li id="AccessFormPHI">Data Entry</li>
<li id="DataEntry">Edit Temporary Forms</li>
<li id="ViewData">View Data</li>
<li id="ViewAggregatedData">Data Aggregation</li>
</ul>
</li>
<li>Help</li>
<li>
Profile
<ul id="SubNav">
<li id="AccessForm">View and Maintain Profile</li>
<li id="ChangePassword">Change Password</li>
<li>Log Out</li>
</ul>
</li>
</ul>
</div>
</div>
CSS:
/* Height of the navigation bar became shorter */
.main {
width: 100%;
font: 13px Georgia, "verdana", "Times New Roman", Times, serif;
color: #FFFFFFF;
background-color: #F2F2F2;
height: 1000px;
left: 0px;
}
/* No difference was appeared*/
#cssmenu {
position: absolute;
top: 100px;
left: 0px;
}
/* Adjust the olor of the navigation bar */
.logo12 {
position: absolute;
padding-top: 10px;
/*padding-left: 60px; */
top: 0%;
height: 6%;
width: 100%;
left: 0px;
background: -moz-linear-gradient(top,#084B8A ,#0B173B);
}
/* Adjust the place where navigation */
#menu {
position: absolute;
left: 45%; /* change to 390px to 350px */
top: 20px;
display: inline;
}
#menu ul {
margin-left: auto;
margin-right: auto;
width :700px; /*change to 60% to 800px*/
}
/* upto now no difference */
#menu ul li {
display: inline;
float: left;
list-style: none;
position: relative;
height: 60px;
width: 130px;
padding-bottom: 20px;
font-size: 13px;
}
/* Adjust the width of the sub navigation bar */
#menu ul li ul li {
float: left;
list-style: none;
position: relative;
height: 30px;
width: 180px;
font-size: 12px;
}
/* Adjust the color of the sub navigation bar */
#menu li ul {
margin: 0px;
padding: 10px;
display: none;
position: absolute;
left: 0px;
z-index: 99;
top: 28px;
background: -moz-linear-gradient(top,#084B8A ,#0B173B); #726E6D; /*Menu Hover Color*/
border: 1;
}
#menu ul li:hover ul {
display: block;
width: auto;
}
/* Upto now no difference was visible */
#menu li li {
list-style: none;
}
/* Color of sub navigation bar letters became gray */
#menu li li a {
color: #FFFFFF;
text-decoration: none;
}
/* Letters hover color red in the sub navigation bar */
#menu li li a:hover {
color: #900;
text-decoration: none;
}
/* Upto now no difference */
li#main1 {
padding-top: 0px;
}
/* Main navigation bar disappeared */
#menu a {
padding-right: 25px;
text-decoration: none;
letter-spacing: -1px;
font-size: 1.2em;
color: #BDBDBD;
font: cambria;
}
/* Upto now no difference */
#menu ul li a:hover {
/* background: #D8D8D8; /*a tag hover color*/
padding: 5px; /*change to 12px to 5px*/
left: 0px;
}
You can use relative width for CSS,for example:
.main, .header{width:100%;}
Add white-space: nowrap to your navigation CSS. I know this is an old post, but seems to have no solution yet.