tags:

views:

773

answers:

2

I have a wide flash movie (to fit in more screen resolution).
I would like to align it to a center of a (for example) 85%-wide div (and the overflowing flash remains hidden).
How could i do that?

edit2:

I'd like to do this with css (and not with javascript):
(I've replaced the flash with text to make the post shorter, the problem is the same)

<html>
<head>
<style>
#div {
    width: 20%;
    overflow: hidden;
    text-align: center;
    background-color: lightblue;
}
#flash {
    width: 400px;
    background-color: blue;
    position: relative;
    top: 0px;
    margin: 0 auto;
}
</style>
<script src="jquery-1.3.2.min.js"></script>
<script>
function center() {
    var flash = parseInt($("#flash").css('width'));
    var div = parseInt($("#div").css('width'));
    if (flash > div) {
     var right = ((flash - div) / 2) + "px";
     $("#flash").css("right", right);
    }
}
$(window).resize(function(){
    center();
});
$(function(){
    center();
});
</script>
</head>
<body>
<div id="div">
<div id="flash">texttexttexttexttext-[CENTER]-texttexttexttexttext</div>
</div>
</body>
</html>
A: 

Seems pretty straightforward, maybe im missing something?

on the div:

div {
    width:85%;
    overflow:hidden;
    text-align:center
}

if that doesn't work can you show us your code

Galen
it doesn't align the flash to the center :(so the flash's center isn't at the div's center
János Harsányi
+1  A: 

You can't align divs by using text-align, because of the fact that divs are block elements. What you can do, if you specify a width for both the container div and the flash div, is set the left and right margins to auto.

#flash {
 width: 50%;
 margin: 0 auto 0 auto;
}
mensch
This method should work in all browsers. Anything that sits inside the #flash div should be centered, unless it's bigger than the div itself.
tahdhaze09
yes, that's the problem. the #flash div is bigger than the #div div.
János Harsányi
In that case I don't think you can pull this off just by using CSS. You'll need a Javascript solution which calculates the sizes of both divs and set the margins based on that data.
mensch
i guess text-align only works on some browser. learned something new!
Galen