【问题标题】:Align everything to centre将所有内容对齐到中心
【发布时间】:2018-09-09 18:53:10
【问题描述】:

我不是网页设计师,但我制作了一个网站,但我遇到了一些可能很容易的事情。无论屏幕尺寸如何,我如何将所有内容对齐到中心。在这种情况下,在 Scroll 组件中,我返回一个 Post 组件,该组件返回一个 react-bootstrap Thumbnails,我想在 Scroll 组件中对齐中心(想象将引导卡与中心对齐)。任何帮助将不胜感激。

//发布组件

<Thumbnail className = "post">
<img src="https://robohash.org/abc"></img>
<h3>facemash user</h3>
<div>
    <ButtonGroup>
        <Button bsStyle = 'success' bsSize="small">
            <Glyphicon glyph="thumbs-up" /> Clap
        </Button>
        <Button bsStyle = 'info' bsSize="small">
            <Glyphicon glyph="edit" /> Comment
        </Button>
        <Button bsStyle = 'danger' bsSize="small">
            <Glyphicon glyph="share" /> Share
        </Button>
    </ButtonGroup>
</div>
</Thumbnail>

//滚动组件

<div className = "scroll">
    {props.children}
</div>

//主要组件

    <Scroll> 
        <Post/> // these should centre align
        <Post/>
        <Post/>
    </Scroll>

//所有CSS样式

/*Main*/

.Main{
    min-height: 98%;
    text-align: center;
}

/*Scroll Component*/

.scroll{
    /*background: linear-gradient(to right, yellow, lime);*/
    min-height: 100%;
    font-size: 24px;
    overflow-y:scroll;
    text-align: center;
    border:4px solid  pink;
}

/*Post*/

.post{
    justify-content: center;
    text-align: center;
    min-width: 320px;
    max-width: 400px;
}

【问题讨论】:

  • Code Ninja,你有没有尝试过以下你想要居中的内容?边距:0 自动;

标签: css reactjs react-bootstrap


【解决方案1】:

如果您使用 flex-box,您应该设置父容器一些样式以对齐子中心:

.scroll{
 /*background: linear-gradient(to right, yellow, lime);*/
 min-height: 100%;
 font-size: 24px;
 overflow-y:scroll;
 text-align: center;
 border:4px solid  pink;
 width: 100%;
 display: flex;
 flex-direction: column;
 justify-content: center;
 align-items: center;
 align-content: center;
 text-align: center;
} 

【讨论】:

  • 谢谢老兄,你救了我。工作得很好。
  • @Code Ninja 欢迎您。)
猜你喜欢
  • 2015-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-28
相关资源
最近更新 更多