国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

圖片

響應(yīng)式 Web 設(shè)計 - 圖片


使用 width 屬性

如果 width 屬性設(shè)置為 100%,圖片會根據(jù)上下范圍實現(xiàn)響應(yīng)式功能:

實例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8"> 
<title>php 中文網(wǎng)</title> 
<style>
img {
    width: 100%;
    height: auto;
}
</style>
</head>
<body>

<img src="https://img.php.cn/upload/article/000/000/024/5c668566136f4479.jpg" width="460" height="345">
<p>調(diào)整瀏覽器窗口查看圖像是如何擴展的。</p>

</body>
</html>

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例

注意在以上實例中,圖片會比它的原始圖片大。我們可以使用 max-width 屬性很好的解決這個問題。


使用 max-width 屬性

如果 max-width 屬性設(shè)置為 100%, 圖片永遠不會大于其原始大?。?/p>

實例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8"> 
<title>php 中文網(wǎng)</title> 
<style>
img {
    max-width: 100%;
    height: auto;
}
</style>
</head>
<body>

<img src="https://img.php.cn/upload/article/000/000/024/5c668566136f4479.jpg" width="460" height="345">
<p>調(diào)整瀏覽器大小,在寬度小于 460px 時查看圖片比例變化。</p>

</body>
</html>

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例


網(wǎng)頁中添加圖片

實例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
<style>
* {
    box-sizing: border-box;
}
img {
    width: 100%;
    height: auto;
}
.row:after {
    content: "";
    clear: both;
    display: block;
}
[class*="col-"] {
    float: left;
    padding: 15px;
    width: 100%;
}
@media only screen and (min-width: 600px) {
    .col-s-1 {width: 8.33%;}
    .col-s-2 {width: 16.66%;}
    .col-s-3 {width: 25%;}
    .col-s-4 {width: 33.33%;}
    .col-s-5 {width: 41.66%;}
    .col-s-6 {width: 50%;}
    .col-s-7 {width: 58.33%;}
    .col-s-8 {width: 66.66%;}
    .col-s-9 {width: 75%;}
    .col-s-10 {width: 83.33%;}
    .col-s-11 {width: 91.66%;}
    .col-s-12 {width: 100%;}
}
@media only screen and (min-width: 768px) {
    .col-1 {width: 8.33%;}
    .col-2 {width: 16.66%;}
    .col-3 {width: 25%;}
    .col-4 {width: 33.33%;}
    .col-5 {width: 41.66%;}
    .col-6 {width: 50%;}
    .col-7 {width: 58.33%;}
    .col-8 {width: 66.66%;}
    .col-9 {width: 75%;}
    .col-10 {width: 83.33%;}
    .col-11 {width: 91.66%;}
    .col-12 {width: 100%;}
}
html {
    font-family: "Lucida Sans", sans-serif;
}
.header {
    background-color: #9933cc;
    color: #ffffff;
    padding: 15px;
}
.menu ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
.menu li {
    padding: 8px;
    margin-bottom: 7px;
    background-color :#33b5e5;
    color: #ffffff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}
.menu li:hover {
    background-color: #0099cc;
}
.aside {
    background-color: #33b5e5;
    padding: 15px;
    color: #ffffff;
    text-align: center;
    font-size: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}
.footer {
    background-color: #0099cc;
    color: #ffffff;
    text-align: center;
    font-size: 12px;
    padding: 15px;
}
</style>
</head>
<body>

<div class="header">
<h1>Chania</h1>
</div>

<div class="row">
<div class="col-3 col-s-3 menu">
<ul>
<li>The Flight</li>
<li>The City</li>
<li>The Island</li>
<li>The Food</li>
</ul>
</div>

<div class="col-6 col-s-9">
<h1>The City</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two parts, the old town and the modern city.</p>
<img src="https://img.php.cn/upload/article/000/000/024/5c668566136f4479.jpg" width="460" height="345">
</div>

<div class="col-3 col-s-12">
<div class="aside">
<h2>What?</h2>
<p>Chania is a city on the island of Crete.</p>
<h2>Where?</h2>
<p>Crete is a Greek island in the Mediterranean Sea.</p>
<h2>How?</h2>
<p>You can reach Chania airport from all over Europe.</p>
</div>
</div>

</div>

<div class="footer">
<p>調(diào)整瀏覽器窗口大小查看內(nèi)容變化。</p>
</div>

</body>
</html>

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例


背景圖片

背景圖片可以響應(yīng)調(diào)整大小或縮放。

以下是三個不同的方法:

1、 如果 background-size 屬性設(shè)置為 "contain", 背景圖片將按比例自適應(yīng)內(nèi)容區(qū)域。圖片保持其比例不變:


這是 CSS 代碼:

實例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8"> 
<title>php 中文網(wǎng)</title> 
<style>
div {
    width: 100%;
    height: 400px;
    background-image: url('https://img.php.cn/upload/article/000/000/024/5c66874932cfb699.jpg');
    background-repeat: no-repeat;
    background-size: contain;
    border: 1px solid red;
}
</style>
</head>
<body>

<p>調(diào)整瀏覽器大小查看效果。</p>

<div></div>

</body>
</html>

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例

2. 如果 background-size 屬性設(shè)置為 "100% 100%" ,背景圖片將延展覆蓋整個區(qū)域:


實例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8"> 
<title>php 中文網(wǎng)</title> 
<style>
div {
    width: 100%;
    height: 400px;
    background-image: url('https://img.php.cn/upload/article/000/000/024/5c66874932cfb699.jpg');
    background-size: 100% 100%;
    border: 1px solid red;
}
</style>
</head>
<body>

<p>調(diào)整瀏覽器大小查看效果。</p>

<div></div>

</body>
</html>

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例

3. 如果 background-size 屬性設(shè)置為 "cover",則會把背景圖像擴展至足夠大,以使背景圖像完全覆蓋背景區(qū)域。注意該屬性保持了圖片的比例因此 背景圖像的某些部分無法顯示在背景定位區(qū)域中。


這是 CSS 代碼:

實例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8"> 
<title>php 中文網(wǎng)</title> 
<style>
div {
    width: 100%;
    height: 400px;
    background-image: url('https://img.php.cn/upload/article/000/000/024/5c66874932cfb699.jpg');
    background-size: cover;
    border: 1px solid red;
}
</style>
</head>
<body>

<p>調(diào)整瀏覽器大小查看效果。</p>

<div></div>

</body>
</html>

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例


不同設(shè)備顯示不同圖片

大尺寸圖片可以顯示在大屏幕上,但在小屏幕上確不能很好顯示。我們沒有必要在小屏幕上去加載大圖片,這樣很影響加載速度。所以我們可以使用媒體查詢,根據(jù)不同的設(shè)備顯示不同的圖片。

以下大圖片和小圖片將顯示在不同設(shè)備上:

   

實例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8"> 
<title>php 中文網(wǎng)</title> 
<style>
/* For width smaller than 400px: */
body {
    background-repeat: no-repeat;
    background-image: url('https://img.php.cn/upload/article/000/000/024/5c66874932cfb699.jpg'); 
}

/* For width 400px and larger: */
@media only screen and (min-width: 400px) {
    body { 
       background-image: url('https://img.php.cn/upload/article/000/000/024/5c66874932cfb699.jpg'); 
    }
}
</style>
</head>
<body>

<p style="margin-top:360px;">調(diào)整瀏覽器寬度,背景圖片在小于 400 px 時將改變。</p>

</body>
</html>

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例

你可以使用媒體查詢的 min-device-width 替代 min-width 屬性,它將檢測的是設(shè)備寬度而不是瀏覽器寬度。瀏覽器大小重置時,圖片大小不會改變。

實例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8"> 
<title>php 中文網(wǎng)</title> 
<style>
/* For device width smaller than 400px: */
body {
    background-repeat: no-repeat;
    background-image: url('https://img.php.cn/upload/article/000/000/024/5c66874932cfb699.jpg'); 
}

/* For device width 400px and larger: */
@media only screen and (min-device-width: 400px) {
    body { 
       background-image: url('https://img.php.cn/upload/article/000/000/024/5c66874932cfb699.jpg'); 
    }
}
</style>
</head>
<body>

</body>
</html>

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例


HTML5 <picture> 元素

HTML5 的 <picture> 元素可以設(shè)置多張圖片。

瀏覽器支持

函數(shù)1546322463316818.gif1546322467179911.gif3.gif4.gif5.gif
:visited不支持38.038.0不支持25.0

<picture> 元素類似于 <video><audio> 元素。可以設(shè)備不同的資源,第一個設(shè)置的資源為首選使用的:

實例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8"> 
<title>php 中文網(wǎng)</title> 
</head>
<body>

<picture>
    <source srcset="https://img.php.cn/upload/article/000/000/024/5c66874932cfb699.jpg" media="(max-width: 400px)">
    <source srcset="https://img.php.cn/upload/article/000/000/024/5c66874932cfb699.jpg">
    <img src="https://img.php.cn/upload/article/000/000/024/5c66874932cfb699.jpg" alt="Flowers" style="width:auto;">
</picture>

<p>調(diào)整瀏覽器寬度和高度,背景在寬度小于 400px 時將改變。 </p>

</body>
</html>

運行實例 ?

點擊 "運行實例" 按鈕查看在線實例

srcset 屬性的必須的,定義了圖片資源。

media 屬性是可選的,可以在媒體查詢的CSS @media 規(guī)則 查看詳情。

對于不支持 <picture> 元素的瀏覽器你也可以定義 <img> 元素來替代。