Cofey
Cofey

Reputation: 11404

Trouble with content overlapping horizontal form using responsive Twitter Bootstrap

I have spent more time than I ever care to admit trying to fix this stupid bug. I have a form that displays to the left of some content. It looks okay on a wide and narrow screen, but on a tablet width (it overlays between 770 and 950 or so) the content to the right overlaps the form fields.

Am I missing something in my markup to use Twitter Bootstrap properly or do I need to add some custom styles using breakpoints to fix it? It appears that the fixed pixel width is causing the issue defined in bootstrap.css. Shouldn't these width properties use % since I'm using a fluid responsive layout? enter image description here

<div class="container-narrow">
  <div class="content">
    <div class="row-fluid">
      <div class="span5">
        <form class="form-horizontal" id="applies-Step1-form" action="/" method="post">
          <div class="control-group">
            <label class="control-label required" for="Step1_email">Email <span class="required">*</span></label>
            <div class="controls">
              <input size="60" maxlength="255" name="Step1[email]" id="Step1_email" type="text" />
            </div>
          </div>

          <div class="control-group">
            <label class="control-label required" for="Step1_home_zip">Home Zip <span class="required">*</span></label>
            <div class="controls">
              <input size="5" maxlength="5" name="Step1[home_zip]" id="Step1_home_zip" type="text" />
            </div>
          </div>
        </form>
      </div>

      <div class="span7">
        <div class="promo-btm">
          <h2>Heading 2</h2>
          <ul class="checks">
            <li>Bullet One</li>
            <li>Bullet Two</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</div>

See the attached screenshot for the bug or you can reproduce it yourself using my fiddle.

If someone could help point out a way to fix this I would be extremely appreciative!

Upvotes: 9

Views: 10979

Answers (3)

David Taiaroa
David Taiaroa

Reputation: 25495

The other posts have pinpointed the root cause of the problem, that your form is too wide for the span5 div with the default bootstrap css

It's not too difficult to make it fit though. See if this helps : http://jsfiddle.net/panchroma/FXXaZ/

I have tightened up your form with this CSS:

/* pull control label left */
.form-horizontal .control-label {
width:70px; /* default 160 */
}

/* pull input box left */
.form-horizontal .controls {
margin-left: 90px; /* defaul 180 */
}

/* shorten input box  */
input, textarea, .uneditable-input {
width: 180px; /* default 206 */
}

Good luck!

Upvotes: 1

Andres I Perez
Andres I Perez

Reputation: 75379

Just add a width to your input elements so they can adapt responsively with all of your screen sizes. You can use something like .span12 as a width on your input elements and that should fix the issue:

HTML

<div class="container-narrow">
  <div class="content">
    <div class="row-fluid">
      <div class="span5">
        <form class="form-horizontal" id="applies-Step1-form" action="/" method="post">
          <div class="control-group">
            <label class="control-label required" for="Step1_email">Email <span class="required">*</span></label>
            <div class="controls">
              <input class="span12" size="60" maxlength="255" name="Step1[email]" id="Step1_email" type="text" />
            </div>
          </div>

          <div class="control-group">
            <label class="control-label required" for="Step1_home_zip">Home Zip <span class="required">*</span></label>
            <div class="controls">
              <input class="span12" size="5" maxlength="5" name="Step1[home_zip]" id="Step1_home_zip" type="text" />
            </div>
          </div>
        </form>
      </div>

      <div class="span7">
        <h2>Heading 2</h2>
        <ul class="checks">
          <li>Bullet One</li>
        </ul>
      </div>
    </div>
  </div>
</div>

Demo: http://jsfiddle.net/yR7Ap/18/

Upvotes: 5

thebjorn
thebjorn

Reputation: 27311

Your form is too wide for the .span5 column. Try adding this above:

<div class="row-fluid">
  <div class="span5">hello</div>
  <div class="span7">world</div>
</div>

and add the following style:

.row-fluid > div { outline: 5px solid green; }

and you'll see what I mean.

Upvotes: 0

Related Questions