Align a div to center

后端 未结 14 2062
别跟我提以往
别跟我提以往 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条回答
  • 2020-12-02 13:45

    Try this, it helped me: wrap the div in tags, the problem is that it will center the content of the div also (if not coded otherwise). Hope that helps :)

    0 讨论(0)
  • 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

    <div id='outer-container'>
    <div id='inner-container'></div>
    <div id='captions'></div>
    </div>
    

    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");
    
    0 讨论(0)
提交回复
热议问题