3 ms·
> I can't center my divs properly. This is actually pretty simple, once you understand how "block" elements work. Block elements will always try to fill up the
by wbkang 8y ago
> I can't center my divs properly.
This is actually pretty simple, once you understand how "block" elements work. Block elements will always try to fill up the "available width" i.e., they stretch side ways. The sum of margin + its width must match the total width.
Inline elements will fill up its parent block like text.
So, a simple example - suppose you set a div's width to 100px, and margin to auto, then you will a 100px wide box centered.
I see people get confused when they try to have a block that has an unspecified width and hope CSS just figures out.
- ken 8y ago> This is actually pretty simple, once you understand how "block" elements work. I disagree -- in this and every case where someone has told me that something is simple once you understand the fundamentals. Understanding how a tool works is completely different from understanding how to use it to accomplish a particular goal. One's a deconstructive process, and the other is a constructive process.