Question

Is it ok to keep a tag directly inside in bootstrap 3? or it's preferable to have every inside .row>.col-md-#

is this structure ok or can create problem on mobile

<div class="container">
  <h1>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</h1>
  <div id="ajaxID">
    <div class="row">
      <div class="col-md-6">Some pic</div>
      <div class="col-md-6">Some text</div>
    </div>
    <div class="row">
      <div class="col-md-6">Some pic</div>
      <div class="col-md-6">Some text</div>
    </div>
  </div>  
</div>
Was it helpful?

Solution

Yes, you can nest directly within container if you don't need a multicolumn section. Check out the source of the home page of Bootstrap docs:

<div class="bs-docs-featurette">
  <div class="container">
    <h2 class="bs-docs-featurette-title">Designed for everyone, everywhere.</h2>
    <p class="lead">Bootstrap makes front-end web development faster and easier. It's made for folks of all skill levels, devices of all shapes, and projects of all sizes.</p>

    <hr class="half-rule">

    <div class="row">
      <div class="col-sm-4">
        <img src="assets/img/sass-less.png" alt="Sass and Less support" class="img-responsive">
        <h3>Preprocessors</h3>
        <p>In addition to vanilla CSS, Bootstrap includes support for the two most popular CSS preprocessors, <a href="../css/#less">Less</a> and <a href="../css/#sass">Sass</a>.</p>
      </div>
      <div class="col-sm-4">
        <img src="assets/img/devices.png" alt="Responsive across devices" class="img-responsive">
        <h3>One framework, every device.</h3>
        <p>Bootstrap easily and efficiently scales your project with one code base, from phones to tablets to desktops.</p>
      </div>
      <div class="col-sm-4">
        <img src="assets/img/components.png" alt="Components" class="img-responsive">
        <h3>Comprehensive docs</h3>
        <p>With Bootstrap, you get extensive and beautiful documentation with hundreds of live examples, code snippets, and more.</p>
      </div>
    </div>

    <hr class="half-rule">

    <p class="lead">Bootstrap is open source. It's hosted, developed, and maintained on GitHub.</p>
    <a href="https://github.com/twbs/bootstrap" class="btn btn-outline btn-lg">View the GitHub project</a>
  </div>
</div>

Notice the p.lead and button are both directly under the container. Rows and columns should only be used if you're actually making columns.

OTHER TIPS

If h1 is centered I don't see why it wouldn't work fine, if it's aligned to the left there might be a margin/padding issue. I'm not sure whether it's correct or not, but why not placing that h1 and #ajaxID above the container or in col-*-12 column just in case?

According to Bootstrap documentation, you can't do this:

Content should be placed within columns, and only columns may be immediate children of rows.

Source: Bootstrap documentation, grid introduction

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top