この章では、CSSを使用して畫像をレイアウトする方法を紹介します。


丸い畫像


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
<style>
img {
    border-radius: 8px;
}
</style>
</head>
<body>
<h2>圓角圖片</h2>
<p>使用 border-radius 屬性來創(chuàng)建圓角圖片:</p>
<img src="https://img.php.cn/upload/course/000/000/004/580989ec73194566.jpg" alt="Paris" width="400" height="300">
</body>
</html>

楕円形の畫像:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
<style>
img {
    border-radius: 50%;
}
</style>
</head>
<body>
<h2>橢圓形圖片</h2>
<p>使用 border-radius 屬性來創(chuàng)建橢圓形圖片:</p>
<img src="https://img.php.cn/upload/course/000/000/004/580989ec73194566.jpg" alt="Paris" width="400" height="300">
</body>
</html>



サムネイル

border略語スケッチを作成するための屬性地図。 border 屬性來創(chuàng)建縮略圖。

實(shí)例

img {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px;
}
<img src="https://img.php.cn/upload/course/000/000/004/580989ec73194566.jpg" alt="Paris">

實(shí)例

a {
    display: inline-block;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px;
    transition: 0.3s;
}
a:hover {
    box-shadow: 0 0 2px 1px rgba
    (0, 140, 186, 0.5);
}
<a href="paris.jpg">
  <img src="https://img.php.cn/upload/course/000/000/004/580989ec73194566.jpg" alt="Paris">
</a>


響應(yīng)式圖片

響應(yīng)式圖片會自動適配各種尺寸的屏幕。

實(shí)例中,你可以通過重置瀏覽器大小查看效果:

Norway

如果你需要自由縮放圖片,且圖片放大的尺寸不大于其原始的最大值,則可使用以下代碼:

實(shí)例

img {
    max-width: 100%;
    height: auto;
}

圖片文本

如何定位圖片文本:

實(shí)例

Norway
左下角
左上角
右上角
右下角
居中

卡片式圖片

實(shí)例

div.polaroid {
    width: 80%;
    background-color: white;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
img {width: 100%}
div.container {
    text-align: center;
    padding: 10px 20px;
}

圖片濾鏡

CSS filter

インスタンス

img 
{
    
-webkit-filter:
 grayscale(100%);
 
/* Chrome, Safari, 
Opera */
     
    
filter:
 grayscale(100%);
}
インスタンス

.responsive {
    padding: 0 6px;
    float: left;
    width: 24.99999%;
}
@media only screen and (max-width: 700px){
    .responsive {
        width: 49.99999%;
        margin: 6px 0;
    }
}
@media only screen and (max-width: 500px){
    .responsive {
        width: 100%;
    }
}

レスポンシブ畫像
レスポンシブ畫像は、さまざまなサイズの畫面に自動的に適応します。

この例では、ブラウザのサイズをリセットすることで効果を確認(rèn)できます:

 Norway

畫像を自由に拡大縮小する必要があり、畫像の拡大サイズが元の最大値を超えない場合は、次のコマンドを使用できます。次のコード:


var modal = document.getElementById('myModal');
// 獲取圖片模態(tài)框,alt 屬性作為圖片彈出中文本描述
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    modalImg.alt = this.alt;
    captionText.innerHTML = this.alt;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
    modal.style.display = "none";
}

畫像テキスト

畫像テキストを配置する方法:

ノルウェー
左下隅
左上隅

右上隅

右下隅

中央揃え

??カードスタイルの畫像??????例???? rrreee????????畫像フィルタ???? CSS の filter 屬性は、要素に視覚効果 (ぼかしや彩度など) を追加するために使用されます。 ??????注: この屬性は、?? Internet Explorer?? または Safari 5.1 (およびそれ以前)?? ではサポートされていません。 ??????例????すべての寫真の色を白黒に変更します(100%グレースケール):????rrreee??????????レスポンシブフォトアルバム??????例????rrreee?????????? ?? ??畫像モーダル(モジュール ステータス)????この例では、CSS と JavaScript を組み合わせて畫像を一緒にレンダリングする方法を示します。 ????まず、CSS を使用して、デフォルトでは非表示になっているモーダル ウィンドウ (ダイアログ) を作成します。 ????次に、JavaScript を使用してモーダル ウィンドウを表示します。畫像をクリックすると、ポップアップ ウィンドウに畫像が表示されます。 ??
學(xué)び続ける
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <style> img { border-radius: 8px; } </style> </head> <body> <h2>圓角圖片</h2> <p>使用 border-radius 屬性來創(chuàng)建圓角圖片:</p> <img src="https://img.php.cn/upload/course/000/000/004/580989ec73194566.jpg" alt="Paris" width="400" height="300"> </body> </html>