[html]画像ファイルを中央寄せにする

2021年12月1日

1.画像を中央寄せにします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<div style="text-align: center;">
<img src="./images/100.png" width="120"/>
</div>
<div style="text-align: center;"> <img src="./images/100.png" width="120"/> </div>
<div style="text-align: center;">
  <img src="./images/100.png" width="120"/>
</div>

画像の親の要素でtext-align:centerを指定します

2.画像のサイズを指定します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<img src="./images/200.png" width="120"/>
<img src="./images/200.png" width="120"/>
<img src="./images/200.png" width="120"/>

width(幅)とheight(高さ)を指定できます。
数値のみの場合、単位はpxです。%の指定も可能です

3.画像ファイルを表示する

構文
<img src ="画像ファイル名">
imgタグとsrcを指定します。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<body>
<img src="100.png" />
<img src="./img/100.png" />
<image src="100.png" />
</body>
<body> <img src="100.png" /> <img src="./img/100.png" /> <image src="100.png" /> </body>
<body>
  <img src="100.png" />
  <img src="./img/100.png" />
  <image src="100.png" />
</body>

 

Html

Posted by arkgame