怎么让div

时间:2018-04-16 12:41:27

标签: css less

我使用更少的代码来让con-order宽度为80%:

.con-order {

    height: 100%;
    width: 80%;
    overflow: hidden;

html代码如下:

<div class="con-order">
    <div class="alert">
      <Alert type="warning" show-icon closable>
    ...

它像这样,我想要内容移动中心。

enter image description here

我尝试使用text-align: center;,但内容变得奇怪。

就像这样,我不想要这个:

enter image description here

我希望所有移动到中心,而不是所有内容都对齐中心。

2 个答案:

答案 0 :(得分:1)

这对你很好。

.con-order {
    height: 100%;
    width: 80%;
    overflow: hidden;
    margin: 0 auto;

答案 1 :(得分:0)

margin: 0 auto是div的实际居中。

它将使元素水平居中,并且无需设置特定宽度即可工作。

.con-order {
  height: 100%;
  width: 80%;
  overflow: hidden;
  margin: 0 auto;
}