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

Question

Question

Stack fields on top of one another in an inline-block section

asked on December 22, 2016

I'm looking for a way to use CSS to achieve the following:

I have 7 fields, I want them to be inline - I am able to do this using the display: inline-block feature.  

The last two fields are Pickup Date & Due Date and I would like them to be stacked on top of one another inside of this inline-block and I'm not sure how to do both.  

I've included the existing code I have and two images of what I'm looking to achieve.  

#q110, #q111, #q112, #q113, #q114, #q115, #q116 {display: inline-block; width: 16%; vertical-align: top;}
#q115, #q116 {position: absolute; position: relative;}
/*115 & 116 are the fields I would like to stack*/

What it shows:

 

What I want it to look like:

0 0

Answer

SELECTED ANSWER
replied on December 23, 2016

While the first question was easy, this one is a bit harder due to the way that Float behaves. In general, when it wraps to a new line, it will wrap to a location that is just below the tallest element on the line above (as you discovered). You have a few choices:

  1. Build an HTML table using table, tr, td, etc... then use javascript to move the Laserfiche fields into the cells. This makes the grid alignment easy, but it can cause other formatting problems. Certain CSS features are not available in Table elements, and this approach is generally frowned upon in modern web development.
  2. Manually position each element with CSS. This is tedious, and can be tough to get right in a way that will display well on a variety of screens/devices. Wouldn't recommend this either.
  3. Use a third party library... Something like the jQuery Masonry plugin. By far the easiest way, but it does require you to reference another script when you load the page. This is what I would recommend, and I can give you a code snippet that uses Masonry below

You will need to use the JavaScript section to load the script and initialize it for your collection of fields. You have to target the container of the elements to apply the script. I would recommend putting your collection of fields into a section, and giving that a CSS class like "ShipmentDetails". Within that section, there will be a <ul> HTML element that contains a bunch of <li> elements which are the actual fields. When you give a field a CSS class, it applies to the <li> element. You should arrange your fields in the following order and give them the following classes on the layout page:

  1. Shipment (inline stack)
  2. Supplier (inline fix)
  3. Consignee (inline fix)
  4. Qty (inline fix)
  5. Weight (inline fix)
  6. Pickup Date (inline stack)
  7. Mode (inline stack)
  8. Due Date (inline stack)

Keep your CSS, but you no longer need the stack1. Then add the following JavaScript:

$(document).ready(function(){
  $.getScript("https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js",function(){
    $(".ShipmentDetails ul").masonry({
      itemSelector: ".inline",
      columnWidth: ".inline",
    });
  });
});

This loads the plugin, applies the Masonry logic to the <ul> within your target section, tells it to apply the layout/formatting to items within the <ul> that have the inline class, and tells it to use the width of the inline class as the default column width for the grid layout.

1 0

Replies

replied on December 22, 2016

I would recommend trying to use "float" to get that effect. You have to be careful with the heights of your elements when you float things, so I would also recommend using a fixed height for your fields.

Here is something I threw together to demo. The first 5 fields have the "inline-6" and the "fix-height" classes, while the last 2 fields have the "inline-6" and "stack" classes.

.inline-6 {
  display: inline-block;
  float:left;
  width: 16%;
}
.fix-height {
  height: 110px;
}
.stack{
  height: 55px;
}

1 0
replied on December 22, 2016

That works great!  Thank you for the help!

0 0
replied on December 22, 2016

Scott,

Now that you helped me with this, I am hoping you can help me take this a bit further...  Now I want to add another field 'Mode:' to appear under the Shipment: field.  Any ideas?  Here's what I tried with a little luck, just not really aesthetically pleasing.  

.inline {
  display: inline-block;
  float:left;
  width: 16%;
}
.fix {
  height: 120px;
}
.stack, stack1{
  height: 60px;
}
.stack1 {
  float: left;
}

Where I've assigned stack1 to the 8th field (Mode)

Here is what it looks like:

I know it's being picky, but I want the mode to be inline with the 'Due Date'

Nate

0 0
replied on December 23, 2016

That did it!  Thank you so much, Scott!

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

Sign in to reply to this post.