Gaps at the top and side of navigation bar buttons - html

I'm creating a website and have run into a minor but incredibly infuriating problem.
I'm creating a Navigation bar and the buttons of the navigation bar have a gap between the far left, and top of the screen. In other words, all buttons have a gap from the top and the leftmost button has a gap from the left of the screen.
The relevant parts of my Stylesheet are shown below.
body {
margin: 0px;
padding: 0px;
font-family: Arial;
}
.navbar_base {
width: 100%;
overflow: hidden;
background-color: rgb(0, 21, 144);
top: 0px;
color: white;
display: block;
}
.navbar_button {
float: left;
padding: 10px;
margin: 0px;
border-radius: 3px;
list-style-type: none;
}
.navbar_button:hover {
background-color: rgb(50, 64, 147);
}
I suspect it's because I have assigned the class to the list rather then the links, but I'm using MVC5 and adding classes to the Html.Actionlink() is cumbersome. I'd like to avoid this solution if possible.
Furthermore I've tried assigning margin: 0px and padding: 0px on ul like so:
ul .navbar_button {
margin: 0px;
padding: 0px;
}
to no avail
Also I am not interested in using Bootstrap at the moment because this is a sort of side project for a specific person and I would like to create something unique for him.
Here is the HTML portion of my code:
<div class= "navbar_base">
<ul>
<li class="navbar_button"> #Html.ActionLink("MainPage","MainPage") </li>
<li class="navbar_button"> #Html.ActionLink("About","AboutPage") </li>
</ul>
</div>
I've looked at the following questions as well, but the answers didn't help me.
Gap at top of page despite margin:0 and padding: 0
Why does this div have gaps at top and bottom
How do I get rid of the two gaps?
Note: I do realize I am still a beginner and MVC may be out of my scope but I have job to do soon and I reckoned the fastest way to learn about how to do MVC is to actually do MVC

<div class= "navbar_base">
<ul>
<li class="navbar_button"> #Html.ActionLink("MainPage","MainPage") </li>
<li class="navbar_button"> #Html.ActionLink("About","AboutPage") </li>
</ul>
By default ul has some margin left properties , you can remove it by
.navbar_base > ul{ margin-left:0px; }

You need to remove the margin and padding from the ul too (your attempt to do so removed it from the li)
body, ul {
margin: 0px;
padding: 0px;
font-family: Arial;
}
.navbar_base {
width: 100%;
overflow: hidden;
background-color: rgb(0, 21, 144);
top: 0px;
color: white;
display: block;
}
.navbar_button {
float: left;
padding: 10px;
margin: 0px;
border-radius: 3px;
list-style-type: none;
}
.navbar_button:hover {
background-color: rgb(50, 64, 147);
}
<div class="navbar_base">
<ul>
<li class="navbar_button"> #Html.ActionLink("MainPage","MainPage") </li>
<li class="navbar_button"> #Html.ActionLink("About","AboutPage") </li>
</ul>
</div>

Related

Why is my paragraph element displaying behind a background color

So im making a website for a school project and all was hunky dory until i tried to put a paragraph element in and it displays above the title text behind the background color
.container {
width: 80%;
margin: 0;
padding: 0;
}
#logotext {
float: left;
font-family: 'Doppio One';
margin-left: 25px;
}
nav {
float: right;
}
#nav {
list-style-type: none;
text-decoration: none;
margin-top: 35px;
}
ul li {
display: inline;
}
li a {
text-decoration: none;
color: white;
}
li a:hover {
color: #fc9516;
}
.darkwrap {
background-color: #414a4c;
position: fixed;
overflow: hidden;
}
.active {
color: #22cc25;
}
#clock {
position: absolute;
top: 0;
right: 0;
margin-top: 25px;
margin-right: 25px;
font-family: Rajdhani;
font-size: 30px;
}
<div class="container darkwrap">
<div id="logotext">
<h1>JF Web Design</h1>
</div>
<!-- Navigation Bar -->
<nav>
<ul id="nav">
<li> Page 1 </li>
<li> About </li>
<li> Page 3 </li>
</ul>
</nav>
</div>
</header>
<span id="clock"></span>
<p>
Hello
</p>
<footer></footer>
i usedchrome to highlight the faulty element so its clear whats happening here its literall positioned at the top behind the bg color
Console Highhlighted element
.darkwrap is position: fixed.
This takes it out of normal flow and locks its position relative to the viewport.
The rest of the content is laid out as normal as if the .darkwrap element didn't exist … so it ends up covered up by it.
You could use margins to compensate for the space covered up by .darkwrap when the viewport is scrolled to the top. I would simply avoid using position: fixed in the first place: The benefits of having the menu on screen all the time very rarely outweigh the drawback of using up all that vertical space all the time.
If you use float: left and float:right please remember to add clear:both to the next element on the website. Here is fixed code:
https://codepen.io/anon/pen/jKRqLz

How to remove space above and below the in-line block elements?

I can't seem to figure out how to remove space above and below my inline block elements as shown in the image.
P.S line-height doesn't remove the space.
Here is the CSS for all the elements.
nav ul li {
font-size:16px;
display:inline-block;
padding:20px;
border: 3px solid black;
}
Image:
JsFiddle
ul has by default margin and padding, so reset it
body {
padding: 0;
margin: 0;
font-family: sans-serif;
}
header {
background: #00795f;
width: 100%;
padding: 40px 0;
/* 40px top and bottom, 0px left and right */
color: white;
text-align: center;
}
nav {
background-color: #43a286;
color: white;
overflow: hidden;
padding: 0px;
text-align: center;
margin: 0;
}
ul {
/* padding: 0; you may need only the margin */
margin: 0
}
a {
text-decoration: none;
color: inherit;
}
nav ul li {
font-size: 16px;
display: inline-block;
padding: 20px;
border: 3px solid black;
}
ul li:hover {
background-color: #399077;
}
section {
line-height: 1.5em;
font-size: 1.5em;
padding: 40px;
width: 75%;
margin: 0 auto;
}
<header>
<h1>Loving it more everyday</h1>
</header>
<nav>
<ul>
<li> Home
</li>
<li> About
</li>
<li> Blog
</li>
<li> Shop
</li>
<li> Gallery
</li>
<li> Contact
</li>
</ul>
</nav>
<section>
When you try your best, but you don't succeed. When you get what you want, but not what you need. When you feel so tired, but you can't sleep. Stuck in reverse. And the tears come streaming down your face. When you lose something you can't replace.When
you love someone, but it goes to waste. Could it be worse? Lights will guide you home. And ignite your bones. And I will try to fix you. And high up above or down below. When you're too in love to let it go. But if you never try you'll never know.
Just what you're worth. When you try your best, but you don't succeed. When you get what you want, but not what you need. When you feel so tired, but you can't sleep. Stuck in reverse. And the tears come streaming down your face. When you lose something
you can't replace.When you love someone, but it goes to waste. Could it be worse? Lights will guide you home. And ignite your bones. And I will try to fix you. And high up above or down below. When you're too in love to let it go. But if you never
try you'll never know. Just what you're worth
</section>

Issues getting nav to be responsive

I am trying to make my navbar look good on mobile devices and for it to be responsive. However, it looks horrible right now via mobile and all mushed together. Is there anyway I could make this look any better without making the links crazy small?
Please look at it via mobile at a page I made up for everyone to see on here..
sundayfundayleague.com/show_nav.php
For some reason in the page I created, all of these links are not showing up in the navbar..
<li>
Draft Selection
</li>
</ul>
</div>
<div class="nav_right">
<ul>
<li>
<?php echo escape($user->data()->username); ?>
</li>
<li>
Messages
</li>
<li>
Admin
</li>
<li>
Log Out
</li>
</ul>
</div>
Usually it will just compress all of the links and it looks awful.
What can I do to make all the things show up and for it to look good?
This is my media query for the header/navbar...
.spectator_header {
position: relative;
height: 200px;
}
.spectator_nav {
height: 75px;
background-color: #800000;
left: 2%;
display: inline;
bottom: 0;
position: absolute;
width: 95%;
font-size: .7em;
font-style: Helvetica;
-moz-border-radius: 0px;
-webkit-border-radius: 15px 15px 0px 0px;
border-radius: 15px 15px 0px 0px;
-webkit-box-shadow: 0px 0px 16px #C0C0C0;
-moz-box-shadow: 0px 0px 16px #C0C0C0;
box-shadow: 0px 0px 16px #C0C0C0;
}
.spectator_nav li a {
text-decoration: none;
display: block;
}
.spectator_nav li:hover ul {
display: block;
}
.spectator_nav ul {
padding: 0px;
}
.spectator_nav li {
position: relative;
float: left;
list-style-type: none;
padding: 25px 4px;
}
.spectator_nav li:first-child {
margin-left: 5px;
}
.spectator_nav li:last-child {
margin-right: 5px;
}
.spectator_nav ul:after {
content: ".";
display: block;
height: 0px;
clear: both;
visibility: hidden;
}
Mobile nav can be very tricky and there are lots of ways to approach it. I'd recommend looking at some resources like This Is Responsive or CSS-Tricks to get some ideas on how to tackle this. There are lots of options so find one that works for you.
The reason not all the links are showing is because the last one is breaking to a new line. Since the container has a fixed height of 75px and there's so much padding around the <li>s you can't see the link on the second line. That's part of why mobile nav is tricky, when you have too many links to comfortably fit on a horizontal line you have to decide how to handle it.
Do you want to your nav to grow to multiple lines, or switch to a hamburger or select menu? Do you want to just cram all the links on a single line no matter what? Do you need to allow for adding more nav links or changing the font size or weight in the future? This would add length to the nav list and affect the approach you want to take. If you have more info I can point you to a good solution, but if your question is simply "how do I make this responsive?" then you need to ask more questions first.

Element only shows sometimes

I'm trying to make a menubar for my website with home, about, and contact links. They are aligned on the right side of the page. For some reason, when I reload the page, sometimes contact seems to return to the next line. I don't have to change anything for this to happen.
Here is the relevant css:
ul#menubar {
display: inline-block;
list-style-type: none;
font-family: "Cantarell";
float: right;
margin-right: 5%;
margin-top: 0;
margin-bottom: 0;
}
li.menubar_item {
display: inline-block;
padding-right: 5%;
}
li.menubar_item a {
color: #D2F2FE;
text-decoration: none;
}
div.menubar_div {
height: 150px;
padding-right: 5%;
}
And the HTML:
<ul id="menubar">
<li class="menubar_item">
<div class="menubar_div">Home</div>
</li>
<li class="menubar_item">
<div class="menubar_div">About</div>
</li>
<li class="menubar_item">
<div class="menubar_div">Contact</div>
</li>
</ul>
It's your padding-right: 5% that ruins it. Since you haven't set a width for the ul#menubar, it's automatically set to 100%. The problem is that the width expands with the padding, causing it to be a total of 115% (100 + 5x3).
You can add this to your ul#menubar:
width: 85%;
text-align: right;
Try adding this line in your CSS :
ul#menubar {
white-space:nowrap;
}
The property white-space:nowrap force the li elements to be side by side

HTML: How do you make a horizontal Navigation Bar have drop down menus?

I'm fairly new to HTML/CSS coding, but I'm currently learning and developing a website. However, I'm sort of stuck on the process of my navigation bar. I managed to get a navigation bar to work, a horizontal one, with a working background image. The one thing I do have trouble with is having my navigation bar have drop down menus, like this: http://maxcdn.webappers.com/img/2008/10/free-css-drop-down-menu.png. Except without the extra sub-menus. Here's what I have so far:
HTML:
<div id="menu">
<ul>
<li>home</li>
<li>blank</li>
<li>about</li>
<li>site</li>
<li>contact</li>
</ul>
</div>
<div style="z-index:0;left:0;top:0;width:100%;height:100%">
<img src="unknown.jpg" style='width:100%;height:100%'/>
</div>
CSS:
#menu {
width: auto;
height: auto;
font-size: 16px;
font-family: Tahoma, Geneva, sans-serif;
font-weight: bold;
text-align: center;
text-shadow: 3px 2px 3px #333333;
background-color: #8AD9FF;
border-radius: 8px;
}
#menu ul {
height: auto;
padding: 8px 0px;
margin: 0px;
display: inline;
}
#menu li {
display: inline;
padding: 20px;
}
#menu a {
text-decoration: none;
color: #00F;
padding: 8px 8px 8px 8px;
}
#menu a:hover {
color: #F90;
background-color: #FFF;
}
Sorry if the question is relatively easy to answer, but I'm having trouble. I'm not sure how to change my HTML code into a code where visitors can hover their mouse over, for example, contact and they'll have the option to pick either Administrator or Other. Thank you.
You'll need to define the onmouseover event of the relevant elements and then, using some Javascript, append new elements somewhere in your menu div (or trigger their visibility). Not the easiest thing to start with for a beginner !