Read more

Use different CSS depending on whether elements render on the same line or multiple lines

Henning Koch
May 30, 2012Software engineer at makandra GmbH

You will find this useful when creating responsive designs that work well on small screens.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

The attached Javascript gives a container different CSS classes (single_line or multiple_lines) depending on whether its children render on one line or multiple lines.

Initialize it with the selectors for container and children:

$(function() {
  $('.navigation').countLines('a');
});

You can now use different CSS styles like this:

.navigation
  &.single_line a
    // styles when all anchors are rendered on the same line
  &.multiple_lines a
    // styles when anchors are rendered on multiple lines
Posted by Henning Koch to makandra dev (2012-05-30 11:22)