css - Bootstrap 在移动设备上左对齐右文本类

标签 css bootstrap-4

在我的表单标签上使用 text-right 类,当响应时,我希望标签左对齐,因此它是左上而不是右上,但是 的更改text-align:left 好像没有生效。

@media (max-width: 767px) {
  .form-group > label.text-right {
    text-align: left;
    color: red;
  }
}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">

<div class="form-group row">
  <label class="col-sm-2 col-form-label text-right">Label</label>
  <div class="col-sm-10">
    <input type="text" class="form-control">
  </div>
</div>

最佳答案

Bootstrap 的文本对齐类是响应式。您不需要任何额外的 CSS
使用 text-sm-right text-left...

<div class="form-group row">
        <label class="col-sm-2 col-form-label text-sm-right text-left">Label</label>
        <div class="col-sm-10">
            <input type="text" class="form-control">
        </div>
</div>

演示:https://www.codeply.com/go/djMd492DHA

关于css - Bootstrap 在移动设备上左对齐右文本类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49354448/

相关文章:

html - Bootstrap 4 容器与前一个容器重叠

html - Bootstrap 排列表单元素

html - 我如何在 bs4 的轮播中集中和缩小两个图像之间的差距?

html - 禁用 :focus and a:active color?

css - chrome 缓存 bootstrap css 吗?

html - 更改字体样式会更改 UI - 标准方法

javascript - 有没有办法在打开页面之前更改页面的元素

twitter-bootstrap - 使用 Bootstrap 4 和 Flexbox 定位导航栏按钮不起作用?

javascript - onMouseOver 重复改变图片的背景颜色

javascript - HTML 和 CSS 动画失败