Create buttons where clicked anywhere do navigation - html

This is probably a very simple question for many of you, but I can't seem to figure it out and I've been at it for about an hour now.
I'm trying to create a navigation bar with buttons. I'd like the buttons to have the following features, but I can't figure out how to implement them:
Clicking anywhere on the button will activate the button redirection.
The font is not underlined or recolored like a regular text hyperlink.
The font is much more "fat" (I don't know how else to describe it.
In the picture, I put small red cross to signal that I'd like to be able to click in those locations for it to work.
I've included a jsfiddle with what I've been able to accomplish thusfar.
My html:
<ul>
<li><a id="nav" href="#">Page1</a></li>
<li><a id="nav" href="#">Page2</a></li>
<li><a id="nav" href="#">Page3</a></li>
<li><a id="nav" href="#">Page4</a></li>
</ul>
My CSS:
body {
margin: 0px
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
ul li {
float:left;
overflow: auto;
padding: 6px 12px 6px 12px;
background-color: grey;
border: 1px solid #000;
text-decoration: none;
margin: 0;
border: 0;
margin-right: 3px;
font-weight: bolder;
color: yellow;
}
ul li:hover{
background-color: black;
}
}

replace ul li { with ul li a{ and ul li:hover{ with ul li a:hover{
http://jsfiddle.net/vxre4x2k/2/

Simply replace ul li with ul li a and ul li:hover with ul li a:hover.
To make the font thicker or thinner change your font-weight

You need to make you anchors work like block elements. The LI's will contain the anchor.
ul li a {
display: block;
text-decoration: none;
padding: 6px 12px 6px 12px;
}
ul li a:hover {
background-color: black;
}

You can use display: inline-block to a(anchor element) and give it some padding for your first request(Clicking anywhere on the button will activate the button redirection.). Also you can remove underline with text-decoration: none; and reduce "fat" from font with font-weight: 100;:
body {
margin: 0px
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
ul li {
float: left;
padding: 6px 12px 6px 12px;
background-color: grey;
border: 1px solid #000;
text-decoration: none;
margin: 0;
border: 0;
margin-right: 3px;
font-weight: bolder;
color: yellow;
}
ul li:hover {
background-color: black;
}
ul li {
padding: 0;
}
ul li a {
display: inline-block;
padding: 5px;
text-decoration: none;
color: white;
font-weight: 100;
}
<ul>
<li><a id="nav" href="#">Page1</a>
</li>
<li><a id="nav" href="#">Page2</a>
</li>
<li><a id="nav" href="#">Page3</a>
</li>
<li><a id="nav" href="#">Page4</a>
</li>
</ul>
References:
font-weight
text-decoration

Clicking anywhere on the button will activate the button redirection.
to do this, wrap your list elements with the anchor elements instead.
ex.
<a href='#'><li>foo</li></a>
The font is not underlined or recolored like a regular text hyperlink.
for the links you gave them each an id of "nav". This isn't recommended as its commonplace to set id's to individual elements. I would look up the difference between CSS id's and classes. In short, classes are used for multiple elements that share the same styles. In this case you would use a class so it should be:
<a class="nav" href="#"><li>Page1</li></a>
The styles for the class to remove the underline would be:
.nav{
text-decoration:none;
color: black;
}
The font is much more "fat" (I don't know how else to describe it.
are you saying you want it to be fat?
if so then try this:
<a class="nav" href="#"><strong><li>Page1</li></strong></a>
or you could also set the css style font-weight property
the font-weight property can be used to increase or decrease the "fattness" of the font.
if that doesn't do it for you i'd suggest using a different font.

Related

How do I get the submenu to not disappear?

I have a navigation menu on my website. It works, however when hovering over a menu item with sub-items they disappear when trying to click on them. It appears that there is a spacing issue with these items.
*Additionally, I am trying to figure out how to insert a | between the menu items. If you could share some insight that would be amazing. I only have basic coding knowledge as you can probably tell from my post.
I appreciate the assistance!
/* do not change */
.container {
overflow: unset;
}
#container ul {
margin: 0px;
padding: 0px;
list-style-type: none;
display: inline-block;
}
#container ul li ul li {
display: none;
}
/* can change */
#container {
text-align: center;
}
#container ul li {
width: 130px;
height: 30px;
line-height: 30px;
float: left;
text-align: center;
margin: 5px;
border-radius: 0px;
}
#container ul li a {
color: black;
text-decoration: none;
font-weight: bold;
display: block;
}
#container ul li a:hover {
text-decoration: none;
border-radius: 0px;
color: #1dcdfe;
}
#container ul li:hover ul li {
background-color: white;
display: block;
margin-left: 0px;
}
<div id="container">
<ul>
<li><a href='#scroll-home'>Home</a></li>
<li><a href='#'>About Us</a>
<ul>
<li><a href='#scroll-whyhere'>Why You're Here</a></li>
<li><a href='#scroll-ourmethod'>Our Method</a></li>
<li><a href='#scroll-whyus'>Why Choose US</a></li>
<li><a href='#scroll-testimonials'>Testimonials</a></li>
</ul>
</li>
<li><a href='#'>Our Services</a>
<ul>
<li><a href='#scroll-wetreat'>What We Treat</a></li>
<li><a href='#scroll-packages'>Packages & Pricing</a></li>
</ul>
</li>
<li><a href='#scroll-faq'>FAQs</a></li>
<li><a href='#'>Contact Us</a></li>
</ul>
</div>
If I'm understanding you correctly, you want horizontal separators on your top-most navigation elements.
To do this, you can add borders to your li elements and then exclude the last one, like so:
#container ul li {
// ... other styles here
border-right: 1px solid black;
}
/* Add this additional style so that the last item doesn't receive the border */
#container ul li:last-child {
border-right: none;
}
A working example can be found at https://codepen.io/BrandonClapp/pen/wvGqrmQ
Following code add the pipes between menu's
#container > ul > li {
border-right: 1px solid black;
}
#container > ul > li:last-child {
border-right: 0;
}
Well thats because you have given every li a specific height here:
#container ul li {
width: 130px;
height: 30px;
line-height: 30px;
float: left;
text-align: center;
margin: 5px;
border-radius: 0px;
}
Which does not let the box grow when its hovered. You can give the nav buttons that have the hovering option an id and give the following code:
#container ul li #drop_down{
height: 100%;
}
For hindering future confusion, if you want to select direct children, use >, like so:
#container > ul {
margin: 0px;
padding: 0px;
list-style-type: none;
display: inline-block;
}
Here you have not used it, so even the inner ul is having these attributes, which ruins it. If you change it to the code above it will get fixed. Why? because the inner ul has the display: inline-block; attribute in your code which should not be.
Furthermore, Try giving the box a background-color and a z-index, so it will not keep detecting hover in behind boxes, in this case contact button.
For your other question I refer you to this link:
How to make a vertical line in HTML
And, or:
https://medium.com/#hollybourneville/creating-border-lines-using-pseudo-elements-in-css-a460396299e8

HTML overlapping text on a nav bar

im trying to get text to overlap the nav bar, when I say overlap I mean expand outside the nav bar white keeping the nav where it is. here is my code I tried using different padding techniques but none have worked. any help would be appreciated :
div {
padding-top:80px;
}
ul {
list-style-type: none;
padding: 0;
overflow: hidden;
margin:15px;
background-color: black;
line-height: 5px;
}
li {
float:left;
font-family: Courier New;
}
li a {
display: block;
color: white;
padding:20px;
text-decoration: none;
text-align: center;
text-decoration: none;
padding: 2px 25px;
}
li a:hover {
/*background-color: ;*/
color: white;
}
li a.active {
background-color: #4CAF50;
}
<div>
<ul>
<li>Million-Air</li>
<li>Men</li>
<li>Wemon</li>
<li style="float:right"><a class="active" href="account.html">Account</a></li>
</ul>
</div>
So I figured it out, it was due to the fact I had float left on the li element and it was pushing all the blank space to the left. So I had to use 'clear: both' for it to work
Try removing your overflow: hidden property. The text will extend outside the box if you do.
If I am misunderstanding your intent, try linking to what you're trying to do if you have examples online.

simple way of making selected navigation page link change colour?

I know this is a silly question but for some reason I'm always having a problem with changing the background colour of a selected navigation item, I looked this up so many times and I tried doing the selected classes for a button but for some reason it doesn't work for me, can someone point out what am I doing wrong?
html:
<div id="nav">
<ul>
<li><a class="selected" href="?page=home">Home</a></li>
<li>Gallery</li>
<li>About</li>
<li>Contact</li>
<li>Shop</li>
</ul>
</div>
css:
#nav {
list-style: none;
width: 100%;
text-align: center;
background-color: #000;
height:52px;
background-color: #000; opacity: 0.7; filter: alpha(opacity=50);
}
#nav ul {
list-style-type: none;
margin: 0px;
padding: 10px;
padding-left: 650px;
}
#nav li {
margin: 0px;
display: inline-block;
}
#nav li a {
padding: 10px;
text-decoration: none;
font-family: 'Quicksand';
font-size: 25px;
color: #fff;
background-color: #000;
}
#nav li a:hover {
color: black;
background-color: #999;
background-color: #666;
color: white;
}
li.selected a { background-color: blue;
}
You've two issues here.
You are using li.selected a but you are assigning your class to a tag so the selector should be li a.selected
Specificity. You have #nav in all the selectors, since ID selectors are more specific, you need to add it to your .active selector as well. So it should be #nav li a.selected
Demo
Suggestion :
I would recommend you to use class instead of id. Keep ID's for JavaScript selectors, as it can access your DOM faster, but for CSS, stick to classes as much as you can, else you will end up with long specific selectors and even !important.
So you should have something like <div id="nav" class="nav"> and use .nav in CSS instead of #nav

Dots in my Anchors in Nav Bar

Doing some basic html/css. I was making a rudimentary navbar with floated links. After getting it working I was stuck with this problem, and so far have not come to a solution.
My links have these dots in them. As the picture shows.
My code is simple:
HTML
<div id="nav-wrapper">
<div id="navbar">
<ul id="nav">
<li>Home</li>
<li>About</li>
<li>Blog</li>
<li>Contact Us</li>
</ul>
</div>
</div>
and the CSS
#nav-wrapper {
background-color: black;
height: 40px;
width: 100%;
border-top: 2px solid gray;
border-radius: 0 0 5px 5px;
}
#navbar {
}
ul#nav li {
float: left;
font-family: sans-serif;
font-size: 18px;
text-decoration: none;
}
ul#nav * a {
width: 25px;
margin: 0 10px 10px 0;
}
My question is what is causing these dots? And why don't they appear if I add more words/links to the list or I erase all but one item? It's odd. I must be missing something extremely embarrassing because this just seems odd.
You want to use the code - list-style: none;
so your code will look like
ul#nav li {
float: left;
font-family: sans-serif;
font-size: 18px;
text-decoration: none;
list-style: none;
}
Add this style:
list-style-type: none;
To this selector:
ul#nav li
Modify your declaration for ul#nav li to include this property
list-style:none;
http://jsfiddle.net/bcDDk/

CSS: Make "hover" of the "a" tag inside of "span" tag, gone

I have a small problem with a hover. So I want to make hover of the a tag inside of span tag, gone.
Here is my HTML file:
<nav id="top-menu">
<ul>
<li> Home </li>
<li> <span>Products</span> </li>
<li> Statistics </li>
<li> Countries </li>
<li> Settings </li>
<li> Contacts </li>
</ul>
</nav>
And here is my CSS file:
nav#top-menu {
width: 100%;
height: 33px;
background-color: #696969;
margin: 0;
padding: 0;
}
#top-menu ul {
display: block;
list-style-type: none;
width: 600px;
margin: 0 auto;
padding: 0;
}
#top-menu ul li {
margin: 0;
padding: 0;
}
#top-menu ul li a {
display: block;
float: left;
max-height: 25px;
width: 100px;
margin: 0;
padding: 5px 0;
font-family: tahoma, sans-serif;
font-size: 20px;
text-align: center;
background-color: #696969;
text-decoration: none;
color: #FFFFFF;
border-bottom: #696969 solid 2px;
}
#top-menu ul li a:hover { border-bottom: #FFFFFF solid 2px; }
#top-menu ul li span a{
color: black;
}
So I add this to make productshover, gone:
#top-menu ul li span a:hover { }
or
#top-menu ul li span:hover { }
But it didn't. Can anyone tell me what am I doing wrong?
Thanks.
Style the hover same as surrounding style (including text-decoration:none), and flag these as !important so they override the browser default stylesheet.
#top-menu ul li span a:hover {
color: #FFFFFF !important;
border-bottom: #696969 solid 2px !important;
text-decoration: none !important;
}
The properties you have to specifically control, are the ones which the "hover" would normally style. Most typically, that might be color.
Try to add hover for the a with !important like
#top-menu ul li span a:hover {
border-bottom: #FFFFFF solid 2px !important;
}
Because you have already given border-bottom to the anchor tag before.
Say something like that for the span:
span a:hover{/*Nothing here*/}
It should negate the hover effect. Hope this helps.