Clearfix is an out-dated hack and unreliable cross-browser.

Regardless of the wisdom of it's use, it shouldn't be hardcoded into modules intended for general use with a variety of themes - it should be left to the theming layer and template customisation provided by end developers.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kanani’s picture

Well you can always override it by copying field-collection-item.tpl.php to your theme and removing the clearfix there.

Anonymous’s picture

Clearfix shouldn't be hardcoded. It should be used only when you need to clear floats, there are no floats in collection item.
And you can always override it in field-collection-item.tpl.php and add the clearfix when needed.

John Pitcairn’s picture

Yes, please remove this. A very typical use would be a collection of images and captions, which you might want to float right as a whole. The clearfix class can be very difficult to override in css for IE7 in particular, and it's irritating having to override a .tpl file just to achieve this.

lloop’s picture

+1

markabur’s picture

Yeah it's backwards that the theme has to *remove* styling provided by the module. Normally the module should supply basic style-free markup and the theme should add styling on top of that.

And yes, clearfix is irrelevant if you're not using floats. Since Field Collection module doesn't/shouldn't use floats anyway, it shouldn't use clearfix. If the theme adds floats then the theme can add clearfix if needed.

John Pitcairn’s picture

Title: Remove hardcoded clearfix from module » Remove hardcoded clearfixes from module

There are also two hard-coded clearfixes in module code in addition to the one in template code.

One is in field_collection_field_formatter_links(), which adds a clearfixed wrapper div.field-collection-container. This container is added for any formatter.

The other is in field_collection_field_formatter_view()

Tristan Chambers’s picture

+1 for no clearfixes

I spent an hour trying to figure out why my fields were going all kinds of weird places on the page. It wasn't until I realized that these were set "clearfix" that I was able to fix the problem. This is not only a huge annoyance but a violation of separation of content from presentation!

tisteegz’s picture

+1 for removing these clearfixes.

I have spent way too long trying to override these styles so that I can layout my field collections how I want. I have added the template to my theme but it's the hard coded clearfixes in the module which are my problem.

valderama’s picture

+1 for removing these clearfixes.

valderama’s picture

valderama’s picture

Status: Active » Needs review
briannowell’s picture

Bumping this issue. This seems to make perfect sense to me, and I am currently overriding this with a template file. However, it does seem backwards to have to do this. I should only be using templates, it seems, to ADD custom styling, not to remove it.

When will this make it into a release?

Pere Orga’s picture

Rerolled patch

joegl’s picture

Will the patch work in the latest version?

joegl’s picture

Does anyone else have a CSS fix? I've tried:

.view-display-id-block_1 .field-collection-item-field-rooms {
  clear: none !important;
}

With no luck. The clearfix class still overrides it.

EDIT: Figured it out. The clear is also on the :after pseudo class so you need:

.view-display-id-block_1 .field-collection-item-field-rooms {
  clear: none;
}
.view-display-id-block_1 .field-collection-item-field-rooms:after {
  clear: none;
}
Nabru’s picture

Patch from #13 worked for me. This should really make it to the final build.

jox’s picture

+1 please remove the clearfixes from the module.

jox’s picture

I needed to get rid of the clearfix in the field-collection-container. This is how I worked around it with css:

.field-collection-container:after {
  clear: none;
}

The problem is that when a field collection is displayed next to (or around) a floating element, then it will move all following elements after the floating element. In other words, the container with the clearfix might also get affected by elements outside of the container, not only by elements inside it (which is the purpose of a clearfix).

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll, +Needs rework

The patch from #13 does not apply to the latest 7.x-1.x-dev and is probably too old to reroll, but I went ahead and tagged the issue accordingly.

Checking patch field_collection.module...
error: while searching for:
          $element[$delta]['entity'] = $field_collection->view($view_mode);
          $element[$delta]['#theme_wrappers'] = array('field_collection_view');
          $element[$delta]['#attributes']['class'][] = 'field-collection-view';
          $element[$delta]['#attributes']['class'][] = 'clearfix';
          $element[$delta]['#attributes']['class'][] = drupal_clean_css_identifier('view-mode-' . $view_mode);

          $links = array(

error: patch failed: field_collection.module:1294
error: field_collection.module: patch does not apply