How to change size of Nav bar - html

All the questions I've looked at refer to WordPress or Bootstrap (what is that?) nav bars, I have made mine using CSS.
I would like to make my nav bar bigger so that it's easier for mobile users to click the correct link. I've tried using the height: px; but all that did was push the text below further down.
What do I use to change the size of the buttons themselves? included my CSS below.
html{background:gray;}
ul {
left: 0;
top: 50%;
width: 100%;
text-align: center;
display: inline-block;
list-style-type: none;
}
li {
display: inline-block;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin: 0
}
li a:hover:not(.active) {
background-color: #111;
}
<ul>
<li><a class="active" href="#home">Home</a>
</li>
<li>About
</li>
<li>Contact
</li>
</ul>

Please note I have added backgrounds in order to display the navbar, and are not required in production
You are OK to use the ul and li elements within your code. In order to make the navbar appear 'taller', you would need to set both the height of the ul element itself, as well as the child li. A quick demo has been provided below.
I have given the height of the ul element 100px, although this value can be changed to your preference. Note you may also want to change line-height property of your a elements to suit this.
html,body {
background: gray;
margin:0;
padding:0;
}
ul {
left: 0;
top: 50%;
text-align: center;
display: block;
list-style-type: none;
background: dimgray;
height: 100px; /* <-- change this line*/
}
li {
display: inline-block;
height: 100%;
}
li a {
display: inline-block;
color: white;
background: lightgray;
line-height: 100px; /* <-- change this line*/
text-align: center;
padding-left: 50px;
padding-right: 50px;
text-decoration: none;
margin: 0;
height: 100%;
}
li a:hover:not(.active) {
background-color: #111;
}
<ul>
<li><a class="active" href="#home">Home</a>
</li>
<li>About
</li>
<li>Contact
</li>
</ul>

What do I use to change the size of the buttons themselves?
Add more padding! Take a look-see.
body {background-color: gray;}
ul {
left: 0;
top: 50%;
width: 100%;
text-align: center;
display: inline-block;
list-style-type: none;
}
li {
display: inline-block;
}
li a {
display: block;
color: white;
text-align: center;
padding: 2em; /* bigger button? add more padding! */
text-decoration: none;
margin: 0
}
li a:hover:not(.active) {
background-color: #111;
}
<ul>
<li><a class="active" href="#home">Home</a>
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
There are many ways to increase the size of the link. This is just one way. jbutler's answer is a good way too. It just depends on what exactly you want it to do.
Hope this helps.

If you are trying to make the text itself larger you can use the font-size property.

Related

How to change the color of only one elemet and move only one element to right side?

This is my HTML:
<nav class="navbar">
<ul>
<li><a class="active home_button" href="#home">Home</a></li>
<li>Profile</li>
<li>Results</li>
<li>About Us</li>
</ul>
</nav>
This is the CSS:
.navbar {
height: 73px;
width: 100%;
}
.navbar ul {
list-style-type: none;
margin: 0;
height: 70px;
padding: 0;
overflow: hidden;
background-color: #362890;
}
.navbar li {
float: left;
}
.navbar li a {
display: block;
color: #fff;
text-align: center;
padding: 22px 20px;
text-decoration: none;
font-size: 26px;
I want to do two things. Firstly I want to make the color of Home orange. Secondly, I want to move About Us on the right side while keeping others on the left side. How can I do that?
Use float:right for the About Us item, and color:orange for the Home item.
.navbar {
height: 73px;
width: 100%;
}
.navbar ul {
list-style-type: none;
margin: 0;
height: 70px;
padding: 0;
overflow: hidden;
background-color: #362890;
}
.navbar li {
float: left;
}
.navbar li a {
display: block;
color: #fff;
text-align: center;
padding: 22px 20px;
text-decoration: none;
font-size: 26px;
}
.home_button{
color:orange !important;
}
#about-us{
float:right;
}
<nav class="navbar">
<ul>
<li><a class="active home_button" href="#home">Home</a></li>
<li>Profile</li>
<li>Results</li>
<li id="about-us">About Us</li>
</ul>
</nav>
I think adding a
!important to .home_button should do the trick, give it a try...
Example
.home_button {
color: orange !important;
}
The !important property in CSS is used to provide more weight (importance) than normal property. In CSS, the !important means that “this is important”, ignore all the subsequent rules, and apply !important rule
For more info on how !important works check here
give home and about a class, then style it

How can I make the background color here to not move whan I hover the links?

This is A navigation bar with links that I made. I want that the black background will not move when hovering...
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333333;
width: 40%;
}
li {float: left;}
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
li a:hover {font-size: large;}
<body>
<nav>
<ul>
<li> Home </li>
<li> Articles </li>
<li> About us </li>
</ul>
</nav>
</body>
You can use transform:scale(X), it won't disturb the flow
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333333;
width: 40%;
}
li {float: left;}
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
li a:hover {transform:scale(1.15);}
<body>
<nav>
<ul>
<li> Home </li>
<li> Articles </li>
<li> About us </li>
</ul>
</nav>
</body>
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transforms/Using_CSS_transforms
By modifying the coordinate space, CSS transforms change the shape and position of the affected content without disrupting the normal document flow. This guide provides an introduction to using transforms.
I suppose you wanted to do something like this. Though I would suggest as #g-cyrelius mentioned, in other answer -- You should make use of transform: scale(2) or something, to avoid break of flow, in your code.
I tried to use your code font-size: large, but this is not the better option.
ul {
list-style-type: none;
margin: 0;
padding: 0;
background-color: #333333;
width: 80%;
}
li {display: inline-block;text-align:center;position:relative;height: 50px;width: 30%;box-sizing: border-box;}
li a {
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
position:absolute;
top: 0;
left: 30%;
}
li a:hover {
font-size: large;
}
<nav>
<ul>
<li> Home </li>
<li> Articles </li>
<li> About us </li>
</ul>
</nav>

How to fit tabs according to screen size / browsers?

I have a 4 tabs which I have showed below. It keeps moving as the screen size changes and with different browsers. I see about.html going down each time I open it on different computers it doesn't stay on a single line tab. I need to keep changing my width:303px.
Actually I need to reduce it on different computers and browsers. Whats the best way to fix this so that it stays on a single line with rest of the tabs.
css
ul
{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li
{
float: left;
}
a:link, a:visited {
display: block;
width:303px;
font-weight: bold;
color: #FFFFFF;
background-color: #98bf21;
text-align: center;
padding: 4px;
text-decoration: none;
text-transform: uppercase;
}
html
<ul>
<li>Home</li>
<li>Offers</li>
<li>Contact<li>
<li>Links</li>
<li>About us</li>
</ul>
<br>
<br>
You have a couple of options that will space and align these without explicit widths (either % or actual px/em etc values):
CSS Tables (Green Version) - Support IE8 and above
ul.table {
display: table;
table-layout: fixed;
width: 100%;
}
ul.table li {
display: table-cell;
}
Flexbox (Plum Version) - Support IE10 and above
ul.flex {
display: flex;
}
ul.flex li {
flex:1;
}
Demo of both
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
margin-bottom: 1em;
}
ul.table {
display: table;
table-layout: fixed;
width: 100%;
}
ul.table li {
display: table-cell;
}
ul.flex {
display: flex;
}
ul.flex li {
flex: 1;
}
ul.flex a {
background: plum;
}
a:link,
a:visited {
display: block;
font-weight: bold;
color: #FFFFFF;
background-color: #98bf21;
text-align: center;
padding: 4px;
text-decoration: none;
text-transform: uppercase;
}
<ul class="table">
<li>Home
</li>
<li>Offers
</li>
<li>Contact
</li>
<li>Links
</li>
<li>About us
</li>
</ul>
<ul class="flex">
<li>Home
</li>
<li>Offers
</li>
<li>Contact
</li>
<li>Links
</li>
<li>About us
</li>
</ul>
Note: This is not a one-stop solution. At some point the screen may not be wide enough to hold all the text. At that point you need media queries.
You could use the calc() function....
width: calc(100% / X);
Where X is the number of tabs.
You can also use....
width: calc((100% / X) - Ypx);
Where Y is the sum amount of padding, margin, or space you want between tabs.
So for 4 tabs with margin: 0 5px; between them and a 1px border on them, you'd use:
width: calc((100% / 4) - 48px);
More info here

Center Nav Bar when window resized?

My navigation bar is centered, but when the window is smaller, it just goes onto the next line, rather than getting smaller to fit the size of the window, and I don't know how to resolve it. It's got drop down elements on it. I'll also be looking at turning this to a vertical list when viewed on mobile devices, but nowhere near doing media queries yet.
Here's my HTML:
<nav id="page-navigation">
<ul>
<li>Home</li>
<ul class="top-menu">
<li>Photography
<ul class="sub-menu">
<li>BMC Himley Mini Show 2015</li>
<li>Kinver Snow</li>
<li>"Mini Runs" Collection</li>
<li>Hofner Bass</li>
<li>Nature</li>
<li>Haynes Motor Museum</li>
<li>Miscellaneous</li>
<li>Classic Mini</li>
</ul>
</li>
<li>Graphic Design
<ul class="sub-menu">
<li>"Story Bag" Artwork</li>
<li>Business Cards</li>
<li>Logo Design</li>
<li>"The Mexican Job"</li>
<li>Magazine Covers</li>
<li>WPAP Artwork</li>
<li>Lyrics Posters</li>
</ul>
</li>
<li>3D Modelling</li>
</ul>
<li>About</li>
<li>Recognition</li>
</ul>
</nav>
And here's my CSS:
/*navigation*/
#page-navigation
{
width: 60%;
height: 53px;
margin-left: auto;
margin-right: auto;
margin-bottom: 10px;
}
#page-navigation ul li
{
color: white;
list-style: none;
background-color: darkslategray;
width: 9em;
float: left;
}
li
{
position: relative;
}
li.title
{
display: none;
}
li a
{
display: block;
color: white;
line-height: 1.3em;
padding: 1em;
text-align: center;
}
li a:link
{
text-decoration: none;
}
li a:visited
{
text-decoration: none;
color: white;
}
li a:hover, .top-menu > li:hover > a
{
background-color: rgb(48,48,48);
}
li a:active
{
background-color: dimgray;
}
ul.sub-menu
{
width: auto;
height: auto;
position: absolute;
left: -9000em;
overflow: hidden;
}
ul.sub-menu li
{
clear: left;
float: none;
margin-left: -2.5em;
z-index: 1000;
}
.top-menu li:hover ul
{
left: 0;
}
ul.sub-menu li a
{
height: auto;
border-bottom: 1px solid gray;
padding: .4em 1em;
background-color: dimgray;
padding-top: 1em;
padding-bottom: 1em;
}
ul.sub-menu li:last-child a
{
border-bottom: none;
}
ul.sub-menu li a:hover
{
background-color: darkslategray;
}
ul.sub-menu li a:active
{
background-color: gray;
}
Thank you.
Your menu is specified as a variable width of 60%:
#page-navigation
{
width: 60%;
...
}
This will cause the width of the bar to scale with the window, and affect the position of the elements within it. To prevent this, specify a static width, such as:
#page-navigation
{
width: 1000px;
...
}
I just insert a line of code and I think it looks pretty nice right now :)
ul.top-menu{
padding: 0;
}
If you resize the screen there is in front of the navigation (next line) a small space and this resolves the problem.
See the resolution also on jsfiddle.
Answer:
Because of the way your HTML document is structured, it's not possible for you to get the intended effect for the following reason:
You have an unordered list nested directly in another unordered list which is (1) not considered correct (see this discussion); but more importantly, while it looks like your navigation has 6 top level items, you really only have 4. So no matter what CSS you apply to it, it won't work.
Recommendations:
Fix the structure of your HTML document first by using the proper classes only on the top navigation items and properly nest your navigation items.*
I would advise restructuring you information architecture to contain less navigation items on the menu. For example, the recognition would make sense to go in your About page. And if this is a portfolio type website, collapsing your Photography, Graphic Design, and 3D Modeling into Projects would work well. And if you're concerned with the separation, that will happen within the page as a sub-navigation.
If you are set on keeping the navigation structure, it's advisable to either collapse your menu into a select menu or hamburger menu on mobile devices since having a large chunk someone's mobile device screen consumed by your navigation is not a good experience for your user. On top of it, you have to consider that users can't "hover" on mobile devices and the size of those dropdowns would be difficult to navigate at best.
*Solution: Demo
HTML (Fixed):
<nav id="page-navigation">
<ul>
<li>Home</li>
<li class="top-menu">Photography
<ul class="sub-menu">
<li>BMC Himley Mini Show 2015</li>
<li>Kinver Snow</li>
<li>"Mini Runs" Collection</li>
<li>Hofner Bass</li>
<li>Nature</li>
<li>Haynes Motor Museum</li>
<li>Miscellaneous</li>
<li>Classic Mini</li>
</ul>
</li>
<li class="top-menu">Graphic Design
<ul class="sub-menu">
<li>"Story Bag" Artwork</li>
<li>Business Cards</li>
<li>Logo Design</li>
<li>"The Mexican Job"</li>
<li>Magazine Covers</li>
<li>WPAP Artwork</li>
<li>Lyrics Posters</li>
</ul>
</li>
<li>3D Modelling</li>
<li>About</li>
<li>Recognition</li>
</ul>
</nav>
CSS (Fixed and Updated):
/*navigation*/
#page-navigation {
width: 100%;
margin-left: auto;
margin-right: auto;
margin-bottom: 10px;
}
#page-navigation ul {
text-align: center;
}
#page-navigation ul li {
color: white;
list-style: none;
background-color: darkslategray;
width: 9em;
/* float: left removes any possibility of it centering */
display: inline-block;
}
li {
position: relative;
}
li.title {
display: none;
}
li a {
display: block;
color: white;
line-height: 1.3em;
padding: 1em;
text-align: center;
}
li a:link {
text-decoration: none;
}
li a:visited {
text-decoration: none;
color: white;
}
li a:hover,
.top-menu > li:hover > a {
background-color: rgb(48, 48, 48);
}
li a:active {
background-color: dimgray;
}
ul.sub-menu {
width: auto;
height: auto;
position: absolute;
left: -9000em;
overflow: hidden;
}
ul.sub-menu li {
clear: left;
float: none;
margin-left: -2.5em;
z-index: 1000;
}
.top-menu:hover ul {
left: 0;
}
ul.sub-menu li a {
height: auto;
border-bottom: 1px solid gray;
padding: .4em 1em;
background-color: dimgray;
padding-top: 1em;
padding-bottom: 1em;
}
ul.sub-menu li:last-child a {
border-bottom: none;
}
ul.sub-menu li a:hover {
background-color: darkslategray;
}
ul.sub-menu li a:active {
background-color: gray;
}
ul.top-menu {
padding: 0;
}
There are still some minor stylings to adjust, but this should get you what you wanted based on your question.

Horizontal list li not taking up the whole height

<ul class="nav">
<li><i class="icon-home"></i></li>
<li>Blog</li>
<li>Elements</li>
<li>Contact us</li>
</ul>
.nav {
line-height: 70px;
margin: 0;
padding: 0;
border: 0;
}
.nav li {
list-style-image: none;
list-style-type: none;
margin-left: 0;
white-space: nowrap;
display: inline;
float: left;
padding-left: 4px;
padding-right: 4px;
}
.active {
background: pink;
}
.icon-home {
background: url(http://i.stack.imgur.com/MNme0.png) no-repeat;
width: 16px;
height: 14px;
display:block;
}
body {
background: gray;
}
How do I make the background of .active take up the whole height of li and center the icon? If you check the demo it doesn't respect the line-height of the li.
Demo: http://codepen.io/anon/pen/ulEGw
You could set .icon-home to display: inline-block;, which will center it vertically with the rest of the text.
You can also keep your line-height this way.
Assuming you want to keep your line-height: 70px on .nav, put height: 70px; on .icon-home.