Freaking AWESOME, exactly what I wanted...
Thanks a lot.
Main Topics
Browse All TopicsI have a DIV, and need to have an image inside of it. The image is larger than the
DIV and I need it to dynamically center itself inside the DIV but I want the edges of
the DIV to overlap the image, kind of like a clipping of the image.
+-------------------------
+--|----------------------
| | | |
| | | |
| | | |
+--|----------------------
+-------------------------
Thee DIV is fluid and I only want a portion of the imag to show when the DIV is reduced
in width and the image to stay centered.
How/Can this be done?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
It's easy to do with a background image...
But remember you should not use background for images that are content.
HTML = content
CSS = presentation
Also, if you use background, you'll need to know the dimension of your image to be able to correctly set the padding or the height of you container.
Here is a solution that uses a real HTML image (should work in all modern browsers):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html
<html>
<head>
<title>test</title>
<style type="text/css">
body {
background: #ddd;
color: #000;
}
div {
width: 40%;
margin: 3em auto;
border: 5px solid red;
overflow: hidden;
position: relative;
z-index: 10;
}
div p {
margin: 0;
margin-left: 50%;
display: table;
display: inline-block;
}
p img {
position: relative;
left: -50%;
}
</style>
</head>
<body>
<div>
<p>
<img src="http://www.google.com
</p>
</div>
<div>
<p>
<img src="http://lug.oregonstat
</p>
</div>
</body>
</html>
I really need it for this:
http://www.austinmetrobase
http://www.austinmetrobase
Can you make it work for that? The original solution, for some reason, no longer works.
> I'd suggest asking for the Q to be reopened, so GrandSchtroumpf can get the points!
Not really...
I assume this question is about the header image.
He chose to use a background-image which is the correct way to go in this case (the header image is presentation, not content).
The only problem is that he still has the image in the html... so the image hides the background image.
It's not the CSS that needs to be fixed, it's like GrandSchtroumpf said, the gif is linked into the header as a real image too, and hides the background image. Just delete the line in the middle here:
<div id="header">
<div align="center"><img id="header" src="../images/amblhead_1_
</div>
So delete
<div align="center"><img id="header" src="../images/amblhead_1_
and just keep
<div id="header"></div>
Business Accounts
Answer for Membership
by: TNamePosted on 2007-01-05 at 14:58:27ID: 18255558
Hi, you could try something like this (adjust dimensions to fit your needs). The image as a background-image of the div, the div with overflow:hidden.
jpg); t; ;
<html>
<head>
<style type="text/css">
#imgDiv {
background-image:url(img1.
background-repeat:no-repea
background-position:center
overflow:hidden;
width:20%; /*just an example*/
height:10%; /*just an example*/
border: 1px solid #bbb;
}
</style>
</head>
<body>
<div id="imgDiv"> </div>
</body>
</html>