CSS 是否可以将 div 底部中心与宽度对齐?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1221088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:54:20  来源:igfitidea点击:

Is it possible to have a div bottom center aligned with the width?

css

提问by Harry

Is it possible to have a div center aligned (ie) always i need to have the div in bottom center with fixed position in a specified width. I know to have it left or right? is there is any way?

是否有可能使 div 中心对齐(即)我总是需要将 div 置于底部中心,并在指定宽度内固定位置。我知道是左还是右?有什么办法吗?

回答by Shiva Srikanth Thummidi

I think this may help you

我想这可能对你有帮助

css:

css:

 #parent{
    position:fixed;
    bottom:0px;
    width:100%;   //width should be 100%
 } 
 #child{
    width:100px; //min width should give to center the div.
    margin:0px auto; //here it will make center 
 }    

HTML

HTML

<div id='parent'>
    <div id='child'>
      centered div
    </div>
</div>

回答by Ivan Zlatanov

.myDiv
{
   position: fixed;
   bottom: 0px;
   width: 200px;
   margin-left: auto;
   margin-right: auto;
}

回答by Tommy Holman

The other answers didnt work for me but here is what did slight modification of Shiva's Answer. Have a parent-child div combo where one grabs the bottom of the page and the other grabs the center like so

其他答案对我不起作用,但这是对 Shiva 的答案稍加修改的内容。有一个父子 div 组合,其中一个抓取页面的底部,另一个抓取页面的中心,就像这样

.bottomOfThePage{
    position:fixed;
    bottom:0px;
    width:100%;
}
.centerOfThePage{
    text-align: center;
    //other text stuff like color
 }

html

html

<div class="bottomOfThePage">
    <div class="centerOfThePage">
        <p>footerStuffHere</p>
    </div>
</div>