How to remove unwanted whitespaces - html

I am practicing html/css by making this website but there are some white spaces to the left and right around the links in list of contents. I have added a sample of html code of how complete list is coded.
I have tried setting the margins and paddings of all elements to zero but nothing is working.
body {
margin: 0;
}
.container {
display: grid;
grid-template-columns: 20% 80%;
margin: 0;
}
.nav_bar {
min-height: 100vh;
overflow-y: auto;
margin: 0;
padding: 0;
}
.nav_bar ul {
display: block;
padding: 5px;
list-style: none;
font-size: 0;
margin: 0;
}
.nav_bar li {
padding: 10px 5px;
border-bottom: 2px solid black;
}
<div class="container">
<div class="nav_bar">
<h3>JS DOCUMENTATION</h3>
<ul class="nav_list">
<li>
Introduction
</li>
</ul>
</div>
</div>
enter image description here

You have given the padding to the ul tag that is the reason why the line did not touch two extreme ends.
just change the padding in the ul to 0
Is this what you are looking for ?
I added the color in order to show where the problem occured
body {
margin: 0;
}
.container {
display: grid;
grid-template-columns: 40% 30%;
margin: 0;
padding:0;
}
.nav_bar {
min-height: 100vh;
overflow-y: auto;
margin: 0;
padding: 0;
}
h3 {
padding: 10px 5px;
}
ul {
display: block;
padding: 0px;
font-size: 0;
margin: 0;
}
li {
padding: 10px 5px;
border-bottom: 2px solid black;
}
li:first-child {
border-top: 2px solid black;
}
a {
text-decoration: none;
color: black;
font-size: 18px;
font-weight: 300;
}
<div class="container" style="background-color:green;">
<div class="nav_bar" style="background-color:lightblue;">
<h3 style="background-color:red;">JS DOCUMENTATION</h3>
<ul style="background-color:pink;" class="nav_list">
<li>
Introduction
</li>

Are u expecting like this :
NOTE: CHECK MY ANSWER IN FULL SCREEN MODE
#drop-down{
padding-inline-start:0; /*use this css */
}
HTML:
<ul class="nav_list" id="drop-down"> <!-add id="drop-down" to ul-->
<li>
Introduction
</li>
</ul>
#drop-down {
padding-inline-start: 0;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.container {
display: grid;
grid-template-columns: 20% 80%;
margin: 0;
}
.nav_bar {
min-height: 100vh;
overflow-y: auto;
margin: 0;
padding: 0;
}
.nav_bar h3 {
padding: 10px 5px;
}
.nav_bar ul {
display: block;
padding: 5px;
list-style: none;
font-size: 0;
margin: 0;
}
.nav_bar li {
padding: 10px 5px;
border-bottom: 2px solid black;
}
.nav_bar li:first-child {
border-top: 2px solid black;
}
.nav_list a {
text-decoration: none;
color: black;
font-size: 18px;
font-weight: 300;
}
<div class="container">
<div class="nav_bar">
<h3>JS DOCUMENTATION</h3>
<ul class="nav_list" id="drop-down">
<li>
Introduction
</li>
</ul>
</div>
</div>

Assuming you mean the padding on the list items (which you don't currently confiugre in your css), you can do the following;
.nav_list li {
padding-left: 0;
padding-right: 0;
}
This will remove the padding on the left and right side side for each list item in your unordered list.
Also note that in your question, you have not yet set all paddings to 0.
.nav_bar ul {
display: block;
padding: 5px;
list-style: none;
font-size: 0;
margin: 0;
}
If this is not desired behaviour, be sure to set the padding of the unordered list to 0 too.

Related

Problems with horizontal nav bar

I am working on a horizontal navigation bar with a dropdown menu. I'm quite new to making codes so this is maybe a stupid question. My navigation is sticking to the left of my website, but I need it to stay in line with the text and I can't get the navigation bar threw my whole webpage how do I fix this?
photo of my website with the 2 problems:
enter image description here
nav {
position: absolute;
}
.horizontal {
list-style-type: none;
margin: 40 auto;
width: 640px;
padding: 0;
overflow: hidden;
}
.horizontal>li {
float: left;
}
.horizontal li ul {
display: none;
margin: 0;
padding: 0;
list-style: none;
position: relative;
width: 100%;
}
.horizontal li:hover ul {
display: inline-block;
}
.horizontal li a {
display: block;
text-decoration: none;
text-align: center;
padding: 22px 10px;
font-family: arial;
font-size: 8pt;
font-weight: bold;
color: #FFFFFF;
text-transform: uppercase;
border-right: 1px solid #607987;
background-color: #006600;
letter-spacing: .08em;
width: 70px;
}
.horizontal li a:hover {
background-color: darkorange;
color: #a2becf
}
.horizontal li:first-child a {
border-left: 0;
}
.horizontal li:last-child a {
border-right: 0;
}
h1 {
margin-top: 80px;
}
<nav id="mainnav">
<ul class="horizontal">
<li>Home</li>
<li>Planning</li>
<li>Takken
<ul>
<li>Kapoenen</li>
<li>Kawellen</li>
<li>Kajoo's</li>
<li>Jojoo's</li>
<li>Givers</li>
<li>Jin</li>
<li>Akabe</li>
</ul>
</li>
<li>Kleding</li>
<li>Contact
<ul>
<li>Leiding</li>
<li>Verhuur</li>
</ul>
</li>
<li>Inschrijven</li>
</ul>
</nav>
Two things in your css are giving you trouble.
nav{ position: absolute; } means this div will not fill the width.
horizontal{ margin: 40 auto;} 40 is not valid.
You MUST specify a measurement unit in CSS, so it should be 40px if I'm guessing your intention, but other units are available.
Here is amended css you can try.
nav {
width: 100%;
background-color: #006600;
}
.horizontal {
list-style-type: none;
margin: 40px auto;
width: 640px;
padding: 0;
overflow: hidden;
}
Step 1) Add HTML:
Example
<!-- The navigation menu -->
<div class="navbar">
<a class="active" href="#">Home</a>
Planning
Takken
Kleding
Contact
Inschrijven
</div>
And CSS:
.navbar {
width: 100%;
background-color: #555;
overflow: auto;
}
.navbar a {
float: left;
padding: 12px;
color: white;
text-decoration: none;
font-size: 17px;
width: 15%;; /* Four links of equal widths */
text-align: center;
}

How to move a specific element?

An element won't move to my intended position. I want to have some white space between the right of "Register" and the browser but don't know how to do it. I have tried padding but it seem to be kind of wrong thinking.
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
font-family: sans-serif;
color: black;
}
.firstpart {
background-color: #eee;
height: 30vh;
}
.navbar li {
list-style: none;
display: inline;
}
.navbar-left {
float: left;
padding: 20px 20px 0 20px;
}
.navbar-right {
float: right;
padding: 20px 20px 0px 20px;
}
.badge {
background-color: black;
color: white;
height: 35px;
width: 80px;
}
<div class="firstpart">
<div class="navbar">
<ul>
<li class="navbar-left">ABOUT</li>
<li class="navbar-left">CONTACT</li>
<li class="navbar-left">FAQS</li>
<div class="navbar-right badge">
<li>REGISTER</li>
</div>
<li class="navbar-right">SIGN IN</li>
<li class="navbar-right">MANAGE BOOKING</li>
</ul>
</div>
</div>
You just need to add:
.navbar {
padding-right: 10px;
}
You can also remove the div inside of your unordered list as this isn't valid HTML. Replace it with:
<li class="navbar-right badge">REGISTER</li>
Code (open in "Full page" view as otherwise "Manage Booking" gets wrapped):
/* Add this */
.navbar {
padding-right: 10px;
}
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body{
font-family: sans-serif;
color: black;
}
.firstpart{
background-color:#eee;
height: 30vh;
}
.navbar li{
list-style: none;
display: inline;
}
.navbar-left{
float: left;
padding: 20px 20px 0 20px;
}
.navbar-right{
float: right;
padding: 20px 20px 0px 20px;
}
.badge{
background-color: black;
color:white;
height: 35px;
width: 80px;
}
<body>
<div class="firstpart">
<div class="navbar">
<ul>
<li class="navbar-left">ABOUT</li>
<li class="navbar-left">CONTACT</li>
<li class="navbar-left">FAQS</li>
<li class="navbar-right badge">REGISTER</li> <!-- Use an li element instead -->
<li class="navbar-right">SIGN IN</li>
<li class="navbar-right">MANAGE BOOKING</li>
</ul>
</div>
</div>
</body>
I think you could simply set a width for .navbar div to say, 98%
.navbar {
width:98%;
}

Whitespace above navigation bar

I've already added body margin and padding to 0. However, there is still white space above my navigation bar and beneath the image above it that I can't figure out how to remove.
*,
html,
body {
padding: 0;
margin: 0;
}
* {
font-family: Arial, sans-serif;
}
.nav {
width: 750px;
margin: 0 auto;
list-style: none;
}
.nav ul {
font-size: 0;
}
.nav li {
display: inline-block;
border-right: 1px solid black;
padding: 10px 30px 10px 30px;
font-size: 22px;
font-weight: 700;
}
.nav li:first-child {
border-left: 1px solid black;
}
.nav li:hover {
background-color: #00FFFF;
}
a {
text-decoration: none;
}
<img src="image.jpg" alt="image cannot be displayed" style="width: 100%; height:150px;" />
<div class="nav">
<ul>
<li>Home</li>
<li>Second Page</li>
<li>Third Page</li>
<li>Fourth Page</li>
</ul>
</div>
Either set display: block; on your image or wrap it in a div. The whitespace is essentially a single space showing up because of the img tag styles which default to display: inline.
img {
display: block; /*add this or set container's font-size to 0 */
}
body {
padding: 0;
margin: 0;
font-size: 0; /*add this, otherwise change the img to block*/
}

Text overlying Text and be scalable.

I'm just getting back into Web Development and so I'm working on stretching those muscles again. What I wanted to achieve was a Header on top of my vertical menu with the Initials in the background and the full name in the middle of those initials. I was able to do that with the code in codepen, however it quickly becomes broken when resizing the window. I know that is due in part to the position absolute. Is there another way to achieve this effect and have it be scalable, but stay within the lines of the nav?
http://codepen.io/anon/pen/OPPKmq
<html>
<head>
<title>Scottish Arts</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="body">
<aside>
</aside>
<nav>
<h1 id="navSA">SA<h1>
<h1 id="sa">Socttish Arts</h1>
<ul>
<li><h3></h3></li>
<li>Home</li>
<li>Scottish Arts</li>
<li>Bagpipes</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</body>
</html>
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
padding: 0;
}
h1,h2,h3 {
padding: 0;
margin: 0;
}
#body {
display: flex;
height: 100%;
}
aside {
width: 25px;
height: 100%;
background: url("img/nhtar.gif");
background-repeat: repeat;
border-right: 2px #000 solid;
}
nav {
height: 100%;
width: 15%;
background-color: #7E717A;
border-right: 4px #A2969E solid;
overflow: hidden;
}
nav #navSA {
font-weight: bolder;
text-align: center;
padding: 0;
margin: 0;
font-size: 8em;
color: #A2969E;
}
nav #sa {
padding: 0;
margin: 0;
position: absolute;
top: 60px;
left: 40px;
font-size: 2em;
text-shadow: 2px 2px #7E717A;
}
nav ul {
margin: 0;
padding: 0;
}
nav ul li {
list-style: none;
text-align: right;
}
nav ul li a {
display: block;
padding: 5px;
background-color: #A2969E;
text-decoration: none;
font-size: 1.5em;
font-family: "Verdana";
font-weight: bold;
color: #fff;
border-bottom: 4px #7E717A solid;
}
nav ul li a:hover {
background-color: #372E34;
}
Giving absolute Position to a child that does not have relative parent , will set it's position relating to BODY .
add position:relative; to nav in css , and everything will be OK ;)
http://codepen.io/anon/pen/LEEwOd

float left causes div to gain 'margin'

I have 5 divs in two wrapper divs and when I am assigning the float left attribute to the 5 dips they are gaining a 'top-margin' of 5, as in they have a space between the top of the wrapper div and them. Here is My HTML and CSS
HTML:
<div class="headerMenuWrapper">
<div class="menuOuterWrapper">
<div class="menuInnerWrapper" id="menuWrapper">
<div class="menuItem">Home</div>
<div class="menuItem">About Us</div>
<div class="menuItem">Products</div>
<div class="menuItem">FAQ</div>
<div class="menuItem">Contact Us</div>
</div>
</div>
</div>
CSS:
.menuOuterWrapper{
margin: auto;
margin-top: 0;
width: 95%;
height: 100%;
}
.menuInnerWrapper {
margin: auto;
margin-top: 0;
width: 90%;
height: 100%;
background-color: #327CF1;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
box-shadow: 1px 1px 5px #000000;
}
.menuItem {
height: 100%;
text-align: center;
border-right: 1px solid #051625;
float: left;
}
.headerMenuWrapper {
margin: auto;
width: 95%;
height: 50%;
}
Is this what you are looking for?
You have a lot going on in your markup that shouldn't be.
I simplified everything for you by using:
nav
ul
li
Instead of floats and margins, I used:
display: table
display: table-cell
text-align: center
HTML
<nav id="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Products</li>
<li>FAQ</li>
<li>Contact Us</li>
</ul>
</nav>
CSS
* {
margin: 0;
padding: 0;
border: none;
}
#menu {
margin: 0 auto;
text-align: center;
}
#menu > ul {
display: table;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
box-shadow: 1px 1px 5px #000000;
background: #327CF1;
width: 100%;
}
#menu ul > li {
display: table-cell;
text-align: center;
border-right: 1px solid white;
color: white;
}
#menu > ul > li:last-child {
border: none;
}
use Resetting Browser-Style Defaults for Elements
shorthand for you
{
margin: 0px;
padding: 0px;
}
margin: auto tells to browser automatically calculate margin
example of reset styles here http://meyerweb.com/eric/thoughts/2007/04/12/reset-styles/