W3.CSS 画像

❮ 前章へ 次章へ ❯

画像の表示

角丸:

Northern Lights

円形:

Forest

ボーダー付き:

Mountains

テキスト:

Nature
Nature

角丸画像

Norway

w3-round class adds rounded corners to an image:

<img src="img_fjords.jpg" class="w3-round" alt="Norway">
Try It Yourself ❯

円形画像

Norway

w3-circle class shapes an image to a circle:

<img src="fjords.jpg" class="w3-circle" alt="Norway">
Try It Yourself ❯

ボーダー付き画像

Norway

w3-border class adds borders around the image:

<img src="fjords.jpg" class="w3-border w3-padding" alt="Norway">
Try It Yourself ❯

カードのような画像

カードのように (そして影を) 表示するために、<img> 要素の周りを w3-card-* クラスでラップします:

Lights

Person

Simon

boss of all bosses

<div class="w3-card-4">
  <img src="img_avatar.png" alt="Person">
</div>
Try It Yourself ❯

レスポンシブ画像

画像が、自動的にコンテナのサイズに合うように自分自身のサイズを変更するように設定することができます。

しなければならないことの全ては、画像幅を 100% に設定することです:

<div class="w3-container">
  <img src="img_lights.jpg" alt="Lights" style="width:100%">
</div>
Try It Yourself ❯

レスポンシブ画像を最大サイズに制限したい場合は、max-width プロパティを使用します:

<div class="w3-container">
  <img src="img_lights.jpg" alt="Lights" style="width:100%;max-width:400px">
</div>
Try It Yourself ❯

画像へのテキスト

画像へテキストを配置するには、w3-display-classes を使用します:

Lights

Top Left

Top Right

Bottom Left

Bottom Right

Middle

画像の上部または下部に中央揃えのテキストを配置することもできます:

sailboat

Top Middle

Bottom Middle

<div class="w3-display-container">
  <img src="img_lights.jpg" alt="Lights">
  <div class="w3-display-topleft w3-container">Top Left</div>
  <div class="w3-display-topright w3-container">Top Right</div>
  <div class="w3-display-bottomleft w3-container">Bottom Left</div>
  <div class="w3-display-bottomright w3-container">Bottom Right</div>
  <div class="w3-display-middle w3-large">Middle</div>
</div>
Try It Yourself ❯

ホバー効果付き画像

Norway

w3-hover-opacity クラスは、マウスオーバーすると画像に透明度を追加します:

<img src="fjords.jpg" class="w3-hover-opacity" alt="Norway">
Try It Yourself ❯

不透明度

w3-opacity クラスは、画像を透明にします:

Normal

With class="w3-opacity"

<img src="img_forest.jpg" alt="Forest" class="w3-opacity">
Try It Yourself ❯

デフォルトの不透明度は 0.6 です。これは、0 ~ 1 の値に変更できます:

<img src="img_forest.jpg" alt="Forest" class="w3-opacity" style="opacity:0.2">
Try It Yourself ❯

Opacity 0.2

class="w3-opacity"

Opacity 0.8


フォトアルバムの作成

この例では、すべてのデバイス上で見映えの良いフォトアルバムを作成するため、W3.CSS レスポンシブ・グリッド・システムを使用しています。 これについては、後段で詳細を学習します。

Summer 2015

5 Terre

Monterosso

Vernazza

Manarola

Corniglia

Riomaggiore


<div class="w3-third">
  <div class="w3-card-2">
    <img src="img_monterosso.jpg" style="width:100%">
    <div class="w3-container">
      <h4>Monterosso</h4>
    </div>
  </div>
</div>
Try It Yourself ❯

❮ 前章へ 次章へ ❯