使用css将div保持在屏幕的中间底部

Tan*_*ani 1 html css

我总是试图在屏幕底部保留一个div.并且由于div宽度小于屏幕所以它应该位于屏幕的中间.第一件事是工作,但如果总是左边漂浮.

代码是

    <div id="catfish" style="position:fixed; bottom:0;  z-index:5000; width: 468px; margin: 0px auto;">
        <div style="position:absolute;  margin-bottom:0px; z-index:15;">
            <a href="Javascript:void(0);" onclick="document.getElementById('catfish').style.display='none'"><img src="http://secretdiarybd.com/wp-content/uploads/2015/05/close.gif.png" alt="close" height="20"></img></a>
        </div>
        <div>
           Some elemnt here
        </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

jsfiddle的例子 请帮帮我.

Fel*_*ber 5

您必须添加leftright与值0.您的DIV如果你也想在中间的文本必须添加text-align: center;

  <div id="catfish" style="position:fixed; bottom:0; left:0; right:0; text-align:center;  z-index:5000; width: 468px; margin: 0px auto;">
        <div style="position:absolute;  margin-bottom:0px; z-index:15;">
            <a href="Javascript:void(0);" onclick="document.getElementById('catfish').style.display='none'"><img src="http://secretdiarybd.com/wp-content/uploads/2015/05/close.gif.png" alt="close" height="20"></img></a>
        </div>
        <div>
           Some elemnt here
    </div
    </div>
Run Code Online (Sandbox Code Playgroud)

希望有所帮助!