4

Resize a div and center it with bootstrap

 2 years ago
source link: https://www.codesd.com/item/resize-a-div-and-center-it-with-bootstrap.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Resize a div and center it with bootstrap

advertisements

I have a form wrapped by a bordered fieldset, now all the form fields fill the fieldset's width. I need some of the textfield shorter and centered. At the moment I'm only able to shorten them using in example col-md-10, but then I don't know how to center them, they stay aligned to the left.

Here is how the fields look like

<div class="form-group">
<label for="planner" class="control-label">form.planner *</label>
<input class="form-control" id="planner" name="planner" type="text">

In addition to form-group, I've tried to add "col-md-10 center-block", but that didn't help, I also tried several combinations using span and offset, but no luck.

The following image shows what I have and what I want, how could I do?

TwChN.jpg

Not all the fields will have to be resized, the form continues below the shown fields and some of the other fields must fit the fieldset's width as they do now.


With col-md-10 add the class col-md-offset-1 to center the col-md-10 element. Like this:

<div class="row">
    <div class="col-md-10 col-md-offset-1">
       I'm centered!!
    </div>
</div>

The offset classes, well, offset the element by the count on the class name, so for a 12 column grid, to center a 10 col element, you move it over 1, hence the col-md-offset-1 class.

For example, to center a col-md-6 element, you would offset it by 3 columns, using the col-md-offset-3 class.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK