html - 使用 Bootstrap 容器时,div 没有固定大小

标签 html css twitter-bootstrap

我目前正在尝试创建一组 div。它们中的内容将是动态的,所以我想为每个设置一个固定的。就目前而言,每个盒子的尺寸都不同。我想利用 max-width,但没能成功。我希望无论屏幕大小如何,除了每个 .role 的大小相同之外,所有内容的行为都相同。请注意,父 container 是一个 Bootstrap container。这是我的 jsFiddle

编辑:我希望所有 div 的大小都相同。理想情况下,如果每个框都是最大框的大小(动态内容插入到 pheaders 中),那就太好了。

index.html

<div class="container">
    <div class="role-list">
    <div class="role">
        <h3>Firefighter - The Best of the best</h3>
        <p>He is a great and I know that he loves his job.
        He is a great and I know that he loves his job
            He is a great and I know that he loves his job
            He is a great and I know that he loves his job

        </p>
    </div>
        <div class="role">
        <h3>Firefighter </h3>
        <p>He is a great and I know that he loves his job</p>
    </div>    
        <div class="role">
        <h3>Firefighter </h3>
        <p>He is a great and I know that he loves his job</p>
    </div>    
        <div class="role">
        <h3>Firefighter - The Best of the best</h3>
        <p>He is a great and I know that he loves his job
             He is a great and I know that he loves his job
            He is a great and I know that he loves his job
            </p>
    </div>   
    </div>
</div>

CSS

.role {
  display: inline-block;
  width: 47%;
  margin: 10px 10px;
  padding: 2%;
  vertical-align: top;
  background: #fff;
  border: 1px solid #ebebeb;
  text-decoration: none;
  -webkit-transition: all 0.2s;
  -moz-transition: all 0.2s;
  -o-transition: all 0.2s;
  -ms-transition: all 0.2s;
  transition: all 0.2s;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}

最佳答案

您应该能够通过向您的 css 添加一个最小宽度来完成此操作。将以下内容添加到 CSS 中的 .role 中。您可以将最小宽度设置为您喜欢的任何大小。

min-width: 400px;

为了实现相同大小的框,您需要设置 width 和 height CSS 属性。这可能会有点棘手,因为如果内容长于尺寸可以处理的长度,那么它将拉伸(stretch) div,除非您将溢出设置为滚动。

jsFiddle

关于html - 使用 Bootstrap 容器时,div 没有固定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32570615/

相关文章:

html - CSS:如何在段落前添加一行?

jquery - 在 HTML 表格中隐藏/显示列

html - 悬停不在 css 菜单 active li 类上工作?对别人有用吗?

html - 为 Bootstrap 面板分配最小宽度

css - 在轮播图片下方显示轮播标题

javascript - 使用 JavaScript 和 AJAX,我还需要 HTML <form> 标签吗?我还需要使用 "submit"按钮向服务器提交表单吗?

html - CSS Position relative goes over fixed 如何解决这个问题?

javascript - 当它说element.style时如何找到代码的来源?

javascript - 打印 div 有效,但在 jQuery 顶部有空格

jquery - jQuery 更新后 Bootstrap 选项卡哈希 : Uncaught Error: Syntax error, 无法识别的表达式 : . nav-tabs a