0
1

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 5 years have passed since last update.

CSSでボタンを作成する

Last updated at Posted at 2017-08-15

目的

以下のボタンを作成する

button.png

コード

indexl.html
<!DOCTYPE html>
<html lang="ja">
<head>
	<meta charset="UTF-8">
	<style type="text/css">
		body {
		    margin: 0;
		    background: #e0e0e0;
		    text-align: center;
		    font-family: Verdana, sans-serif;
		}
		#btn {
			width: 170px;
			height: 30px;
			margin: 0 auto;
			padding: 7px;
			font-size: 20px;
			border-radius: 5px;
			cursor: pointer;
		    background: #00aaff;
			box-shadow: 4px 4px 0 #0088cc;
			}
		#btn:hover {
			opacity: 0.8;
		}
	</style>
</head>
<body>
	<div id="card">
		<div id="card-front"></div>
		<div id="card-back"></div>
	</div>
		<div id="btn">BUTTON</div>
	</body>
</html>

margin: 0 auto;

「margin: 0 auto;」を記述する事で、ボタンを中央揃いにする事ができます。
第1引数の0は上下、第2引数のautoは左右の幅を指定します。
第2引数をautoで指定した場合、左右等分のmarginが算出され、ボックスは中央に配置されます。

参考

http://kojika17.com/2012/08/margin-of-css.html
https://techacademy.jp/magazine/9355

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?