huskycyan

webデザインを中心に学習したことを日記として残しています。

webの授業・CSS3

CSS3の勉強の続き。

今日はlinear-gradient/radial-gradient/background-size/background複数枚指定のお勉強。
この授業に入る前に使っていたのはlinear-gradient/background-size/background複数枚指定だ。
radial-gradientだけ使いどころがなく使ってこなかったがliner-gradientはCSSの指定方法が変わらないため問題ない。
問題なのはベンダープレフィックスの指定の仕方が多少違うところだと思う。いくらなんでも行数が多すぎるうえCSSの書き方が違う。
少しのデザインのために何行にもなってしまう。W3Cが統一してくれると助かるのだが・・・

書き方
linear-gradient(開始位置と角度,開始色,途中色,終了色)
開始位置は書かないとトップからボトムへ、途中色は使わなければ書かなくてよい、途中色はいくつでも設定できる。角度はdegで指定。

radial-gradient(開始位置と角度、形状とサイズ、開始色、途中色、終了色)
開始位置は指定しないと中心から外へ、サイズは指定可能で初期値はcover、途中色は使わなければ書かなくてよい、途中色はいくつでも設定できる。

background-size(実数もしくはパーセント、auto、cover、contain)
auto-幅と高さがautoの場合元サイズ、どちらかがautoの場合比率を保ったままもう一方のサイズに合わせる。
cover-縦横比を保ったまま表示画像全体を覆うサイズにする。
contain-縦横比をたもったまま表示画像全体が表示される。

background複数表示(カンマで区切る、最初に設定したものが手前に来る)
background-image:url(),url(),url();
background-position:...,...,...,;
background-repeat:...,...,...,;
background-size:...,...,...,;

出来上がりイメージ

f:id:husky1127:20141118195210j:plain
f:id:husky1127:20141118195235j:plain

<style>
.linear-gradient{
  background:-moz-linear-gradient(white,gray);/*トップからボトムの順、ベンダープレフィックスを最初に書く*/
  background:-webkit-linear-gradient(white,gray);
  background:linear-gradient(white,gray);
  width:200px;
  height:50px;
  line-height:50px;
  color:#FFFFFF;
  text-align:center;
  }
.linear-gradient2{
  background:-moz-linear-gradient(left,#930, #FFF);/*開始位置、開始色、終了色…中間色をつけることも可能*/
  background:-webkit-linear-gradient(left,#930,#FFF);
  background:linear-gradient(to right,#930,#FFF);/*左から右へ、同じ意味*/
  width:200px;
  height:50px;
  line-height:50px;
  color:#FFFFFF;
  text-align:center;
  }
.linear-gradient3{
  background: -moz-linear-gradient(left 45deg, red, orange, yellow, green, blue, indigo, violet);  /*開始位置、開始色、中間色、終了色*/
  background: -webkit-gradient(linear, left top, right bottom, from(red), color-stop(0.2, orange), color-stop(0.3, yellow), color-stop(0.5, green), color-stop(0.7, blue), color-stop(0.8, indigo), to(violet));
  background: linear-gradient(left 45deg, red, orange, yellow, green, blue, indigo, violet);
  width:200px;
  height:50px;
  line-height:50px;
  color:#FFFFFF;
  text-align:center;
  }
.linear-gradient4{
  background: rgb(179,220,237); /* Old browsers ジェネレーター使用*/
  background: -moz-linear-gradient(top,  rgba(179,220,237,1) 0%, rgba(61,26,145,1) 48%, rgba(64,21,119,1) 50%, rgba(132,115,155,1) 100%); /* FF3.6+ */
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(179,220,237,1)), color-stop(48%,rgba(61,26,145,1)), color-stop(50%,rgba(64,21,119,1)), color-stop(100%,rgba(132,115,155,1))); /* Chrome,Safari4+ */
  background: -webkit-linear-gradient(top,  rgba(179,220,237,1) 0%,rgba(61,26,145,1) 48%,rgba(64,21,119,1) 50%,rgba(132,115,155,1) 100%); /* Chrome10+,Safari5.1+ */
  background: -o-linear-gradient(top,  rgba(179,220,237,1) 0%,rgba(61,26,145,1) 48%,rgba(64,21,119,1) 50%,rgba(132,115,155,1) 100%); /* Opera 11.10+ */
  background: -ms-linear-gradient(top,  rgba(179,220,237,1) 0%,rgba(61,26,145,1) 48%,rgba(64,21,119,1) 50%,rgba(132,115,155,1) 100%); /* IE10+ */
  background: linear-gradient(to bottom,  rgba(179,220,237,1) 0%,rgba(61,26,145,1) 48%,rgba(64,21,119,1) 50%,rgba(132,115,155,1) 100%); /* W3C */
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b3dced', endColorstr='#84739b',GradientType=0 ); /* IE6-9 */
  width:200px;
  height:50px;
  line-height:50px;
  text-align:center; /* IE6-9 */
  color:#FFFFFF;
  border-radius:10px;
}

.radial-gradient{
  background:radial-gradient
  width:200px;
  height:50px;
  line-height:50px;
  text-align:center;
  color:#FFFFFF;
  }
.radial-gradient{
  background: -moz-radial-gradient(yellow, green);
  background: -webkit-radial-gradient(radial,yellow, green);
  background: radial-gradient(yellow, green);
  width:200px;
  height:50px;
  line-height:50px;
  text-align:center;
  color:#FFFFFF;
}
.radial-gradient2{
background: rgb(255,94,97); /* Old browsers */
background: -moz-radial-gradient(center, ellipse cover,  rgba(255,94,97,1) 0%, rgba(208,228,247,1) 30%, rgba(135,188,234,1) 70%, rgba(255,94,97,1) 100%); /* FF3.6+ */
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(255,94,97,1)), color-stop(30%,rgba(208,228,247,1)), color-stop(70%,rgba(135,188,234,1)), color-stop(100%,rgba(255,94,97,1))); /* Chrome,Safari4+ */
background: -webkit-radial-gradient(center, ellipse cover,  rgba(255,94,97,1) 0%,rgba(208,228,247,1) 30%,rgba(135,188,234,1) 70%,rgba(255,94,97,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-radial-gradient(center, ellipse cover,  rgba(255,94,97,1) 0%,rgba(208,228,247,1) 30%,rgba(135,188,234,1) 70%,rgba(255,94,97,1) 100%); /* Opera 12+ */
background: -ms-radial-gradient(center, ellipse cover,  rgba(255,94,97,1) 0%,rgba(208,228,247,1) 30%,rgba(135,188,234,1) 70%,rgba(255,94,97,1) 100%); /* IE10+ */
background: radial-gradient(ellipse at center,  rgba(255,94,97,1) 0%,rgba(208,228,247,1) 30%,rgba(135,188,234,1) 70%,rgba(255,94,97,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff5e61', endColorstr='#ff5e61',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
  width:200px;
  height:50px;
  line-height:50px;
  text-align:center;
  color:#FFFFFF;
}
.background-size{
  width:600px;
  height:300px;
  background:url(test.jpg) no-repeat;
  }
  
body{
  background:url(1.jpg) no-repeat;/*backgroound-sizeテスト*/
  background-size:cover;/*cover比率を保ち全体を覆う、contain比率を保ち全体表示*/
  }
</style>
</head>

<body>
<p class="linear-gradient">linear-gradient</p>
<p class="linear-gradient2">linear-gradient2</p>
<p class="linear-gradient3">linear-gradient3</p>
<p class="linear-gradient4">linear-gradient4</p>

<p class="radial-gradient">radial-gradient</p>
<p class="radial-gradient2">radial-gradient2</p>

</body>


background複数枚指定

<style>
html,body{
  height:100%;
  }
body{
  margin:0;
    background-image:url(wall.png), url(plane.png), url(sky.jpg);
  background-position:bottom, 50% 10%, center;
  background-repeat:no-repeat;
  -webkit-background-size:100% auto, auto, cover;
  -moz-background-size:100% auto, auto, cover;
  background-size:100% auto, auto, cover;
}
</style>