You are viewing limited content. For full access, please sign in.

Question

Question

CSS and forms - three fields in a row

asked on January 5, 2021

I'm only a novice at CSS and was hoping for some help with formatting a form I'm creating. 

 

I've managed to use classes to make an inline-block for three fields to appear in a horizonal row, however the spacing is very weird and I'm hoping to get some suggestions to make this look more consistent. My first field takes up the most space, but is still only at 33% of the width. 

 

I've used the following CSS to make it happen, but as you can see below it works, but does not look great. Any help would be much appreciated as it's taken me quite some time to just get to here! 

.Row {display:inline-block; width: 33%; vertical-align:top;}
.Row .cf-field {width:600px;}
.Row .cf-label {width:100%}

0 0

Replies

replied on January 5, 2021 Show version history

For the issue with the label, if your form is set to have labels on the Left, then it adds an additional class and the percentage width for that is overriding your custom CSS.

To fix that, either switch Labels to Top, or add !important like so:

.Row .cf-label {width:100% !important;}

CSS is applied based on "specificity" so any time there's conflicting settings, the most specific selector is what is applied. !important is like the "nuclear option" that can override anything that isn't already using !important.

CSS Specificity (w3schools.com)

 

Next, you'll probably want to switch the radio buttons to either side-by-side, or two columns, but if you set them to two colums your 600px width on .cf-field is going to be a problem.

Instead that should be 100%, or maybe 98% to ensure you have some spacing between fields.

.Row .cf-field {width:100% !important;}

Lastly, instead of setting the .cf-field element to 600px to keep your field inputs wide enough, you can either set them to Large (X-Large will work for the Initials/Single Line, but not the Date), or you can manually set a width for the input children.

If you do this, you'll need to keep the % lower to ensure there's room for the date picker icon, so something like 85% would do the trick.

Putting it all together and consolidating duplicate settings you get:

.Row {
  display:inline-block;
  width: 33%;
  vertical-align:top;
}

.Row .cf-field,
.Row .cf-label {
  width:100% !important;
}

.Row .cf-field input[type="text"] {
  width: 85% !important;
}

NOTE: the reason for the input[type="text"] selector is to make sure it doesn't affect the radio inputs.

2 0
You are not allowed to follow up in this post.

Sign in to reply to this post.