親要素の直下にある要素にmargin-topをつけても期待通りには動かない。
マージンの色が親要素のさらに親要素の背景色になってしまう問題がある。
[解決方法]
・スペースを取りたいときにはpaddingを使う(marginは使わない)
・何か(a など)を挟み込んで配置を変えてやる(親要素直下でなければ期待通りに動く)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<body> <div class="sampleDiv"> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="sampleTable"> <tr> <th scope="row">サンプルサンプルサンプルサンプル</th> <td>サンプルサンプルサンプルサンプル</td> </tr> </table> </div> </body> body { background:#FFF; } .sampleDiv { background:#000; } .sampleTable{ margin-top:100px; } |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<body> <div class="sampleDiv"> a <table width="100%" border="0" cellspacing="0" cellpadding="0" class="sampleTable"> <tr> <th scope="row">サンプルサンプルサンプルサンプル</th> <td>サンプルサンプルサンプルサンプル</td> </tr> </table> </div> </body> body { background:#FFF; } .sampleDiv { background:#000; } .sampleTable{ margin-top:100px; } |
この記事を書いた人
新着記事
2015.11.27Illustrator[Mac]IllustratorのカラーモードをRGBへ変更する方法
2015.11.27IllustratorIllustratorのカラーモードをRGBへ変更する方法
2015.11.26Illustrator[Mac]IllustratorのカラーモードをCMYKへ変更する方法
2015.11.25IllustratorIllustratorのカラーモードをCMYKへ変更する方法