首页 > 解决方案 > How to make div into center using html or css

问题描述

I have divs which is displaying at the left side of the page i want to display them on center of the page I have also attached the screen shot of my divs:

     $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'),
    ],
  ];

and my 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;
 }

I have just pasted one div css, instead of making div into center it displaying the text into center which is in div. How can I make my divs into center?

Please also find my screen.

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%;
    }

and html:

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

标签: htmlcssanimationlayout

解决方案


如果您在 div.page_sum和 div中添加类 .summary-center.page_summary它应该可以工作。

.summary-center {
  margin: auto;
  width: 50%;
}

推荐阅读