简体   繁体   English

带有标题 id 的中心 div

[英]Center div with id of a title

I have a title and a div horizontally, what I am trying to do is to center the div with the corresponding title.我有一个标题和一个水平的 div,我想做的是将 div 与相应的标题居中。

enter image description here在此处输入图像描述

As can be seen in the image, it cannot be centered properly.从图像中可以看出,它无法正确居中。

This is my code:这是我的代码:

<h1 id='<?= str_replace(" ", "", $data->title); ?>'><?= $data->title; ?></h1>
<?= $data->text; ?>

<div class="flexbox">
  <div class="contenido-flex">
    <blockquote>
      <p><?= $data->title; ?></p>
    </blockquote>
    <pre class="is-paddingless" id="a<?= esc($data->id); ?>"><code class="<?= strtolower($data->tip); ?>">
          <?php if ($data->fdc== "JSON") : ?>
          <?= json_decode($data->cod); ?>
          <?php else : ?>
             <?= $data->cod; ?>
          <?php endif; ?>  
          </code></pre>
  </div>
</div>




.flexbox {
    /*  */
    height: 100vh;
}

.contenido-flex {
    margin-top: -700px;
}

You could use align-items: center;你可以使用 align-items: center; Here is an example:这是一个例子:

 .flexbox { background: red; height: 100vh; display: flex; align-items: center; align-content: center; }.contenido-flex { background: green; }
 <h1 id='123'>MyTitle</h1> <div class="flexbox"> <div class="contenido-flex"> <blockquote> <p>Title</p> </blockquote> <pre class="is-paddingless" id="a-11>"><code class="123"> Some Data </code></pre> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM