- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘CSS’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Can all (major) browsers left align or right align elements using margin-right: auto
and margin-left: auto
, respectively?
I did this last year (I think) with Mozilla Firefox, and it didn’t work. But when I tried now, it actually aligns it perfectly. I just want to know if this is a valid way, and a relatively well supported method?
Edit:
I do not mean center aligning stuff (already know how to do that.) I mean, like this:
https://jsfiddle.net/akhurshid/2sswp/
And I do know about using float
s to align. I just want to know if setting one property to be auto
is “correct.”
Yes.
As for what didn’t work last year…we can’t comment as we don’t know what you tried.
That said, I can’t think doing it this way is very useful.
Really? Horizontally aligning something without making the proceeding content flow seems useful, i.e.:
.foobar {
margin-left: auto;
}
vs.
.foobar {
float: right;
clear: both;
}
As a single element on a row sure…but put another element on the same row and you see why floats are usually used.
https://jsfiddle.net/ggqymnes/
These days, I’d use flexbox where it does make sense to use margin-x:auto