/    Sign up×
Community /Pin to ProfileBookmark

HTML & CSS margin/padding issues

Hello!

I need to add a navigation bar to my website, but there seems to be an issue either with the padding or the margin, because there is always a space at the top. When I change the position to “position: fixed;” in my CSS an unwanted margin appears at the left. I have tried to fix this using several approaches, but I haven’t managed to get my head around the issue.

I have already tried to fix it using the traditional code:
`body {
margin: 0;
padding: 0;
}`

Still doesn’t work.
All of the elements have a default margin or padding, and I need at least my nav bar and footer to not have this spacing.

Here’s the full HTML for now:

`<!DOCTYPE HTML>
<html>

<head>

<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width”>
<title>Sarah Smith</title>
<link rel=”stylesheet” type=”text/css” href=”assets/css/main.css” media=”screen” />
<link href=”//fonts.googleapis.com/css?family=Montserrat” rel=”stylesheet”>
<link href=”//fonts.googleapis.com/css?family=Raleway” rel=”stylesheet”>
<script src=”assets/js/script.js”></script>
<script src=”https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js” integrity=”sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM” crossorigin=”anonymous”></script>

</head>

<body>

<header>
<div class=”navbar”>
<a class=”logo” href=”index.html”>Sarah Smith
<span id=”flogo”>Luthier</span></a>
<div><a href=”#story”>Story</a></div>
<div><a href=”#pricing”>Pricing</a></div>
<div><a href=”#contact”>Contact</a></div>
</div>

</header>

<div id=”PageContainer”>
<main role=”main” id=”sitemain”>

<div class=”welcome”>
<h1>LUTHIER IN BCN</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>

<div class=”profile”>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum</p>
<img class=”prtgnst” src=”https://www.spelldesigns.com/wp-content/uploads/By-Tezza-Spell-Edit-Spell-The-Gypsy-Collective-30.jpg”>

</div>
<div class=”info”>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum</p>
<img class=”prtgnst” src=”https://www.spelldesigns.com/wp-content/uploads/By-Tezza-Spell-Edit-Spell-The-Gypsy-Collective-30.jpg”>
</div>
<div class=”subscribe”>

</div>

</main>

</div>

<!–===== FOOTER PART =====–>

<footer class=”footer-area”>
<div class=”footer-widget”>
<div class=”container”>
<div class=”row justify-content”>
<div class=”footer-content text-center”>
<a href=””>
<img src=”” alt=”Logo”>
</a>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor inci- didunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exe- rcitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<ul>
<li><a href=”#”><i class=”fb-logo”></i></a></li>
<li><a href=”#”><i class=”tw-logo”></i></a></li>
<li><a href=”#”><i class=”ig-logo”></i></a></li>
</ul>
</div> <!– footer content –>
</div> <!– row –>
</div> <!– container –>
</div> <!– footer widget –>
<div class=”footer-copyright”>
<div class=”container”>
<div class=”row”>
<div class=”col-lg-12″>
<div class=”copyright-text”>
<p>Copyright © 2019. Crafted by <a href=”https://google.com” rel=”nofollow”>Gabriela</a></p>
</div> <!– copyright text –>
</div>
</div> <!– row –>
</div> <!– container –>
</div>
</footer>

<!–===== BOOTSTRAP JS & JQUERY CDN =====–>

<script src=”https://code.jquery.com/jquery-3.3.1.slim.min.js” integrity=”sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo” crossorigin=”anonymous”></script>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js” integrity=”sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1″ crossorigin=”anonymous”></script>
<script src=”https://code.jquery.com/jquery-3.3.1.slim.min.js” integrity=”sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo” crossorigin=”anonymous”></script>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js” integrity=”sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1″ crossorigin=”anonymous”></script>

</body>
</html> `

Any ideas on how to fix this? How can I remove the default positioning of the website? And would that be efficient?

Thank you.

to post a comment
CSSHTML

2 Comments(s)

Copy linkTweet thisAlerts:
@siddhi_patelSep 10.2019 — Hi, try like this:

``<i>
</i>&lt;ul&gt;
&lt;li&gt;&lt;a href="flogo.asp"&gt;Luthier&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="story.asp"&gt;Story&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="pricing.asp"&gt;Pricing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="contact.asp"&gt;Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;<i>
</i>
`</CODE>

Css for above code:
<CODE>
`<i>
</i>ul {
list-style-type: none;
margin: 0;
padding: 0;
}<i>
</i>
``
Copy linkTweet thisAlerts:
@codyhillSep 10.2019 — @powerbank#1607770 Instead of

body {<br/>
margin: 0;<br/>
padding: 0;<br/>
}


use


*{<br/>
margin: 0;<br/>
padding: 0;


use that every time you start a new prject.

This *(the start) selects all the elements in the file. Also, add box-sizing: border-box;. It would be helpfull

<i>
</i>* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
×

Success!

Help @powerbank spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...