Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap form inside panel layout looks wrong

If I have a form defined inside a bootstrap panel, then the form group layout goes to pieces.

enter image description here

I coloured the form red so that I could see where it was ;) here's the jsFiddle : https://jsfiddle.net/DTcHh/

I have found that if I add

.panel-body .form-horizontal .form-group {
    margin-right: 25px;
    margin-left: 25px;
}

to the css, I then get this

enter image description here

(I coloured the form red so that I could see where it was ;) )

so it looks like it's fixed, but seems a terrible hack to me

  • Is this is a bug in bootstrap
  • Do I just have to apply this css
  • Is there something wrong with my form definitions ?

thanks

like image 714
jmls Avatar asked Aug 07 '15 13:08

jmls


People also ask

What is the default layout of the bootstrap form?

Bootstrap Form LayoutsVertical form (this is default)

What is form inline in bootstrap 5?

Inline formsUse the .row-cols-* classes to create responsive horizontal layouts. By adding gutter modifier classes, we'll have gutters in horizontal and vertical directions. On narrow mobile viewports, the .col-12 helps stack the form controls and more.

How do I center a form in bootstrap 5?

To center a div on the page, you need to set the width of your container, then apply margin:0 auto; to it and it will center left and right on the page. If you want to center text, just add text-center to the class of the div your text is in. Bootstrap will do the rest. Save this answer.


1 Answers

According to bootstrap docs (https://getbootstrap.com/docs/3.4/css/#forms-horizontal), the class form-horizontal makes <form> act like a .row so you don't need to add it and have .col-**-* in from groups, label and stuff. The docs give you an example o

But you have a .row inside a .row and no .col-**-*. .row has negative margin to delete the padding of his parent so with no .col-**-* as parent it has 2 negative margins.

So it's kind of messy. I suggest removing your .row and .form-horizontal class to achieve the look you want or add the margin like you already did.

Here it's a fiddle.

like image 57
Turqueso Avatar answered Sep 28 '22 19:09

Turqueso