Simplifying a code

When using not on Blogger,

I just wanted to know why it may be necessary to have

  margin: 0;
  padding: 0;

On this rule-set.

.nav {
  margin: 0;
  padding: 0;
  list-style: none;
}

But not this one.

.nav li {
  float: left;
}

or should those properties be on this one too.


.nav li {
  float: left;
}

Because that’s how you want it to be, nothing more, nothing less. It’s a design choice. You can use one, both or none. There is no technical reason why one should be preferred over the other. It’s entirely down to how you want things to appear visually.

But I didn’t write the code, @PaulOB did, so maybe he would know the answer to this.

Fine if that’s what you wish to do. I did mention that Paul is on the same timezone as myself and Technobear, didn’t I?

Oh, it’s 1 am over there.

1 Like

A little after, but close enough…

Please consider a less restrictive view. It is not a black and white matter of necessity, it is a gray matter of context.

The <ul> and <ol> elements have {margin:1em 0} and {padding-left:2.5em} by default. Coders may (or may not) assign {margin:0} to the list element to eliminate the vertical margins and may assign {padding:0} to eliminate the {padding-left:2.5em}. Whether he does or not depends on the context in which the list is being used and the way it is displayed.

The setting depends on context. A horizontal menu compared to a vertical menu provide classic examples of when the margins and padding might be used or not.

The padding-left provides room for the default list markers to show. It is is removed, the list markers disappear.

This has nothing to do with <ul> or <ol> it’s

<li>

#121

The ul and ol elements have default margin and padding applied by the UA therefore you need to remove them when you don’t want those properties affecting your layout.

The li element has no default padding or margin so you don’t need to add those rules for it.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.