jquery - What am I doing wrong trying to center this div? (its a little off) -
jquery - What am I doing wrong trying to center this div? (its a little off) -
i trying center div horizontally marker can see here http://jsfiddle.net/rkejg/8/, it's little more right should be.
this code
$("#infobox").css({ marginleft: (parseint($("#content").width(), 10) / 2) - (parseint($("#infobox").width(), 10) / 2) + 'px' });
then realized should add together halves of content
, infobox
, set them in negative margin, made whole lot worse:
$("#infobox").css({ marginleft: '-' + (parseint($("#content").width(), 10) / 2) + (parseint($("#infobox").width(), 10) / 2) + 'px' });
result: margin-left: -16110.5px
what doing wrong here? thanks!
i cleaned html , set marker
class position: relative
. seems have resolved issue. out padding, , removed additional margin in marker class. think did couple other changes in css, you'll have compare original. there quite bit clean up.
fiddle
update: go back, position relative parent of absolutely positioned element practice, not required , not fixed this. padding in infobox class , static margin in content class, html not beingness nested fixed issue.
[update][update]
based on have, think need wrapper css width:100%; padding-top:45%; position:relative
, set kid divs margin: 0 auto
shown in fiddle http://jsfiddle.net/bfelda/rkejg/22/ can set top padding container whatever want of course. may missing point. want text centered above marker regardless of marker located?
jquery
Comments
Post a Comment