user4585315
user4585315

Reputation:

CSS image positioning inside <div>

I have been making a website and I want an opening image to be found on my screen. The problem is that I have the picture I want to use but it is to big for the space I want it to fit in. This could be solved 2 ways: I could scale the image to fit in the Div or I could position the image inside the div to show the essential parts of my picture. Ideally I would like the second option but I am ok with the first. I believe that I have done sufficient research on this question and this question is not like these:First, Second. I have also done my own experiments on this problem but using the position property and clear divs these have not worked to my satisfaction.

Here is what i believe to be the essential code for this question:

HTML:

<div class="jumbotron">
    <h1> New IQ Test </h1>
    <p>Take our quiz</p>
</div>

CSS:

.jumbotron {
    /*padding-left: 50px;
    padding-right: 10px;*/
    height: 500px;
    display:block;
    background-image: url(http://bit.ly/1IMUMR0);
    width: 100%;
    /*padding-top: 100px;
    position: absolute;
    bottom: -30px;*/
    text-align: center;
    color:white;
}

.jumbotron h1 {
    padding-top: 150px;
    font-weight: normal;
    opacity: 100;
    text-shadow: 0 0 10px black;
    font-family: Helvetica;
}

The image I am using is not owned by me. I realize this is illegal. I am NOT going to put this web page out for general use so it us ok if I use this image. All your help is greatly appreciated.

Upvotes: 3

Views: 1029

Answers (4)

jberk
jberk

Reputation: 92

.jumbotron {
/*padding-left: 50px;
padding-right: 10px;*/
background-size: 100% 100%;
/*background-size: cover;*/
height: 500px;
display:block;
background-image: url(http://bit.ly/1IMUMR0);
width: 100%;
/*padding-top: 100px;
position: absolute;
bottom: -30px;*/
text-align: center;
color:white;

Upvotes: 2

John
John

Reputation: 312

I would scale it down with CSS myself, but if you're fine with just a portion of the image showing, then why don't you crop it? You'll get the affect you're looking for, and your asset size will decrease.

Upvotes: 0

Daniel Williams
Daniel Williams

Reputation: 2317

background-size: cover;

Will just show part of the image as you resize the browser.

background-size: 100% 100%;

Will auto-size the image on browser resize so the full image is always visible.

Upvotes: 0

posit labs
posit labs

Reputation: 9431

Try background-size: cover; or background-size: contain; or maybe some other value.

https://developer.mozilla.org/en-US/docs/Web/CSS/background-size

Upvotes: 2

Related Questions