If you want each div
to have margin: 0 auto;
, then use a simple element selector like
div {
margin: 0 auto;
}
If you want to center the div
having IDs ONLY, then use element[attr] selector like
div[id] {
margin: 0 auto;
}
But beware before using these; they are too general, and will lead to inconsistent results if your layout gets broader, so it's better to wrap an element around these div
elements you want to apply margin: 0 auto;
on and assign an ID to that(say, #wrapper
) and than use a selector like
#wrapper > div {
margin: 0 auto;
}
Or, using
#wrapper {
margin: 0 auto;
}
should suffice as well...
Don't want to use a wrapper element? Modify your IDs like #center-first
, #center-second
and so on, then you can use element[attr=val] selector like
div[id^=center-] {
margin: 0 auto;
}
The above selector matches ANY IDS which start with a word center
followed by a -
Demo