Confused about a Note in Supporting older browsers article

Hi

I am studying CSS on MDN. In this article, https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Supporting_Older_Browsers, there is a note which says " Note: The clear property also has no effect once the cleared item becomes a grid item, so you could have a layout with a cleared footer, which is then turned into a Grid Layout. My confusion is Shouldn’t it need to say " once the floated item becomes grid item " instead of " once the cleared item becomes a grid item ". Same in the below line " floated footer " instead of " cleared footer ".

Thank you.

1 Like

Hi Ali,

The code snippet above that note use the float property to align the three items inside a container to support older browser. The paragraph above the snippet says that the float property will be ignored if the element is a grid item. Since clear and float can be used toghether to avoid some tedious “bug”. The note correctly says that the clear property is also has no effect if the element is a grid item.

I hope to have been clear (with the hope that you’re not a grid item :smiley: )

1 Like

I do think that might be clearer. Especially since the clear property does not even appear in code on this page. Do you want to file an issue for this on the content repo? I am happy to assist you if needed.

The easiest way would be to click the “Report a problem with this content on GitHub” link at the bottom of the page you linked to.


Schalk
Staff Community Manager - MDN Web Docs

3 Likes

Hi,

First of all, thank you for the response. Let me clear my question again the note says " The clear property also has no effect once the cleared item becomes a grid item, so you could have a layout with a cleared footer, which is then turned into a Grid Layout.". let say we have floated items inside some container. If we make that container a grid container then all the items inside that container will become grid items and items will ignore the float property.

That means if floated items became grid items then the float property will be ignored. So if there are no floated elements then the clear property has no use here as it only works with the float property.

So how do we make cleared item grid item? But we can make floated item grid item. I hope my confusion is clear now.

Thank you.

1 Like

It believe that the “cleared item(s)” and “floated item(s)” refer to the different elements. Let’s look at another example. We use a simple unordered list like this:

<ul class="card-list">
  <li>Card 1</li>
  <li>Card 2</li>
  <li>Card 3</li>
  <li>Card 4</li>
</ul>

<p>When the above list items are floated, I need to be cleared to be on my own line.</p>

with the following CSS:

.card-list {
  list-style: none;
}

.card-list li {
  float: left;
  margin-right: 1rem;
}

p {
  clear: left;
}

If you now change the above to the following:

.card-list {
  list-style: none;
}

.card-list li {
  float: left;
  margin-right: 1rem;
}

p {
  clear: left;
}

@supports (display: grid) {
  .card-list {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(4, 1fr)
  } 
}

The list items inside card-list become grid items, so the float property does not affect the list items anymore. Also, technically, the clear: left; rule is no longer needed for the paragraph element. So you have two options here. First, you could leave the code as-is, and everything would work as expected.

You could also reset the clear property to its default value as follows:

@supports (display: grid) {
  .card-list {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(4, 1fr)
  }

  /* this is not needed as the `clear` property will no longer have any effect */
  p {
    clear: initial; /* this will reset the `clear` attribute to `none` */
  }
}

This will reset clear to its initial state of none, but there is no need for this, really. When floating the elements, you will also notice that we give each list item a right margin of 1rem. You should reset this to the browser default in the same way we reset the clear property or, simply to 0 which has the same result.

@supports (display: grid) {
  .card-list {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(4, 1fr)
  }

  .card-list li {
    margin-right: initial; /* this will reset the margin to `0`  */
  }

  /* this is not needed as the `clear` property will no longer have any effect */
  p {
    clear: initial; /* this will reset the `clear` attribute to `none` */
  }
}

See the Pen Grid layout with float fallback by Schalk Neethling (@schalkneethling) on CodePen.

1 Like

Hi, schalkneethling,

Thank you for the response. Your example is very clear but my exact point regarding the " Note " is " once the cleared item becomes a grid item " so in your above example who is the " cleared item ". the paragraph right, not the list items because they are floated items. So if we make the " .card-list " container a grid container then that means the floated items now became grid items not the cleared item which is a paragraph, in this case, that is cleared. If we just for a moment think like " once the floated item becomes a grid item "I won’t be confused like this.

So I think either the note needs to be more clear or I am not getting it right.

Thank you.

2 Likes

You are 100% correct. I will open a pull request to update that note.

2 Likes

Thank you very much for your support schalkneethling,

Also please check under the note where the heading is " Float and clear " under the heading " Fallback methods" which says " As shown above, the float and clear properties cease to affect the layout if floated or cleared items become flex or grid items. " Do you think it also needs some updating as it is saying the same thing here?

Again thank you.

1 Like

I opened an issue(https://github.com/mdn/content/issues/15285) suggesting that we consider removing that particular note. Please feel free to comment in the issue.

1 Like

Thank you schalkneethling.