html - 试图将一堆 col-md-10 div 居中但不居中

标签 html css vue.js bootstrap-4

我正在尝试将容器中的一堆文章居中。我目前在容器上使用辅助类 center-block 和 css float: none; 但它没有居中。我试图将 center-block 放在实际的 col-md-10 文章容器中,但这导致了类似三 Angular 形的效果。

我如何使文章 div 居中以及我做错了什么?

<template>
  <div class="articles">
    <h1 v-text="title"></h1>
    <div v-if="Object.keys(articles).length !== 0" class="center-block">
      <div v-for="article in articles" class="col-md-10 article-border">
        <h1 v-text="article.title"></h1>
        <img :src="article.image" class="pull-left img-responsive margin10 thumb img-thumbnail">
        <p v-text="article.content">
        </p>
        <a class="btn btn-success pull-right marginBottom10" :href="article.url">Continue Reading..</a>
      </div>
    </div>
    <div v-else>No Articles Found!</div>
  </div>
</template>

...

.center-block {
    float: none;
}

当前输出:

enter image description here

期望的输出:

enter image description here

JSFiddle:https://jsfiddle.net/rx9ohzg3/1/

最佳答案

要使用 Bootstrap 提供的方法,请使用相应的 offset 类:将类 offset-md-1 添加到具有 col 的元素-md-10 将其向右移动一列,从而使其居中。 (12 列总宽度减去 10,对于您的 DIV = 2,除以 2 左右 = 1 列,左侧应保持为空)

你可以在这个代码笔中看到它,它包含与你的 fiddle 相同的代码,(几乎)只添加了那个偏移类:

https://codepen.io/anon/pen/jaKege

注意:我还用 float-right 类替换按钮的 pull-right 类,因为 pull-right 在 Bootstrap 4

关于html - 试图将一堆 col-md-10 div 居中但不居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47477873/

相关文章:

html - CSS 左右文本在碰撞时停止下降。

vue.js - babel.config.js babel eslint 关闭/禁用规则

javascript - 如何使用 Vue 在 API 端点中自动监视更改?

javascript - node.js 表单处理更新和删除

css - 现代浏览器是否仍然需要基于 float 的布局?

html - 选择和输入的文本颜色

javascript - VueJS 与 bootstrap-vue : one column in table without data

javascript - JQuery 无法更改背景图像 URL

点击后html链接标签颜色不变

html - 嵌套表的宽度不可更改