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 trial

CSS

What am I doing wrong with this image?

I have a background image in a div that the website's title and a quote sit on. When I drag the browser window to be bigger the image moves too so that it's cropped and way too close. When I drag the window smaller it goes back to normal and acts as it should.

HTML:

HTML

` <header class="main-header">

    <div class="title">
        <h1>The Website Name</h1>
        <h2>We're highly skilled lawn technicians, satisfacation guaranteed or your money back.</h2>
        <ul>
            <a href="#"><li>Get Your Free Quote Here!</li></a>
        </ul>
    </div>
</header>







CSS

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
}

body {
    margin: 0 auto;
    padding: 0;
}

 a {
    color: lightgreen;
    text-decoration: none;
}

/*===========================
    Header Layout
=============================*/

.main-header {

    height: 600px;
    background: #000 url('../imgs/background.jpg') no-repeat center;
    background-size: cover;
    border-bottom: 60px gold  solid;
}


.title h1{
    color: #fff;
    font-size: 2.5em;

}

.title h2{
    color: #fff;
    font-size: 1.5em;
    margin-top: 20px;
}

.title {
    padding: 80px;
    margin-left: 10px;
    margin-right: 10px;
}


.title li {
    display: inline-block;
    background-color: lightgrey;
    padding: 20px;
    border-radius: 12px;
    margin-top: 20px;
    color: blue;
    font-size: 1.8em;
    margin-right: 1em;
} ```
Steven Parker
Steven Parker
231,261 Points

To demonstrate the issue using your image, make a snapshot of your workspace and post the link to it here.

3 Answers

Well this isn’t a treehouse project it’s in sublime text.

Steven Parker
Steven Parker
231,261 Points

I suppose we could substitute something. What is the pixel size of the image?

1280x554

Steven Parker
Steven Parker
231,261 Points

1280 is pretty big .. how big do you have to make the window for this to happen?

If by "way too close" you're talking about the image enlarging, that's how the "cover" setting works. Perhaps you'd prefer another setting:

    background-size: contain;