LoginSignup
30
24

More than 5 years have passed since last update.

filter: blur するとフチがぼやける対策

Last updated at Posted at 2016-01-06

image
^これに

css
  img {
    -webkit-filter: blur(10px);
  }

^blurになるスタイルを当てると

image
^こうなる。フチまでブラーがかかってしまうため、このままだとちょっと使いづらい。

で、こうする。

html
<div>
  <img src="nekocyan.jpg" alt="" width="500" height=333">
</div>

imgをwrapperで包んで

css
  div {
    width: 500px;
    height: 333px;
    position: relative;
    overflow: hidden;
  }
  img {
    position: absolute;
    width: 520px;
    height: 353px;
    top: -10px;
    left: -10px;
  }

枠になるdivのサイズに元の画像サイズに指定し、overflow: hidden;に。
中のimgはblurのpxぶんだけ四方に伸ばす。(blurのpxの2倍を縦横に足す)
で、blurのpxぶんのネガティブマージンをとると
image
こんな感じにフチが綺麗なblur画像になる。

追記

コメント頂いたやり方のほうが全然スマートな方法でした。
コメント欄ご参照ください。

30
24
4

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
30
24