/    Sign up×
Community /Pin to ProfileBookmark

Centering a floating div

This is not a fixed width layout. I have one or two CSS techniques applied to these images– a shadow for all of them which requires floating, and there is also a caption for some of them.

[url]http://matt.mw/gmsaa/articles/passing_in_review3.html[/url]

I need to be able to center the last picture “with” the shadow in this layout, but am wondering how to do this. I managed to do it with two images (as you can see at the very top) using 2 divs within another div, but one image is really killing me with floating items.

[CODE].img-shadow {
float:left;
background: url(http://matt.mw/gmsaa/img_shadow/shadowAlpha.png) no-repeat bottom right;
margin: 10px;
}
.img-shadow img {
display: block;
background-color: #fafafa;
border: 1px solid #a9a9a9;
margin: -6px 6px 6px -6px;
padding: 4px;
}

<div class=”img-shadow”><img src=”http://matt.mw/gmsaa/articles/passing_in_review/passing_in_review_images-012.jpg” /></div>[/CODE]

[B]
So without taking away this float & shadow, how do I place this image in the exact center when this layout is not fixed? [/B]
Obviously text-align:center has no effect on floating items. Seems different positioning methods like “absolute” ruin my shadow.

Please help me out! Thanks.

to post a comment
CSS

2 Comments(s)

Copy linkTweet thisAlerts:
@_yo_wasup_authorJun 21.2011 — I guess I can't edit my post.....

Link update: http://matt.mw/passing_in_review3.html
Copy linkTweet thisAlerts:
@JayhawkJun 24.2011 — The following inclodes a bunch of color styling as well as the margin styling for centering, but itshould illustrate the point. The z-index puts the shadowed div behind the other one.
[code=html].fshadow { /* properties on form shadow */
width: 400px;
height: 520px;
position: absolute;
left: 50%;
margin-left: -190px;
top: 50px;
background-color: #cdcdcd;
}
.fbox { /* properties on form container */
width: 400px;
height: 520px;
position: absolute;
left: 50%;
margin-left: -200px;
top: 40px;
border-top: 2px solid #910000;
border-left: 2px solid #910000;
border-right: 2px solid #6E0000;
border-bottom: 2px solid #6E0000;
color: #000000;
background-color: #FFFFFF;
font-weight: bold;
text-align: center;
}

<div class='cbox black p34' style='width:1270px; margin:30px 0; text-align:center'>

<div class='fshadow' style='width:900px; height:145px; margin-left:-440px; top:150px; z-index:120;'>
</div>
<div class='fbox' style='width:900px; height:145px; margin-left:-450px; top:140px; z-index:125;'>
</div>

</div>

[/code]
×

Success!

Help @_yo_wasup_ spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...