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 trialAlex Chamberlain
5,706 PointsBackground image not positioned correctly
Hi everyone,
Am trying to position my svg image to the corner of the screen. I have tried to add the background-position: top left; property but it didn't work. I have included my code and a picture of how it looks in my browser. I am still trying to figure out what is the problem.
.div1{
background-image: url(../images/back.svg);
background-repeat: no-repeat;
background-size: 100%;
background-position: top left;
height: 100vh;
}
<div class='container'>
<div class='div1'>
p
</div>
<div class='div2'>
p
</div>
</div>
Thanks!
2 Answers
HIDAYATULLAH ARGHANDABI
21,058 PointsTry the background-size: cover;
property
Alex Chamberlain
5,706 PointsI just tried it, it didn't work it showed the same result
Mister Moody
48,333 PointsThe background-size: cover;
property is gold for background images. Scary that that didn't work for you; possibly an issue with inheritance/specificity(?). Perhaps you can use the top: value;
and left: value;
property for positioning the image, where the value of top: xx;
is 0
... tinker with the left value and use vw
unit for responsiveness.
Sean T. Unwin
28,690 PointsSean T. Unwin
28,690 PointsIt seems to me to be a sizing issue, but without knowing the size of the SVG as well as the size or proportion of the screen you want the SVG to display it's difficult to give a definitive answer.
Have you tried removing the
background-size
andheight
properties or adjusting those values?