LoginSignup
1
2

More than 5 years have passed since last update.

CSS3 画像を画面中央に表示する

Posted at

コード

sample.html

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>画像を画面中央に表示する</title>
<style>
html,body{
  height: 100%;
  margin: 0;
  padding: 0;
}

#wrapper{
  height: 100%;
  display: flex;
  display: -moz-flex;
  display: -ms-flex;
  display: -webkit-flex;


  justify-content: center;
  -moz-justify-content: center;
  -ms-justify-content: center;
  -webkit-justify-content: center;

  align-items: center;
  -moz-align-items: center;
  -ms-align-items: center;
  -webkit-align-items: center;
}

img{
  box-sizing: border-box;
  border: 1px solid #EE6E73; 
  vertical-align: middle;
}
</style>
</head>
<body>
<div id="wrapper">
 <img src="sampleImg.png">
</div>
</body>
</html>

align-items: center;を使えば垂直方向の中央配置も簡単に実装できます。

実行結果

スクリーンショット 2015-07-01 17.33.57.png

1
2
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
1
2