Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialstephanie harrison roberts
1,713 PointsMargins around a background image
Hi All, Anyone tell me where Im going wrong? dont want any white margins around my image.....hat do i need to add?
thanks
<!DOCTYPE html>
<html>
<title>Obi & El Media Agency</title>
<link rel="stylesheet" href="New.css">
<body>
<div class="main_container">
<!-- <h1 class="main_title">Obi & El</h1>-->
</div>
</body>
</html>
```CSS
html{
height: 100%;
height: 100vh;
}
.main_container {
background: url(Brackets_Images/typewriter.jpg)no-repeat;
background-size: cover;
/* border: 4px solid red;*/
height: 100vh;
max-width: 50%;
margin: 0;
background-position: 50% 50%;
}
3 Answers
Steven Parker
231,261 PointsYour container with the background is inside the body, and the body has margins by default. You can explicitly remove them in the CSS:
body { margin: 0; }
Also, the HTML code seems to be missing the starting and ending head
tags.
Moinul Haq
Front End Web Development Techdegree Student 11,178 PointsYou should reset your default browser margin to 0.
*{ margin:0; }
stephanie harrison roberts
1,713 PointsFab, thanks for letting me know! Steph
mryoung
4,156 PointsI like to universally remove margins and padding to not have as many issues with positioning.
- { Margin: 0 auto; Padding: 0; Box-sizing: border-box; }
But doing so to the body instead should help too I believe, if you’d rather not use the universal approach.
Steven Parker
231,261 PointsUniversally removing margins may have unintended side-effects, such as causing all paragraphs to run together.
stephanie harrison roberts
1,713 Pointsstephanie harrison roberts
1,713 PointsThank you so much! Steph