How to adjust height and area of nav links in Materialize CSS? - html

I have a brand-logo in my navbar and to make it fit and look good, I had to increase the height of my navbar. However, after doing so the nav links stay in the position as if the height never changed. To fix that I had to add a margin to the ul tag. Even though that did push down the links enough, the hover effect does not extend to surround the full height of the navbar. How do i fix this?
html:
<nav class="deep-orange darken-2">
<div class="nav-wrapper container">
<a class="brand-logo" href=""><img src="logo.png" alt=""></a>
<ul class="hide-on-med-and-down right nav-links">
<li>Home</li>
<li>Admission</li>
<li>Mentors</li>
<li>Location</li>
</ul>
</div>
</nav>
css:
.brand-logo img {
height: 95px;
}
nav {
height: 100px;
}
.nav-links {
margin-top: 15px;
}

Ok, quick answer is line-height:
nav {
height: 100px;
}
nav ul li,
nav ul li a,
.brand-logo {
line-height: 100px;
}
https://codepen.io/doughballs/pen/vYNGGYW
Materialize nav links all get their spacing via line height, which is passed down from nav height, and when you chnage the height manually with CSS , you also need to change the line height.
Also - Materialize has two nav heights, mobile and above, and they are set at certain breakpoints. The absolute best way to do this si suing sass - you change the height of the nav once, and then all the line heights are updated from this one variable.
If this is something you're interested in, let me know and I'll update the pen.
You don't need to do anything crazy with margins - use the same conventions that Materialize uses.

Related

Image link to homepage is not clickable

I have a logo on the top left of my website which links to the home page. Some areas of the image aren't clickable. The areas that can be clicked work fine. The clickable/non-clickable areas seem to be dispersed randomly. How can I make the link work across the entire area of the logo?
<header>
<nav>
<a id="nav-logo" href="index.html">
<img src="img/logo-header.png" alt="logo" />
</a>
</nav>
</header>
#nav-logo,
nav img{
display: inline-block;
float: left;
height: 65px;
margin: 5px;
cursor: pointer;
}
Try this
#nav-logo { display: block; }
Most likely it's the margin which isn't clickable. Also, you are using the same CSS settings for the link AND the image, which doesn't really make sense (both floated and inline-blocks, both have a margin etc.). Make the image display: block, define a width for the container, make the image width 100% and its height auto

Vertical Alignment isn't quite right

I'm trying to vertically align a logo and UL within a navigation bar. I've got pretty close and it looks fine really, however there is some extra space underneath and above them both that I can't account for. I've set the padding on the links and logo to allow the user to be able to click them more easily.
Place the mouse underneath the logo and underneath the nav bar, I've tried to do it so that as soon as your mouse reaches the nav bar, it hits the padding of the logo and therefore the mouse cursor turns to pointer. However, there is a gap there...using the developer tools, I can see that it's the div.inner element...but it says it has a margin. I've tried setting the margin to 0 on that div and it doesn't go away.
Here is the jsfiddle example: http://jsfiddle.net/Forresty/0smpmsqn/2/
I'm using the same vertical alignment method as here: http://webdesign.tutsplus.com/tutorials/the-holy-grail-of-css-centering--cms-22114
Here is the HTML:
<nav>
<div class="outer">
<div class="inner">
<div class="logo1">LOGO</div>
<ul>
<li>About</li>
<li>My Work</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
Any help would be greatly appreciated. Or even if it's not possible to get rid of that extra space, an explanation of why it's there would be great.
Thanks in advance.
Remove
Display: table-cell;
To align in the middle use
line-height | Margin | Padding
The display table cell add's the space
You can change the following:
.outer {
display: table;
width: 100%;
height: 100%;
padding: 0;/*set padding to 0*/
}
.logo1 {
display: inline-block;
font-family: dan_custom-font;
font-size: 2em;
float: left;
margin: 0.3em;/*replace padding with margin*/
margin-left: 0.7em;/*set a bit more margin left*/
cursor: pointer;
color: #de1b1b;
text-align: center;
-webkit-transition: color .3s;
transition: color .3s;
}
fiddle
You can set .outer class padding: 0 and replace margin with padding in .logo1.
You have many options.
Adjust the height of the nav so that it fit the logo and ul.
Adjust the padding of the logo and ul so that it fits the nav.
To see whether they fit, first set a background color for logo and the ul and check.

How to make a List Item the same height as the parent div?

<nav>
<ul id="navUl">
<li>
<div class="settingsDiv">
hey
</div>
</li>
</ul>
</nav>
What I want to do is set the div's height to 100% so that it'll be whatever height the nav is.
I can't say what you've done wrong - because you didn't supply your CSS code.
But here is a working copy of what you're asking: http://jsfiddle.net/WDAXp/2/
You need to set <nav>'s height, then set #navUl, #navUl li, and settingsDiv height to 100%.
edit
oops, didn't read the question properly. fixed it.
You have to give the nav some fixed height, and the others inherit from the parent.
nav {
height: 100px;
}
ul, li, .settingsDiv {
height: inherit;
}
jsFiddle

How to have a navbar similar to the one on Twitter Bootstrap's website

How can we create a navbar similar to the one on Twitter Boostrap's website? The navbar is black, and more importantly is centered in the middle of the page. The alignment of the links seem to be too high too.
The navbar created using the code below is aligned to the left. How do you get it to be centered with a max width like on Twitter Bootstrap's website.
Target navbar
Attempt
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<a class="brand" href="#">Bootstrap</a>
<ul class="nav">
<li class="active">Home</li>
<li>Get Started</li>
<li>Scaffolding</li>
</ul>
</div>
</div>
one nice technique i like for aligning the links always to the center is to use line-height:
.navbar-inner { height: 60px; }
.nav { line-height: 60px; }
make it the same as the height of the container div, whether this is placed on .navbar-inner or .nav is your call. but it will make the text of the links always vertically aligned in the middle.
Using the bootstrap framework, .navbar-inner should have the same css applied to it as .container or .container-fluid (depending on if you are using the fluid layout or not). For non-fluid layouts this means the following rules:
.navbar-inner {
margin: 0 auto;
width: 1140px; /* or whatever width you choose for your .container */
}
fluid layouts this means:
.navbar-inner {
padding: 0 20px;
}
You need to put everything inside the navbar-inner inside a <div class="container">.

Converting margin from pixel to percentage - breaks float left element

I have the following HTML block:
<div class="container clearfix">
<div class="grid_8 omega">
<ul class="nav">
<li>About</li>
<li>Cupcakes & Prices</li>
<li>Locations</li>
<li class="last">Contact Us</li>
</ul>
</div>
Which is styled this way:
ul.nav {
margin-top: 18.18%;
list-style: none;
float: right;
}
ul.nav li {
float: left;
margin-right: 40px;
}
And this gives me the following result (Web developer toolbar outlines on):
Now I am trying to change the 40px margin to percentage in order to make the site more fluid and from I have learnt I should use the target / context = result which in this case is 40px / 660px = 0.06 which is roughly 6%. I then change the 40px to 6% and I get the following instead:
What have I done wrong here? The width of the ul block has shrunk and the margin-right is not changing when I resize the browser window. It seems no matter what amount of percentage I put in there is no value in percentage that makes this work at all. I must be using percentages wrong? Why isn't it working?
Ok, I figured it out thanks to #AliBassam 's comment
As he said, the percentage of margin-right is related to the parent element ul instead of div. The width of the ul block is related to how much margin the li element has, but if that margin is a percentage of the ul width then both elements are depending on each other and it just makes no sense.
To fix that, you need to set a width to ul.nav:
ul.nav {
width: 83%;
margin-top: 18.18%;
list-style: none;
float: right;
}
That is 83% of 600px that is in the div containing the ul.nav which translates to around 500px
I doesn't know what the height is... so it doesn't know what 18.8% is. You have to declare the html and body 100% height first. and all things within... it's tricky. like #Mr_Green says... it's basing on width because it's insane!!! also... 18.8 os a whack number. (same with the ul... 6.3498% of what... ? )