0

I'm using JSSOR image gallery and currently it is stretching portrait images.

I have made a css class where it is no longer stretching:

enter image description here

However I can't get the imace centered in the div.

<div>
    <div class="portrait" u=image style="background-image: url(../img/zachry/1.jpg">&nbsp;</div>
    <div u="thumb"></div>
</div>

Here is the CSS?

.portrait {
position: relative;
width: 850px; 
height: 565px;
background-repeat: no-repeat;
text-align: center;
}

How can I get the image centered?

8
  • 4
    background-position: center; Commented Oct 5, 2015 at 14:59
  • 3
    text-align applies to children of the div. the background is not a child. Commented Oct 5, 2015 at 15:01
  • Pangloss's answer works. Thanks. Commented Oct 5, 2015 at 15:03
  • 2
    @Pangloss Make that a real answer Commented Oct 5, 2015 at 15:04
  • 1
    Why are you not using an <img> tag? Using CSS to display images for a carousel/slideshow seems wrong to me. Commented Oct 5, 2015 at 15:04

3 Answers 3

2

You are using an image as a background from a div.

Almost any element has an attribute called: background-position which can take center as value to center the image given into the middle from the element.

so it could be something like:

.portrait {
    ...
    background-position: center;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Using the following code in your CSS should work:

background-position: center;

1 Comment

You should explain why.
1

I think of two possible ways....

  1. div {background-position: center;}

  2. div {margin-left:auto; margin-right:auto;}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.