0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

画像のサイズを修正

Posted at

画像を表示するためのimg要素にサイズの情報を付加していない場合なら

HTML
<p class="sample">
    <img src="riverchildren.jpg" alt="写真">
</p>

上記では画像ファイル「riverchildren.jpg」を表示させていますが、縦横のサイズは記述していません。
この場合は、以下のようにCSSソースを記述するだけで、画像を望みのサイズで表示できます。

CSS
p.sample img {
    width: 200px;  /* 横幅を200pxに */
}

上記では、class名に「sample」が指定されたp要素に含まれるimg要素に対して、横幅200pxで表示する指定を加えています。これだけで、横幅が200pxになった上で、高さは縦横比を維持して自動調整されます。

https://www.nishishi.com/css/resize-image-keep-aspect-ratio.html

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?