通过容器宽度的响应性

时间:2015-05-06 17:17:14

标签: twitter-bootstrap responsiveness

我正在使用bootstrap进行响应式表单布局。我能够通过bootstrap网格系统实现响应式布局(col-xs - ..,col-md - ..等等) 以下是工作示例:http://jsfiddle.net/xf93jnLw/2/

问题是由于媒体查询,表单布局是通过屏幕视口宽度调整的,其中左侧导航宽度+表格容器宽度。我希望仅根据表格容器宽度调整响应度。因此,如果我想在模态窗口中使用此表单容器,则表单字段和标签应通过表单容器宽度进行调整,而不是整个屏幕视图端口。是否有任何纯CSS解决方案?

感谢您的回复...

HTML代码:              左导航                                                    

                                                                                       用于测试的长尺寸标签:                         

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>

                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Medium sized label:"><div class="content ng-binding">Medium sized label:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>

                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Short label:"><div class="content ng-binding">Short label:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>

                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Long sized label for testing:"><div class="content ng-binding">Long sized label for testing:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>

                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Medium sized label:"><div class="content ng-binding">Medium sized label:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>

                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Short label:"><div class="content ng-binding">Short label:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>
                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Long sized label for testing:"><div class="content ng-binding">Long sized label for testing:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>

                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Medium sized label:"><div class="content ng-binding">Medium sized label:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>

                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Short label:"><div class="content ng-binding">Short label:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>
                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Long sized label for testing:"><div class="content ng-binding">Long sized label for testing:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>

                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Medium sized label:"><div class="content ng-binding">Medium sized label:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>

                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Short label:"><div class="content ng-binding">Short label:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>
                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Long sized label for testing:"><div class="content ng-binding">Long sized label for testing:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>

                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Medium sized label:"><div class="content ng-binding">Medium sized label:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>

                <div class="ers-field col-xs-12 col-sm-6 col-md-6 col-lg-6">
                    <div class="col-xs-4 col-sm-4 ers-col-label">
                        <label class="ers-label" title="Short label:"><div class="content ng-binding">Short label:</div></label>
                    </div>

                    <div class="col-xs-8 col-sm-8 ers-col-field">
                        <input type="text" class="form-control">
                    </div>
                </div>                    

                <div class="clearfix visible-lg-block"></div>

        </div>
      </div>
    </fieldset>
  </form>
</div>

CSS:

.left-nav {float:left; background:purple; color:white; height:100%; width:10%;}
.form-container {float:left;width:85%; background:lightblue}
.ers-field {
  margin: 0 0 3px 0; }
  .ers-field .ers-label {
    padding: 8px 0 5px 5px;
    font: normal 13px Arial, sans-serif; }
    .ers-field .ers-label .required {
      color: #cc0000; }
    .ers-field .ers-label .content {
      max-width: 93%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      float: left; }
  .ers-field .ers-input {
    padding: 0 15px 0 5px; }

@media (max-width: 1000px) {
  .ers-col-field, .ers-col-label {
    padding: 0 5px; } }
@media (min-width: 1001px) {
  .ers-col-field, .ers-col-label {
    padding: 0 15px 0 5px; } }

1 个答案:

答案 0 :(得分:0)

jsFiddle

检查一下,我不确定这是否解决了您的问题,但您可能想要重新编码HTML并按照这样的方式进行操作。它不仅更整洁,而且更标准,更易于维护。

您还可以查看我的答案HERE它可能有助于您更好地了解Bootstrap的网格系统。