html - Bootstrap 表单字段不会停留在包含 div 中

标签 html css angularjs twitter-bootstrap

我想制作一个在网络和移动设备上看起来不错的 Bootstrap 表单。似乎简单的标记效果不佳。这是一个 Angular 应用程序,但我不认为 Angular 数字...

一个问题是,如果我尝试通过一个 div 包含多个字段以应用背景色,则这些字段不包含在内,溢出了 div 的左侧。

另一个我认为相关的问题是,这些字段出现在移动设备上时,左右边距为 0px,看起来不太好。

这是标记:

在索引 .html 中:

<html lang="en" ng-app="myApp">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>My BS App</title>
  <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> 
  <link rel="stylesheet" href="css/app.css"/>
</head>
<body>
  <div class="container">
    <div class="header">
      <h3 class="text-muted">My BS App</h3>
    </div>
    <div class="row">
      <div class="col-md-6">
        <div ng-view></div>

该 Angular View 指令导致表单被包含如下...

<form class="form-horizontal" name="parentForm" role="form" novalidate mb-submit="save()">
    <fieldset>
        <div ng-repeat="parent in family.parents()">
            <legend>{{parent.firstName}} {{parent.lastName}}</legend>

            <div class="row">
                <div class="form-group">
                    <div class="col-md-10">
                        <div class="checkbox">
                            <input type="checkbox" ng-checked="parent.list" ng-model="parent.list">List parent</input>
                        </div>
                    </div>
                </div>
            </div>

            <div style="background-color:red;">Why don't I contain the following?

                <div class="row">
                    <div class="form-group">
                        <div class="col-md-10">
                            <input type="text" placeholder="First name" name="firstName" class="form-control" ng-model="parent.firstName" required>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="form-group">
                        <div class="col-md-10">
                            <input type="text" placeholder="Last name" name="lastName" class="form-control" ng-model="parent.lastName" required>
                        </div>
                    </div>
                </div>

这是糟糕的结果:看到字段如何向左溢出了吗?

在网络上....

enter image description here

关于它在移动设备上的样子...

enter image description here

最佳答案

尝试删除 <div class="row">标签包裹着你的 <div class="form-group">标签。这两个类都有负的左右边距,它们由嵌套标签合并。

关于html - Bootstrap 表单字段不会停留在包含 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23296517/

相关文章:

javascript - 重写指令以不使用隔离范围?

javascript - 复杂对象的 Angular 自定义过滤器

angularjs - 我正在使用 ng-bind-html 但它导致我的 css 文本溢出 : ellipsis . 如何应用此属性?

html - 使用 D3.csv 读取 csv 数据,每一列在单独的数组中

jquery - 单击 Bootstrap Accordion 时显示不同的颜色

css - 100%的div宽度并没有占据页面的100%?

javascript - javascript根据窗口大小扩展div和bg图像

html - 如何设置两张图片超越另一张图片?

html - <li> 没有完全着色

javascript - 如何在D3.js中通过JSON文件解析按键对对象进行排序