「CSS」プロパティdisplayの値inline-blockを指定して横に並べ幅と高さを指定する

環境

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Google Chrome 103.0.5060.134
Windows 10 home 64bit
Google Chrome 103.0.5060.134 Windows 10 home 64bit
Google Chrome 103.0.5060.134
Windows 10 home 64bit

構文
display: inline-block;
inline-blockは、inlineのように横に並べて表示し、かつwidthとheightを指定します。

使用例

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

<div class="cft">tokyo</div>
<div class="cft">oosaka</div>
<div class="cft">fukuoka</div>
</body>
</html>

結果
div要素「tokyo」、「oosaka」、「fukuoka」は横に並べます。

CSS

Posted by arkgame