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

Question

Question

Mobile friendly in-line css

asked on June 22, 2020

I found a post from a few years back that mentioned using the Display: inline-block CSS causes issues with the mobile friendly nature of Forms, and that fields could still be displayed side by side without using that CSS, but it didn't explain how. Here's that discussion:

https://answers.laserfiche.com/questions/114442/Mobile-friendly-form#114456

 

Does anyone know how to go about formatting fields so that they can appear side by side but also retain the ability to be compatible for mobile? I've been using display: inline-block to get forms looking real nice on PC, but they look horrid on mobile and I'm just now realizing that's because of the CSS I've been writing. Any tips/tricks to writing mobile friendly CSS that also looks great on desktop would be much appreciated. Thanks!

2 0

Answer

SELECTED ANSWER
replied on June 22, 2020 Show version history

I've been utilizing the CSS media rules to only apply my inline field settings dynamically based on the size of the display and that seemed to do the trick on a form I recently launched.

In the example below, the any display larger than 600px or more gets the inline styles, and anything smaller gets different settings, including making the form title smaller and hiding the form border and page background.

@media (min-width:600px){
  .smallField,
  .mediumField,
  .largeField {
    display:inline-block;
    vertical-align: top;
  }

  .smallField {
    width:25% !important;
  }

  .mediumField {
    width: 37.5% !important;
  }

  .largeField {
    width: 50% !important;
  }
}

@media (max-width:600px){
  body {
    background-image: none !important;
  }
  
  .cf-formwrap {
    box-shadow: none !important;
  }
  
  .smallField,
  .mediumField,
  .largeField {
    width: 100% !important;
  }
  
  #form-logo {
      width: 40px !important;
      margin-right: 18px !important;
  }

  #form-title-wrap {
      padding-left: 58px !important;
  }

  #form-title-wrap label {
      font-size: 10px !important;
  }

  #form-title-wrap h1 {
      font-size: 14px !important;
      line-height: 25px !important;
      min-height: 25px !important;
  }
}

Things will be a bit different depending on whether you're using left labels, top labels, etc., but this should give you a general idea.

Chrome and the new version of Edge also have pretty good mobile emulation for testing if you right-click, inspect, then enable the device toolbar.

 

3 0
replied on February 9, 2022

Thank you, Jason, for sharing this post with me during Empower - sometimes we lookup for answers and get bogged down in the multitude of them, to sift through and find the right one. Your seems down to the point, can't wait to try it!

 

0 0
replied on February 9, 2022

It works wonderfully, Stefka! I've now got this CSS on every single one of our forms. Enjoy it :D

1 0

Replies

replied on August 31, 2020

Hey All!

I found Dylan's question and Jason's response extremely helpful!  Thanks for posting!

Here is what my form looked like (on the phone) before I added the info from Jason's post:

I then inserted the following info (from the very top of Jason's answer):

@media (min-width:600px){
  .smallField,
  .mediumField,
  .largeField {
    display:inline-block;
    vertical-align: top;
  }

into the top of the CSS for my form, saved it, and got great results when viewing my form on a Samsung Galaxy in Edge.  

On a PC the form looks like this:

 

On the mobile device (Samsung Galaxy using Edge Browser) it now looks like this:

No overlapping, wonky fields when viewed on a mobile device, and the form looks the way I want it to on a full sized screen.

Thanks again,

Hope someone finds this helpful too.

Christine

 

2 0
replied on September 1, 2020 Show version history

Christine,

I'm glad you found this useful! I'm happy someone else found this helpful :) Have fun making all of your forms mobile-friendly!!!

0 0
replied on June 23, 2020

Thank you very much Jason! This is a fantastic starting off point. I've never even heard of media rules before (LF is the only exposure I've had to CSS and JavaScript). It sounds like I can simply just nest the existing inline-block CSS classes under that media rule and have it accomplish exactly what I'm looking to do. All those other modifications you have included as well are definitely something I'll play with too, so thank you for those as well! I also had no idea about that mobile emulator and that will be fantastic for testing, so once again, thank you!!!

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

Sign in to reply to this post.