Issue
I'm relatively new to HTML and CSS. I'm working on a portfolio website for class and am not using Bootstrap.
I can't seem to get rid of this small weird space on the right side of my page. I want my navbar to span the entire length of my page! The same thing is happening with my header image even when I change the margins, padding, etc. I'm out of ideas!
Any help/ideas would be appreciated. Thank you so much!
/* GENERAL */
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;700&family=Patrick+Hand&display=swap');
* {
box-sizing: border-box;
}
body {
background-color:#ddd;
background-size: cover;
font-family: 'Manrope', sans-serif;
margin: 0;
padding: 5px;
}
h1 {
background-color: rgba(229, 152, 155, .7);
font-family: 'Patrick Hand', cursive;
font-size: 80px;
margin: -5px;
text-align: center;
}
h2 {
font-family: 'Patrick Hand', cursive;
}
h3 {
font-family: 'Manrope', sans-serif;
text-align: center;
}
/* NAV/LINKS */
nav {
background-color: white;
height: 70px;
margin-top: -5px;
margin-right: -5px;
margin-left:-5px;
padding: 0;
width: 100%;
}
nav h2 {
color: black;
float: left;
font-size: 30px;
line-height: 55px;
padding: 0px 20px;
}
nav ul {
float:right;
padding: 3px 20px 20px 3px;
}
nav ul li {
float: left;
list-style: none;
position: relative;
}
nav ul li a {
display: block;
color: #AC6BA7;
font-size: 14px;
padding: 22px 14px;
text-decoration: none;
}
nav ul li ul {
background-color: white;
border-radius: 0px 0px 4px 4px;
display: none;
padding: 3px;
position: absolute;
}
nav ul li:hover ul {
display: block;
}
nav ul li ul li {
border-radius: 4px;
}
nav ul li ul li a {
padding: 8px 12px;
}
nav ul li ul li a:hover {
background-color: #E5989B;
}
/* PAGE IMAGES */
.header-img {
margin: -5px;
width: 100%;
}
/* PAGES */
/* MEDIA QUERIES */
/* FOOTER */
<!------ SKELETON CODE (SAME ON ALL PAGES) ------>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/main.css">
<title>Jen Nino: Class Website</title>
</head>
<body>
<!------ NAV BAR (SAME ON ALL PAGES) ------>
<nav>
<h2>JEN NINO</h2>
<ul>
<li><a href="#">NAV ≡</a>
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="webdesign.html">WORK</a></li>
<li><a href="contact.html">CONTACT</a></li>
</ul>
</li>
</ul>
</nav>
<!------ HEADER (SAME ON ALL PAGES, DIFF IMAGE) ------>
<header>
<img class="header-img" src ="images/sanfrancisco.png" alt="My husband and I in front of San Francisco Bay. There is a skyline in the background.">
</header>
<!------ MAIN/ARTICLE/SECTION (DIFFERENT ON PAGES) ------>
<main>
<h1>HOME</h1>
<article class="about-me-parent">
<section class="about-me-child">
<p> Text</p>
</section>
<section class="about-me-child">
<p>Text </p>
</section>
</article>
</main>
<!------ FOOTER (SAME ON ALL PAGES) ------>
<footer>
Here
</footer>
</body>
</html>
Solution
I think i may have some helpful comments.
We usually use positive margins. Like
margin-top: 5px
will give you a margin of 5px on the top.nav, h1, div... are block elements. That means that their width is naturally all that is available and a
width: 100%
is usually not necessary.If you do use
width: 100%
, the element will be the width of the parent element. So if you then apply margins, the element will be pushed to one side, but the width o the element will still be 100% of the parent. To avoid this, you can usewidth: calc(100% - 2*5px)
for example. But in your case, i don't recommend setting any width at all.
So... less is more. The development tools in firefox or chrome can be a great help to understand what is going on if your css isn't exactly doing what you expected.
Answered By - Sophia Koulen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.