Как сделать div в центр, используя html или css - PullRequest
0 голосов
/ 06 марта 2020

У меня есть div, которые отображаются в левой части страницы. Я хочу, чтобы они отображались в центре страницы. Я также прикрепил снимок экрана с моим div:

     $array = [
    'Summary' => [
      'data' => '<div align="center"style="display: inline-block;width: 10%;" class="page_sum"><h1>Scan Summary:</h1></div>

                <div class="page_summary"><br/>
                    <div><h3 style="display: inline-block;width: 10%;" class="total_found">Total Files Found: '.$totalFind.'</h3></div>
                    <div><h3 style="display: inline-block;width: 10%;" class="total_dir">Total Directories: '.$totalIsDir.'</h3><br/></div>
                    <div><h3 style="display: inline-block;width: 10%;" class="planned_sync">Planned Sync Files: '.$totalShouldFind.'</h3></div>
                    <div><h3 style="display: inline-block;width: 10%;" class="actual_sync">Actual Synced: '.$totalResolved.'</h3><br/></div/>
                    <div><h3 style="display: inline-block;width: 10%;"class="missing_sync">Missing Synced Files: '.$forOfor.'</h3><div/>',
      'colspan' => 5, 'class' => array('foo', 'bar'),
    ],
  ];

и мой css:

 .page_sum{
 width: 100px;
 height: 50px;
  display: inline-block;
 }

 .page_sum { /* Using drop shadow, should appear identical to box shadow */
  -webkit-box-shadow: 0px 0px 11px 0px rgba(0,0,0,0.75);
  -moz-box-shadow: 0px 0px 11px 0px rgba(0,0,0,0.75);
  box-shadow: 0px 0px 11px 0px rgba(0,0,0,0.75);
  background: #cccccc;
 }

Я только что вставил один div css, вместо того, чтобы сделать div в центр, он отображает текст в центр, который находится в div. Как я могу сделать мои деления в центре?

Пожалуйста, также найдите мой экран.

enter image description here

CSS:

    .page_sum{
    width: 100px;
    height: 50px;
    display: inline-block;

    }

 .page_sum { /* Using drop shadow, should appear identical to box shadow */
  -webkit-box-shadow: 0px 0px 11px 0px rgba(0,0,0,0.75);
  -moz-box-shadow: 0px 0px 11px 0px rgba(0,0,0,0.75);
     box-shadow: 0px 0px 11px 0px rgba(0,0,0,0.75);
     background: #cccccc;
   }
  .summary-center {
   margin: auto;
   width: 50%;
    }

и html:

    '<div class="summary-center" style="display: inline-block;width: 10%;" class="page_sum"><h1>Scan Summary:</h1></div>

Ответы [ 3 ]

2 голосов
/ 06 марта 2020

если вы добавите класс .summary-center в div .page_sum и в div .page_summary, он должен работать.

.summary-center {
  margin: auto;
  width: 50%;
}
1 голос
/ 06 марта 2020

Попробуйте:

<div class="page_summary summary-center">
  <h1>Scan Summary:</h1>
  <br/>
  <div>
    <h3 style="display: inline-block; width: 10%;" class="total_found page_sum">Total Files Found: XX</h3>
  </div>
  <div>
    <h3 style="display: inline-block; width: 10%;" class="total_dir page_sum">Total Directories: XX</h3>
    <br/>
  </div>
  <div>
    <h3 style="display: inline-block; width: 10%;" class="planned_sync page_sum">Planned Sync Files: XX</h3>
  </div>
  <div>
    <h3 style="display: inline-block; width: 10%;" class="actual_sync page_sum">Actual Synced: XX</h3>
    <br/>
  </div>
  <div>
    <h3 style="display: inline-block; width: 10%;"class="missing_sync page_sum">Missing Synced Files: XX</h3>
  </div>
</div>

<style>
  .page_sum {
    /* Using drop shadow, should appear identical to box shadow */
    -webkit-box-shadow: 0px 0px 11px 0px rgba(0,0,0,0.75);
    -moz-box-shadow: 0px 0px 11px 0px rgba(0,0,0,0.75);
    box-shadow: 0px 0px 11px 0px rgba(0,0,0,0.75);
    background: #cccccc;
  } 

  .summary-center {
    margin: auto;
    width: 50%;
    text-align: center;
  }
</style>

Это выглядит следующим образом:

center

1 голос
/ 06 марта 2020
.center {
    display: flex;
    justify-content: center;
    align-items: center;
}
...