CSS Head Nav and Dropdown Menu Alignment problem - html

I am working on a project for school and am trying to add a drop down menu to my head navigation. I am still pretty new to css but had fun playing with the styling to get an interesting alignment that would work with the vision I had for the page (this is part of a larger piece that I didn't include to keep it relevant to the question)
I wanted to create a right aligned menu that was set to the bottom of the head div. I got everything to work by using absolute positioning but now that I am trying to add a fancy multi level drop down menu things aren't working. I have tried combinations of inline block and relative and absolute positioning but the dropdown does not align correctly. It just bunches up at the bottom offset to the right.
When I try styling the nav bar like people do in tutorials it gets messed up when I remove the absolute positioning.
Is there a way to get the dropdown to work with the current method of styling? I don't have any hover effects or visibility yet because I can't even get it lined up! That part should be pretty straight forward for the dropdown and submenus.
and probably more importantly
Is there a better way to accomplish this visual goal? (right-aligned at the bottom of the white div)
This is not a dynamic styling yet so you have to stretch the viewport for it to make sense.
/*====================================MAIN=================================*/
body {
background-color: #d5d3d5;
font-family: 'Gill Sans', 'Gill Sans MT', 'Calibri', 'Trebuchet MS', sans-serif;
margin: 0px;
padding: 0px;
}
.flex_body {
background: linear-gradient(90deg, rgba(255, 255, 255, .0), rgba(255, 255, 255, 1) 20%);
display: flex;
margin: 0px;
padding: 0px;
height: 800px;
}
.page_body {
background: linear-gradient(90deg, rgba(255, 255, 255, .0), rgba(255, 255, 255, 1) 15%);
margin: 0px 0px 0px 30px;
padding: 0px 0px 0px 20px;
height: 800px;
overflow: hidden;
}
/*=============================MAIN=NAVIGATION=================================*/
#header {
background-color: #ffffff;
height: 130px;
margin: 0px;
padding-bottom: 0px;
position: relative;
box-shadow: inset 0px -15px 18px -6px rgba(121, 104, 124, 0.678);
}
#headNAV ul {
list-style-type: none;
position: absolute;
text-align: right;
bottom: 0;
right: 0;
margin: 8px;
}
#headNAV ul li {
display: inline;
position: relative;
font-size: 18px;
padding: 5px 0px 15px 0px;
margin: 0px 0px 0px -5px;
}
#headNAV ul li:not(:last-child) {
border-right: 1px solid #8f85a1dc;
}
#headNAV ul li a {
display: inline-block;
padding: 5px 40px 10px 40px;
margin: 0px 0px -2px 0px;
text-decoration: none;
color: #353138;
}
#headNAV ul li a:hover {
background-color: #50328ddc;
color: white;
text-decoration: underline;
box-shadow: 0px 5px 3px 1px #50328ddc;
}
#search_icon {
max-width: 5%;
max-height: 5%;
margin: 0px;
padding: 0px;
display: inline;
}
#headNAV ul li input {
margin: 5px 35px 10px 35px;
}
/*======================myPage-Nav============================*/
#myPage_button:hover>#myPage {
color: white;
}
#myPage_button {
text-decoration: underline;
}
#myPage {
color: #50328ddc;
font-size: 22px;
font-weight: bold;
text-decoration: underline;
}
#dropdown-btn {
padding: 0px 10px;
}
#myPage-menu {
margin: auto;
}
#headNAV ul li #myPage-menu li {
position: absolute;
background-color: #fff;
display: inline-block;
padding: 0px;
border: none;
}
<header id="header">
<nav id="headNAV">
<ul>
<li>Mission</li>
<li>News</li>
<li>Events</li>
<li>Forums</li>
<li><a id='myPage_button' href="#">My<span id='myPage'>Page</span><span id = "dropdown-btn" class="fas fa-caret-down"></span></a>
<ul id="myPage-menu">
<li>Main Feed</li>
<li>Projects</li>
<li>Messages</li>
<li>Profile</li>
<li>Search</li>
</ul>
</li>
<li><input type="text" name="search" placeholder="Search..."></li>
<li><a id="header_login" href="#">Login/SignUp</a></li>
</ul>
</nav>
</header>
Thank you for any input!
Kevin

Related

Is there any way how can I make one row hypertext in vertical menu?

I am setting up a new web page and making a horizontal menu. The hypertext is made by 2 words. It should be in one row, but actually one word = 1 row. I have here in CSS a hover effect over it, whenever the hover effect works, the hypertext is in this moment in one row. I am a little bit lost and confused. I don't know what to change, can you help me?
I have already tried changing in CSS display attribute to table, block, solid. Also I have tried min-width, with hopes that text will expand on one line, but it didn't helped at all. Also I tried to change margin and padding but nothing changed.
https://i.stack.imgur.com/AgqOJ.jpg
HTML
<div id ="panel">
<img src= "Logo.jpg" alt="Logo">
<h3>Nabidka</h3>
<ul>
<br />
<br />
<br />
<li>Hlavní stránka</li>
<li>Program 2020</li>
<li>Kde sídlíme</li>
<li>Organizátoři</li>
<li>O nás</li>
<li>Galerie</li>
<li class ="last">Facebook</li>
</ul>
</div>
CSS
#panel{
width: 15%;
float: left;
background: rgb(153,153,153);
padding: 5px 0 0 0;
}
#panel h3{
display: none;
}
#panel ul{
margin: 0;
padding: 0;
list-style-type: none;
background: rgb(153,153,153);
}
#panel li{
/*border-top: 0px solid rgb(0,176,176);*/
/*border-width: 2px 0px 0px 0px;*/ /*line between hypertexts*/
/*margin: 0px 0px 0px 0px;*/
/*margin-bottom: 1px;*/
display: block;
}
#panel a{
display: block;
width: 100px;
height: 30px;
color: black;
font-size: 120%;
font-weight: bold;
text-decoration: none;
padding: 6px 185px 6px 4px;
margin: 5px 0px 0px 0px;
background: rgb(153,153,153);
}
#panel a:hover{ /*redrawing*/
color: white;
text-decoration: none;
background: rgb(0,0,0);
padding: 4px 0px 4px 2px;
min-width: 100%;
}
#panel li.spodni{
height: 1500px;
}
img {
width: 200px;
height: 200px;
padding: 0px 0px 0px 20px;
}
The a tag width has been limited in normal state:
#panel a{
display: block;
width: 100px; --> this line
height: 30px;
color: black;
font-size: 120%;
font-weight: bold;
text-decoration: none;
padding: 6px 185px 6px 4px;
margin: 5px 0px 0px 0px;
background: rgb(153,153,153);
}
You could remove the line width: 100px; because display:block will set the element width to 100% of its container.
the width in your a tag selector in CSS was limiting the width of the elements forcing a text wrap. this fixes it
<div id ="panel">
<img src= "Logo.jpg" alt="Logo">
<h3>Nabidka</h3>
<ul>
<br />
<br />
<br />
<li>Hlavní stránka</li>
<li>Program 2020</li>
<li>Kde sídlíme</li>
<li>Organizátoři</li>
<li>O nás</li>
<li>Galerie</li>
<li class ="last">Facebook</li>
</ul>
</div>
<style>
#panel{
width: 15%;
float: left;
background: rgb(153,153,153);
padding: 5px 0 0 0;
}
#panel h3{
display: none;
}
#panel ul{
margin: 0;
padding: 0;
list-style-type: none;
background: rgb(153,153,153);
}
#panel li{
/*border-top: 0px solid rgb(0,176,176);*/
/*border-width: 2px 0px 0px 0px;*/ /*line between hypertexts*/
/*margin: 0px 0px 0px 0px;*/
/*margin-bottom: 1px;*/
display: block;
}
#panel a{
display: block;
width: 150px;
height: 30px;
color: black;
font-size: 120%;
font-weight: bold;
text-decoration: none;
padding: 6px 185px 6px 4px;
margin: 5px 0px 0px 0px;
background: rgb(153,153,153);
}
#panel a:hover{ /*redrawing*/
color: white;
text-decoration: none;
background: rgb(0,0,0);
padding: 4px 0px 4px 2px;
min-width: 100%;
}
#panel li.spodni{
height: 1500px;
}
img {
width: 200px;
height: 200px;
padding: 0px 0px 0px 20px;
}
</style>

How do I align my navbar so it's permanently in the middle of my white box (without padding etc)?

This is my website. The nav bar is causing me horrendous problems. Last night my friend told me it was dropping down and I just don't know how to fix it:
http://i60.tinypic.com/23iigpi.png
So I removed the width and reduced the text on some buttons which is depressing for me.
Anyway, now I want my smaller nav bar to centre in the middle of my white block. Does anyone know the best way?
http://www.simplypsychics.com/null/index-test.html
I have tried:
and modifying various positioning in the CSS but nothing seems to work.
This is my CSS for the nav:
#nav {
position: absolute;
top: 98px;
left:15px;
float: left;
list-style: none;
background-image:url(../images/menubanner.png);
background-color: #f5c3fd;
border-radius:7px;
-webkit-box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.05);
-moz-box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.05);
box-shadow: 1px 3px 1px rgba(0, 0, 0, 0.05);
}
#nav li {
float: left;
}
#nav li a {
display: block;
padding: 8px 13px;
text-decoration: none;
font-weight: bold;
color: #494949;
border-right: 1px solid #fceaff;
}
#nav li a:hover {
color: #822e8e;
}
#nav .home-icon1 {
background: url(../images/icon-home.png) no-repeat center;
width: 39px;
height: 34px;
background-color: #494949;
color: #f5c3fd;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
position: relative;
border-right: 1px solid #fceaff;
float: left;
padding: 0;
list-style: none;
}
#nav .home-icon1 a:hover {
background: url(../images/icon-home.png) no-repeat center;
width: 39px;
height: 34px;
background-color: #494949;
color: #f5c3fd;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
position: relative;
border-right: 1px solid #fceaff;
float: left;
padding: 0;
list-style: none;
}
#nav .home-icon2 {
background: url(../images/icon-findapsychic.png) no-repeat left;
padding: 0px 0px 0px 15px;
}
#nav .home-icon3 {
background: url(../images/icon-psychicreadings.png) no-repeat left;
padding: 0px 0px 0px 25px;
}
#nav .home-icon4 {
background: url(../images/icon-bookareading.png) no-repeat left;
padding: 0px 0px 0px 22px;
}
#nav .home-icon5 {
background: url(../images/icon-aboutus.png) no-repeat left;
padding: 0px 0px 0px 30px;
}
#nav .home-icon6 {
background: url(../images/icon-help.png) no-repeat left;
padding: 0px 0px 0px 14px;
}
and this is my HTML:
<div id="nav" style="margin:0 auto !important;">
<li class="home-icon1" onclick="window.location.href='http://www.simplypsychics.com/'"></li>
<li class="home-icon2">FIND A PSYCHIC READER</li>
<li class="home-icon3">PSYCHIC READINGS</li>
<li class="home-icon4">BOOK A READING</li>
<li class="home-icon5">FIND OUT MORE</li>
<li class="home-icon6">HELP/FAQ</li>
</div>
Also if the nav bar looks awful for you like it did my friend please let me know! :(
On parent (#headerwhiteback) set:
text-align: center;
Then on #nav, remove:
position: absolute;
float: left;
And add this CSS:
#nav {
display: inline-block;
}
#nav::before {
content: "";
clear: both;
}
Also, to your liking: add margin-top: on #nav (25px seems ok) and make padding-top: on next element, #headertextbottom, much smaller (20px seems ok).
This is just a quick fix for your header. Please remember: CSS looks horrific here and looks set to be rewritten from scratch or only cause you more and more trouble. Good luck!
If the nav bar is more-or-less a set width (#nav looks to stay at 840px) then you can set left:50% and margin-left:-420px (-420 px because it's half the width of the navbar, and we want to move it towards the left). This should work because you've already set the navbar to be positioned absolutely.
You'll have to remove this from the #nav div though: style="margin:0 auto !important;"
Inline style and !important is doubly bad!

How do I make my Current CSS Drop down menu Responsive and mobile friendly?

I am having trouble with this, I have looked through other peoples questions and answers I have found some helpful info however I am struggling to apply it to my menu. I am looking for my current menu which is pure CSS and HTML no other scripts or code to become fully responsive and mobile friendly. i.e. I want to make sure when the browser window size is reduced that the menu also gets smaller then to the point where it turns into the mobile button that you tap to expand.
I am hoping someone can show me the exact code I need to add to it with the correct class names etc. I have already tried and failed at this by trying to adapt other peoples answers. I am aware there are various places that will "build" one for free and give me the code however I want the desktop version of my menu to be 100% the same I just need it to scale properly to smaller screens.
I also do not want to use jquery javascript or anything else that is not HTML5 or CSS3, the code is inserted into my index.php and css into my external css file,
From my index page:
<!-- NAV-BAR-START -->
<div id="navbar"><div id='cssmenu'>
<ul>
<li><a href='/?p=home'><span>Home</span></a></li>
<li class='has-sub'><a href='/?p=gallery'><span>Gallery</span></a>
<ul>
<li><a href='/?p=photos'><span>Photos</span></a></li>
<li><a href='/?p=videos'><span>Videos</span></a></li>
<li><a href='/?p=audio'><span>Audio</span></a></li>
</ul>
</li>
<li class='has-sub'><a href='/?p=ian-milne'><span>Ian Milne</span></a>
<ul>
<li><a href='/?p=about'><span>About Ian</span></a></li>
<li><a href='/?p=testimonials'><span>Testimonials</span></a></li>
<li class='last'><a href='/?p=location'><span>Location</span></a></li>
</ul>
</li>
<li><a href='/?p=events'><span>Events</span></a></li>
<li><a href='/?p=bookings'><span>Bookings</span></a></li>
<li class='last'><a href='/?p=contact'><span>Contact</span></a></li>
< /ul>
</div></div>
<!-- NAV-BAR-END -->
And the associated CSS:
/* CSS DROPDOWN MENU */
#cssmenu {
border: none;
border: 0px;
margin: 0px;
padding: 0px;
font: 67.5% 'Lucida Sans Unicode', 'Bitstream Vera Sans', 'Trebuchet Unicode MS', 'Lucida Grande', Verdana, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
width: auto;
text-align:center;
}
#cssmenu ul {
background: #000dfa;
height: 50px;
list-style: none;
margin: 0;
padding: 0;
-webkit-border-radius: 8px 8px 0px 0px;
-moz-border-radius: 8px 8px 0px 0px;
border-radius: 8px 8px 0px 0px;
-webkit-box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
-moz-box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
}
#cssmenu li {
float: none;
padding: 0px 0px 0px 15px;
display: inline-block;
}
#cssmenu li a {
color: #ffffff;
display: block;
font-weight: normal;
line-height: 50px;
margin: 0px;
padding: 0px 25px;
text-align: center;
text-decoration: none;
}
#cssmenu li a:hover {
background: #000894;
color: #ff8400;
text-decoration: none;
-webkit-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
-moz-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
}
#cssmenu ul li:hover a {
background: #000894;
color: #ff8400;
text-decoration: none;
}
#cssmenu li ul {
display: none;
height: auto;
padding: 0px;
margin: 0px;
border: 0px;
position: absolute;
width: 200px;
z-index: 200;
}
#cssmenu li:hover ul {
display: block;
}
#cssmenu li li {
display: block;
float: none;
margin: 0px;
padding: 0px;
width: 200px;
background: #000dfa;
/*this is where the rounded corners for the dropdown disappears*/
}
#cssmenu li:hover li a {
background: none;
}
#cssmenu li ul a {
display: block;
height: 50px;
font-size: 12px;
font-style: normal;
margin: 0px;
padding: 0px 10px 0px 15px;
text-align: left;
}
#cssmenu li ul a:hover,
#cssmenu li ul li:hover a {
border: 0px;
color: #ff8400;
text-decoration: none;
background: #000894;
-webkit-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
-moz-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
}
I have now put this into jsfiddle aswell for those who were asking
http://jsfiddle.net/GregTimeassistant/WLP8h/
You can style for each media query. Just copy/paste all your styles for each case.
You can resize your browser window so you can see the result for each media query.
Just experiment a lot, you will see that it is easy to customize your design for each aspect ratio.
#media (max-width: 600px) {
#cssmenu {
/*
copy styles here
*/
}
}
Check this example that covers a lot of devices (but needs some updating for new HD smartphones and tablets).
https://gist.github.com/marcobarbosa/798569

Increasing the width of button by a few percent on hover

So, I have this made.
HTML
<div id="navholder" class="bgd">
<nav id="nav">
<ul>
<li>Почетна</li>
<li>Делатност</li>
<li>Историјат</li>
<li>Службе</li>
<li>Колектив</li>
<li>Контакт</li>
</ul>
</nav>
</div>
#navholder {
height: 60px;
text-align: center;
margin: 0 auto;
}
#nav {
height: 30px;
margin-top: 10px;
background: #B8860B;
}
#nav ul li{
margin-top: 3px;
display: inline;
font-size: 120%;
opacity: 1.0;
}
#nav ul li a {
display: inline-block;
height: 120%;
padding: 5px;
-webkit-box-shadow: -1px 0px 22px rgba(50, 50, 50, 0.5);
-moz-box-shadow: -1px 0px 22px rgba(50, 50, 50, 0.5);
box-shadow: -1px 0px 22px rgba(50, 50, 50, 0.5);
border: 1px solid white;
opacity: 1.0;
background: #DAA520;
}
#nav a:hover {
color: white;
background: black;
width: ?
}
I want the buttons once hovered over with a mouse to increase about 20%. The problem that I found is if I use the exact width like "width: 60px not every button is of the same size.
On the other hand if I use width: 120% I believe the page takes the width of the whole #navholder element which is defined by the class .bgd.
Any ideas on how can I make this happen?
Thanks.
You could use transform: scale()
jsFiddle example
#nav a:hover {
transform:scale(1.3,1.3);
-webkit-transform:scale(1.3,1.3);
-moz-transform:scale(1.3,1.3);
}
Just increase the padding on hover:
#nav a:hover {
color: white;
background: black;
padding: 5px 10px; /* 5px top/bottom, 10px left/right */
}
You may set width with em's and increase font-size.
Also, you may add border/padding on hover:
#nav a:hover {
border-right: solid 20px black;
/* or padding-right */
}

Change css background for my code

I'm not good in css, so please try to help me
I have this css code
#mo-stats-w1 {
background: url("http://i48.tinypic.com/108dbix.png") 0px 0px repeat-x;
/*height: 143px;*/
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
margin: 10px 0px 0px 0px;
padding-bottom: 10px;
background-color: #3EC4CD;
}
#mo-stats-w2 {
padding: 12px 0px 0px 15px;
}
#mo-stats-w1 ul {
padding: 0px 0px 0px 0px;
margin: 0px 0px 1px 0px;
height: 59px;
}
#mo-stats-w1 ul li {
display: block;
list-style: none;
padding: 1px;/*0px 0px 0px 0px;*/
margin: 0px 1px 0px 0px;
width: 174px;
height: 59px;
float: left;
}
ul#mo-stats-r1 li { background: url("http://i50.tinypic.com/23j0bcg.png") 0px 0px no-repeat; }
ul#mo-stats-r2 li { background: url("http://i50.tinypic.com/23j0bcg.png") 0px -59px no-repeat; }
#mo-stats-w1 ul li strong {
font-size: 24px;
height: 22px;
font-family: Arial, "Nimbus Sans L", "FreeSans";
font-weight: bold;
color: #1774C2;
text-shadow: 1px 1px 1px white;
display: block;
padding: 0px 0px 0px 0px;
margin: 10px 0px 0px 11px;
}
#mo-stats-w1 ul li span {
font-size: 13px;
font-weight: bold;
color: #3e3e3e;
display: block;
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 11px;
}
and this html code
<div id="mo-stats-w1">
<div id="mo-stats-w2">
<ul id="mo-stats-r2">
<li><strong>Status</strong></li>
<li><strong>100</strong> <span>Points</span></li>
<li><strong>30</strong> <span>Pending Points</span></li>
<li><strong>0</strong> <span>Direct Referrals</span></li>
<li><strong>Total</strong></li>
<li><strong>2</strong> <span>Links</span></li>
<li><strong>114</strong> <span>Views</span></li>
<li><strong>7</strong> <span>Unlocked Views</span></li>
</ul>
</div>
</div>
So the layout will be
Change the background for "Status" and "Total" to #4EC772 and background hover #7DD798 and the color for both words to be #FFFFFF
To be something like this
How i can do that please ?
jsfiddle: http://jsfiddle.net/WwY2v/
Thanks
You need to use the nth-child() pseudo class to target those two <li> and do the same for the color: #fff; except specify the <strong> element after ..
Updated fiddle: http://jsfiddle.net/WwY2v/2/
This is what I added:
#mo-stats-r2 li:nth-child(4n + 1):hover {
background: #4EC772;
}
#mo-stats-r2 li:nth-child(4n + 1) strong:hover {
color: white;
}
Simply add a class to the required elements like:
<li class='highlight'><strong>Status</strong></li>
...
...
<li class='highlight'><strong>Total</strong></li>
And use the following css:
.highlight {
color:#FFFFFF; /* normal text color */
background-color:#4EC772; /* normal bg color */
}
.highlight:hover, .highlight:focus {
color:#FFFFFF; /* hover text color */
background-color:#7DD798; /* hover bg color */
}