新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
詳解CSS圖片布局
層疊樣式表(英文全稱(chēng):Cascading Style Sheets)是一種用來(lái)表現(xiàn)HTML(標(biāo)準(zhǔn)通用標(biāo)記語(yǔ)言的一個(gè)應(yīng)用)或XML(標(biāo)準(zhǔn)通用標(biāo)記語(yǔ)言的一個(gè)子集)等文件樣式的計(jì)算機(jī)語(yǔ)言。CSS不僅可以靜態(tài)地修飾網(wǎng)頁(yè),還可以配合各種腳本語(yǔ)言動(dòng)態(tài)地對(duì)網(wǎng)頁(yè)各元素進(jìn)行格式化。

圓角圖片
實(shí)例
圓角圖片:
img {
border-radius: 8px;
}
實(shí)例
橢圓形圖片:
img {
border-radius: 50%;
}
縮略圖
我們使用 border 屬性來(lái)創(chuàng)建縮略圖。
實(shí)例
img {
border: 1px solid #ddd;
border-radius: 4px;
padding: 5px;
}
實(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);
}
響應(yīng)式圖片相冊(cè)
實(shí)例
.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%;
}
}
圖片 Modal(模態(tài))
本實(shí)例演示了如何結(jié)合 CSS 和 JavaScript 來(lái)一起渲染圖片。
首先,我們使用 CSS 來(lái)創(chuàng)建 modal 窗口 (對(duì)話框), 默認(rèn)是隱藏的。
然后,我們使用 JavaScript 來(lái)顯示模態(tài)窗口,當(dāng)我們點(diǎn)擊圖片時(shí),圖片會(huì)在彈出的窗口中顯示:
實(shí)例
// 獲取模態(tài)窗口
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 element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
文章名稱(chēng):詳解CSS圖片布局
本文網(wǎng)址:http://fisionsoft.com.cn/article/cdsicss.html


咨詢
建站咨詢
