HTMLとCSSとJavaScriptとPHP

角を丸くする border-radius

border-radius

borderの角の処理で矩形を角丸にできる

Firefox3.6では全く効きません。Firefox4.0は微妙にボーダーにラインが入るようです。safari5.05Chrome11は少し描画がおかしいようです。IE8以下は全く効きません。IE9ではうまくいくようです。Opera11.10は画像が丸くならず、ボーダーも少しおかしいようです。

HTMLファイルを作成


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>border-radius</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; }
  section h1,section img{
  	border:1px solid #000000;
  }
</style>
</head>
<body>
	<section>
		<h1>border-radiusを使わない</h1>
		<p><img src="images/mydog.jpg" alt="mydog"></p>
	</section>
</body>
</html>
		

h1要素とp要素にCSSで1pxの黒のボーダーを設定しています。(わかりよくするためだけでボーダーを設定しないと角丸にならないわけではありません。)

上記サンプルを開く

border-radiusを設定


  section h1,section img{
  	border:1px solid #000000;
  	border-radius:10px;
  	}
		

border-radius:10px;10pxのところを変更するだけです。ここはパーセントも指定できます。ボーダーの長さに対してと思われます。

上記サンプルを開く

border-radiusの詳細な設定


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>border-radius</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; }
  section h1,section img{
  	border:1px solid #000000;
	border-radius:10px;
  }
  .radius1{
	border-radius:10px 20px 30px 40px;
  }
  .radius2{
	border-radius:10px / 50px;
  }
  .radius3{
  	border-radius:50%;
  }  
</style>
</head>
<body>
	<section>
		<h1>border-radiusを設定</h1>
		<p><img src="images/mydog.jpg" alt="mydog"></p>
		<p><img src="images/mydog.jpg" alt="mydog" class="radius1"></p>
		<p><img src="images/mydog.jpg" alt="mydog" class="radius2"></p>
		<p><img src="images/mydog.jpg" alt="mydog" class="radius3"></p>
	</section>
</body>
</html>
		

上記サンプルを開く

border-radiusの詳細な設定2


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>border-radius</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; }
  .radius1{
	border:20px #000000 solid;
	border-radius:40px;
  }
  .radius2{
	border:20px #000000 double;
	border-right: 20px #ff0000 solid;
	border-bottom: 20px #000000 dashed;
	border-radius:40px;
  }
  .radius3{
	border:20px #000000 solid;
	border-radius:40px;
	border-left-color:#ff0000;
	border-right-style:none;
  }
  .radius4{
	border:20px #000000 solid;
	border-radius:40px;
	border-left:10px #ff0000 solid;
	border-right:40px #ff0000 solid;
  }
</style>
</head>
<body>
	<section>
		<h1>border-radiusの詳細設定2</h1>
		<p class="radius1">HTMLとCSSとJavaScriptとPHP</p>
		<p class="radius2">HTMLとCSSとJavaScriptとPHP</p>
		<p class="radius3">HTMLとCSSとJavaScriptとPHP</p>
		<p class="radius4">HTMLとCSSとJavaScriptとPHP</p>
	</section>
</body>
</html>
		

ボーダーは4方向個別に設定できるので太さや色が違った時の描画を比べてみました。

上記サンプルを開く