Align a div to center

后端 未结 14 2070
别跟我提以往
别跟我提以往 2020-12-02 13:20

I want to float a div to center. Is it possible? text-align: center is not working in IE.

14条回答
  •  -上瘾入骨i
    2020-12-02 13:47

    One of my websites involves a div whose size is variable and you won't know it ahead of time. it is an outer div with 2 nested divs, the outer div is the same width as the first nested div, which is the content, and the second nested div right below the content is the caption, which must be centered. Because the width is not known, I use jQuery to adjust accordingly.

    so my html is this

    and then I center the captions in jQuery like this

    captionWidth=$("#captions").css("width");
    outerWidth=$("#outer-container").css("width");
    marginIndent=(outerWidth-captionWidth)/2;
    $("#captions").css("margin","0px "+marginIndent+"px");
    

提交回复
热议问题