简体   繁体   English

Bootstrap 4 居中(水平)图像 + div 内的文本

[英]Bootstrap 4 center (horizontally) image + text inside div

Bootstrap 4:引导程序 4:
How to horizontally center a div that contains an image and text to the right of the image?如何将包含图像和文本的 div 水平居中放置在图像的右侧?

                                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                 |     | Heading                     |
                                 + IMG +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                                 |     | Lead                        |
                                 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

I tried making three columns inside a row,我试着在一行内制作三列,

<div class="row">
    <div class="col"></div>
    <div class="col-auto">
        <img src="..." width="..." height="..." />
        <h1 class="display-5 m-0">...</h1>
        <p class="lead">...</p>
    </div>
    <div class="col"></div>
</div>

but the problem is the heading is too long and wraps around to the next line.但问题是标题太长,绕到下一行。 If I make the middle column larger, it is no longer centered.如果我使中间列更大,它不再居中。 I need it to be centered regardless of text length.无论文本长度如何,我都需要将其居中。

 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/> <div class="row justify-content-center"> <div class="col-3"> <img src="https://pixlr.com/photo/image-design-11-1-pw.jpg" style="width: 100%;height: 100%;" /> </div> <div class="col-9"> <h5>Hello World</h5> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed hendrerit adipiscing blandit. Aliquam placerat, velit a fermentum fermentum, mi felis vehicula justo, a dapibus quam augue non massa.</p> </div> </div>

Try this code试试这个代码

  <div class="text-center">
      <div class="row justify-content-md-center">
        <div class="col-md-auto">
          <img src="https://placehold.it/100x100">
        </div>
        <div class="col-md-auto">
            <h1 class="display-5 m-0">...</h1>
            <p class="lead">...</p>
        </div>
      </div>
    </div>

Working demo here: https://www.bootply.com/UHz1ACh2CI这里的工作演示: https : //www.bootply.com/UHz1ACh2CI

I figured it out.我想到了。

<div class="row">
  <div class="col-12 d-flex flex-row justify-content-center">
    <img src="..." width="..." height="..." />
    <div>
      <h1 class="display-5 m-0">...</h1>
      <p class="lead">...</p>
    </div>
  </div>
</div>

对齐内部的图像和文本<div>水平和垂直</div><div id="text_translate"><p>我想水平和垂直对齐 div 内的图像和文本。 我的代码:</p><pre> &lt;div style="white-space:nowrap" (click)="sidenav.toggle()"&gt; &lt;img alt='image' style="margin-top: 1vw;display: inline;" width="25" height="35" src="../assets/menu-white-18dp.svg"&gt; &lt;span style="display:inline; white-space:nowrap;" &gt; KRON&lt;/span&gt; &lt;/div&gt;</pre><p> 目前它看起来像这样: <a href="https://i.stack.imgur.com/VP0Ld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VP0Ld.png" alt="在此处输入图像描述"></a></p><p> 我希望“KRON”与图像对齐。 我做错了什么?</p></div> - Align image and text inside <div> horizontally and vertically

暂无
暂无

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

相关问题 在引导程序内水平居中div元素? (文本中心不起作用) - Center horizontally div elements inside bootstrap? (text-center not working) 在div内部水平居中 - Center image inside div horizontally 如何在div内水平和垂直居中放置图像和文本? - How can I center an image and text horizontally and vertically inside a div? 如何垂直和水平居中引导 div 图像 - how to center a bootstrap div image vertically and horizontally 在div内水平和垂直居中对齐图像 - Center align image inside div horizontally and vertically 将div中的可点击图像水平居中 - center horizontally a clickable image inside a div 使用HTML div中的引导程序将文本水平和垂直居中 - Center text horizontally and vertically using bootstrap in HTML div 对齐内部的图像和文本<div>水平和垂直</div><div id="text_translate"><p>我想水平和垂直对齐 div 内的图像和文本。 我的代码:</p><pre> &lt;div style="white-space:nowrap" (click)="sidenav.toggle()"&gt; &lt;img alt='image' style="margin-top: 1vw;display: inline;" width="25" height="35" src="../assets/menu-white-18dp.svg"&gt; &lt;span style="display:inline; white-space:nowrap;" &gt; KRON&lt;/span&gt; &lt;/div&gt;</pre><p> 目前它看起来像这样: <a href="https://i.stack.imgur.com/VP0Ld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VP0Ld.png" alt="在此处输入图像描述"></a></p><p> 我希望“KRON”与图像对齐。 我做错了什么?</p></div> - Align image and text inside <div> horizontally and vertically Bootstrap Center 水平对齐一个 div - Bootstrap Center align a div horizontally 如何在bootstrap4列中垂直和水平居中此文本? - How to vertically and horizontally center this text inside bootstrap4 columns?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM