条件1. 対象がブロック要素である
条件2. 対象にwidthが規定されている
条件3. 親要素にwidthが規定されている
※htmlデフォルトでbodyにwidthが規定されており(子要素に継承されているとのこと)
|
1 2 3 4 5 6 7 |
.sample { width:300px; display:block; margin:0 auto; background:yellow; border:solid 1px; } |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無題ドキュメント</title> <style> .sample { width:300px; display:block; margin:0 auto; background:yellow; border:solid 1px; } .sample--block { display:block; } .sample--inline-block { display:inline-block; } .sample--inline { display:inline; } .sample--table { display:table; } </style> </head> <body> <div> <span class="sample sample--block">display:block;</span> </div> <div> <span class="sample sample--inline-block">display:inline-block;</span> </div> <div> <span class="sample sample--inline">display:inline;</span> </div> <div> <span class="sample sample--table">display:table;</span> </div> </body> </html> |
この記事を書いた人
新着記事
2015.11.27Illustrator[Mac]IllustratorのカラーモードをRGBへ変更する方法
2015.11.27IllustratorIllustratorのカラーモードをRGBへ変更する方法
2015.11.26Illustrator[Mac]IllustratorのカラーモードをCMYKへ変更する方法
2015.11.25IllustratorIllustratorのカラーモードをCMYKへ変更する方法