简体   繁体   English

使用Bootstrap在小屏幕上将左/右对齐的列移动到中心

[英]Shift left/right aligned columns to the center on a small screen using Bootstrap

I've got a basic header with a logo on the far left and text on the far right (right aligned). 我有一个基本的标头,最左边有一个徽标,最右边是文本(右对齐)。 As the page gets smaller the text overlaps with the logo and doesn't look great. 随着页面变小,文本与徽标重叠,并且看起来不太好。

Fiddle here: 在这里摆弄:

<div class="container">
  <div class="row">
    <div class="col-xs-2">
      <img src="https://unsplash.it/100/100/?random" class="img-circle" alt="placeholder">
    </div>
    <div class="col-xs-10 text-right text-uppercase">
      <h1>Scooby Doo</h1>
      <h3>Where are you</h3>
    </div>
  </div>
</div>

How can I have everything shift to the middle and have my columns be centered on small screens? 如何使所有内容转移到中间并使列集中在小屏幕上? (logo on top, text underneath) Poured over Bootstrap documentation and can't figure it out with the grid system. (顶部徽标,下方文本)倾倒在Bootstrap文档中,并且无法通过网格系统解决。 If Bootstrap doesn't allow for that kind of re-positioning, is there a way with custom css/media queries? 如果Bootstrap不允许这种重新定位,是否可以使用自定义CSS /媒体查询?

You could use a combination of col-sm and col-xs to make sure they do not overlap 您可以结合使用col-smcol-xs来确保它们不重叠

Fiddle 小提琴

<div class="container">
  <div class="row">
    <div class="col-xs-12 col-sm-2">
      <img src="https://unsplash.it/100/100/?random" class="img-circle" alt="placeholder">
    </div>
    <div class="col-xs-12 col-sm-10 text-right text-uppercase">
      <h1>Scooby Doo</h1>
      <h3>Where are you</h3>
    </div>
  </div>
</div>

As for aligning the text, you could use these media queries : https://github.com/twbs/bootstrap/issues/11292 至于对齐文本,您可以使用以下媒体查询: https : //github.com/twbs/bootstrap/issues/11292

Alternatively, if you would duplicate the block, you can achieve what you want with hidden-xs and visible-xs , however duplication is not something I would suggest as it reduces maintainability, but I added it to make the answer complete, as it is an option. 另外,如果你想复制块,就可以达到你想要隐藏-XS可见-XS什么,但复制是不是我建议,因为它减少了维护,但我添加它来作回答完整,因为它一个选项。

See this Fiddle which gives you this code 看到这个小提琴给你这个代码

<div class="container">
  <!-- Hidden only on XS, not centered -->
  <div class="row hidden-xs">
    <div class="col-sm-2">
      <img src="https://unsplash.it/100/100/?random" class="img-circle" alt="placeholder">
    </div>
    <div class="col-sm-10 text-right text-uppercase">
      <h1>Scooby Doo</h1>
      <h3>Where are you</h3>
    </div>
  </div>

  <!-- Only visible on XS, centered-->
  <div class="row visible-xs">
    <div class="col-xs-12 text-center">
      <img src="https://unsplash.it/100/100/?random" class="img-circle" alt="placeholder">
    </div>
    <div class="col-xs-12 text-center text-uppercase">
      <h1>Scooby Doo</h1>
      <h3>Where are you</h3>
    </div>
  </div>
</div>

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

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