「CSS」インライン要素とブロックレベル要素を使うサンプル

環境
Google Chrome 103.0.5060.66(Official Build)

構文
1.margin上下左右効きます。
2.display:inline-blockと指定するとinlineと同じように画面上は横に並びます。
3.widthとheightで幅と高さを指定できます。
4.displayにinline-blockを指定しています

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<head>
<style>
.cft div {
display: inline-block;
height: 50px;
margin: 20px 20px 20px 20px;
background-color: skyblue;
}
</style>
</head>
<body>
<div class="cft">
<div>111 tokyo</div>
<div>222 oosaka</div>
<div>333 fukuoka</span>
</div>
</body>
</html>
<!DOCTYPE html> <html> <head> <style> .cft div { display: inline-block; height: 50px; margin: 20px 20px 20px 20px; background-color: skyblue; } </style> </head> <body> <div class="cft"> <div>111 tokyo</div> <div>222 oosaka</div> <div>333 fukuoka</span> </div> </body> </html>
<!DOCTYPE html>
<html>
<head>
<style>
  .cft div {
    display: inline-block;
    height: 50px;
    margin: 20px 20px 20px 20px;
    background-color: skyblue;
  }
</style>
</head>
<body>

<div class="cft">
  <div>111 tokyo</div>
  <div>222 oosaka</div>
  <div>333 fukuoka</span>
</div>

</body>
</html>

実行結果
inline-blockの指定があるので横に並びます,widthとheightとmarginは反映されます。

CSS

Posted by arkgame