好的,我有一個網站,我想把我所有的照片放在上面,到目前為止我有一個肖像部分,但是,它不能正確顯示,我希望它成行,這樣看起來整潔,并且同樣,當您單擊影像時,它會在單擊影像時在頁面底部打開更大的影像,我希望頁面自動向下移動到影像,但我希望它打開不同的影像,這樣我就可以在底部顯示高解析度,我知道這都是 CSS 和 javascript,但我對這些并不太確定。
此外,甚至可以在計算機上使用它,它會將所有影像排成一行,您可以滾動瀏覽,在您單擊圖片并獲得大圖片后,然后當您單擊大圖片上的 x 時,它會將它們放回原處成列
這是網站,所以你可以看到我想要做什么。單擊此處轉到我正在訪問的肖像頁面
這是代碼
function myFunction(imgs) {
var expandImg = document.getElementById("expandedImg");
var imgText = document.getElementById("imgtext");
expandImg.src = imgs.src;
imgText.innerHTML = imgs.alt;
expandImg.parentElement.style.display = "block";
}
.text {
font-family: "Sofia", sans-serif;
font-size: 30px;
text-shadow: 5px 5px 5px #ababab;
margin: 0;
padding: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.link {
color: black;
font-weight: bold;
text-decoration: none;
}
.link:hover {
color: grey;
font-weight: normal;
text-decoration: none;
}
.text2 {
font-family: Comic Sans MS;
font-size: 1em;
display: inline;
}
div.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 200px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
font-family: Comic Sans MS;
font-size: 2em;
}
* {
box-sizing: border-box;
}
.column {
float: left;
width: 25%;
padding: 10px;
}
.column img {
opacity: 0.8;
cursor: pointer;
}
.column img:hover {
opacity: 1;
}
.row:after {
content: "";
display: table;
clear: both;
}
.container {
position: relative;
display: none;
}
#imgtext {
position: absolute;
bottom: 15px;
left: 15px;
color: white;
font-size: 20px;
}
.closebtn {
position: absolute;
top: 10px;
right: 15px;
color: white;
font-size: 35px;
cursor: pointer;
}
<!DOCTYPE html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<meta name="viewport" content="width=device-width" />
<meta property="og:description" content="Tyler Rawlings Photography">
<meta property="og:url" content="https://tylerphotography.tk">
<meta property="og:title" content="Tyler Rawlings Photography">
<meta name="theme-color" content="#D500FF">
<meta content="Tyler Rawlings Photography" property="og:title">
<meta name="og:site_name" content="">
<meta name="twitter:title" content="Tyler Rawlings Photography">
<meta name="twitter:description" content="Tyler Rawlings Photography">
<meta content="Tyler Rawlings Photography" property="og:description">
<meta property="og:image" content="https://tylerphotography.tk/static/TylerR.png">
<meta name="twitter:image" content="https://tylerphotography.tk/static/TylerR.png">
<meta name="og:image" content="https://tylerphotography.tk/static/TylerR.png">
<meta name="robots" content="index, follow">
<title>Tyler Rawlings Photography - About</title>
<link rel="icon" href="/static/icon.ico">
</head>
<body>
<center>
<p class='text' style="font-family:Comic Sans MS; font-size: 3em;">Tyler Rawlings</p>
<p class='text' style="font-family:Comic Sans MS; font-size: 2em;">Photography</p>
<br>
<br>
<a class='link' href='/'>
<p class='text2'>Home</p>
</a>
<a class='link' href='/about'>
<p class='text2'>About</p>
</a>
<a class='link' href='/equipment'>
<p class='text2'>Equipment</p>
</a>
<a class='link' href='https://www.instagram.com/drumsnaps' target='_blank'>
<p class='text2'>Instagram</p>
</a>
<br>
<br>
<p class='text' style="font-family:Comic Sans MS; font-size: 2em;">Portraits</p>
<br>
<div class="row">
<div class="column">
<img src="./static/nancysc.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/decsadsc.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/decsc.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/joesc.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/dadsc.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/paisleysc.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/deccorn.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/grandpop.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/robinsmoke.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/danny.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/james.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/taxman.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
<div class="column">
<img src="./static/strangerthingsjoe.PNG" alt="Portraits" style="width:100%" onclick="myFunction(this);">
</div>
</div>
<div class="container">
<span onclick="this.parentElement.style.display='none'" class="closebtn">×</span>
<img id="expandedImg" style="width:100%">
<div id="imgtext"></div>
</div>
</center>
</body>
</html>
uj5u.com熱心網友回復:
對于同樣大小的圖片,盡量將它們放在相同的寬度和高度,例如,制作一個css類.img { height: 160px;width: auto;}試試這個,并在它們之間放置邊距作為間距。抱歉,如果這沒有幫助,我認為這是您的問題,祝您好運:D
uj5u.com熱心網友回復:
我更改了您的 HTML 和 CSS 中的一些內容 - 也許它會有所幫助:
<base href="...">向該<head>部分添加了一個標簽以使示例在此處作業(現在它顯示影像)- 代替
div類row的類image-container - 制作
image-container了一個帶包裝的 flex 布局容器 - 代替
div類column的類image - 在底部添加了一些新的 CSS
<div>托管影像的元素現在具有固定大小并隱藏溢位。這樣我們就得到了一個漂亮的網格- 將 a
max-width應用于<img>元素并洗掉了行內樣式width: 100%。這樣影像保持比例。
- 使“預覽”
div元素成為絕對定位的疊加層。洗掉了class屬性并id在 CSS 代碼中分配了一個具有適當 ID 的選擇器
您可以稍微使用width/heightCSS 中的值來更改縮略圖影像的大小。
請看一下這個作業示例:
function myFunction(imgs) {
var expandImg = document.getElementById("expandedImg");
var imgText = document.getElementById("imgtext");
expandImg.src = imgs.src;
imgText.innerHTML = imgs.alt;
document.getElementById('container').style.display = "block";
}
.text {
font-family: "Sofia", sans-serif;
font-size: 30px;
text-shadow: 5px 5px 5px #ababab;
margin: 0;
padding: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.link {
color: black;
font-weight: bold;
text-decoration: none;
}
.link:hover {
color: grey;
font-weight: normal;
text-decoration: none;
}
.text2 {
font-family: Comic Sans MS;
font-size: 1em;
display: inline;
}
div.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 200px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
font-family: Comic Sans MS;
font-size: 2em;
}
* {
box-sizing: border-box;
}
.column {
float: left;
width: 25%;
padding: 10px;
}
.column img {
opacity: 0.8;
cursor: pointer;
}
.column img:hover {
opacity: 1;
}
.row:after {
content: "";
display: table;
clear: both;
}
#imgtext {
position: absolute;
bottom: 15px;
left: 15px;
color: white;
font-size: 20px;
}
.closebtn {
position: absolute;
top: 10px;
right: 15px;
color: white;
font-size: 35px;
cursor: pointer;
}
/* New CSS */
.image-container {
display: flex;
flex-wrap: wrap;
}
.image {
width: 200px;
height: 200px;
margin: 10px;
overflow: hidden;
cursor: pointer;
}
.image img {
max-width: 200px;
}
#container {
position: absolute;
left: calc(50% - 300px);
top: 10%;
width: 600px;
padding: 20px;
background-color: white;
overflow: hidden;
}
<!DOCTYPE html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<base href="https://tyler.photography/">
<meta name="viewport" content="width=device-width" />
<meta property="og:description" content="Tyler Rawlings Photography">
<meta property="og:url" content="https://tylerphotography.tk">
<meta property="og:title" content="Tyler Rawlings Photography">
<meta name="theme-color" content="#D500FF">
<meta content="Tyler Rawlings Photography" property="og:title">
<meta name="og:site_name" content="">
<meta name="twitter:title" content="Tyler Rawlings Photography">
<meta name="twitter:description" content="Tyler Rawlings Photography">
<meta content="Tyler Rawlings Photography" property="og:description">
<meta property="og:image" content="https://tylerphotography.tk/static/TylerR.png">
<meta name="twitter:image" content="https://tylerphotography.tk/static/TylerR.png">
<meta name="og:image" content="https://tylerphotography.tk/static/TylerR.png">
<meta name="robots" content="index, follow">
<title>Tyler Rawlings Photography - About</title>
<link rel="icon" href="/static/icon.ico">
</head>
<body>
<center>
<p class='text' style="font-family:Comic Sans MS; font-size: 3em;">Tyler Rawlings</p>
<p class='text' style="font-family:Comic Sans MS; font-size: 2em;">Photography</p>
<br>
<br>
<a class='link' href='/'>
<p class='text2'>Home</p>
</a>
<a class='link' href='/about'>
<p class='text2'>About</p>
</a>
<a class='link' href='/equipment'>
<p class='text2'>Equipment</p>
</a>
<a class='link' href='https://www.instagram.com/drumsnaps' target='_blank'>
<p class='text2'>Instagram</p>
</a>
<br>
<br>
<p class='text' style="font-family:Comic Sans MS; font-size: 2em;">Portraits</p>
<br>
<div class="image-container">
<div class="image">
<img src="./static/nancysc.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/decsadsc.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/decsc.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/joesc.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/dadsc.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/paisleysc.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/deccorn.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/grandpop.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/robinsmoke.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/danny.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/james.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/taxman.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
<div class="image">
<img src="./static/strangerthingsjoe.PNG" alt="Portraits" onclick="myFunction(this);">
</div>
</div>
<div id="container" style="display: none">
<div onclick="this.parentElement.style.display='none'" class="closebtn">×</div>
<img id="expandedImg" style="width:100%">
<div id="imgtext"></div>
</div>
</center>
</body>
</html>
uj5u.com熱心網友回復:
/*
find the dialog...
*/
let dialog=document.querySelector('dialog');
/*
simple object that defines methods for opening/closing a dialog
but also adds 2 event listeners specifically to close the modal
if the user clicks on the modal or loses focus
*/
let modal={
open:()=>{
if( dialog.showModal ) dialog.showModal();
else dialog.setAttribute('open',true);
dialog.addEventListener('click',(e)=>{
modal.close()
});
dialog.addEventListener('blur',(e)=>{
modal.close()
});
},
close:()=>{
if( dialog.close )dialog.close();
else dialog.removeAttribute('open');
}
};
/*
assign an event listener to each div within the `.row` container
- invoke the modal on click and set the properties of the child
elements.
*/
document.querySelectorAll('.columns > .column').forEach(n=>n.addEventListener('click',function(e){
let img=this.querySelector('img')
dialog.querySelector('img').src=img.src;
dialog.querySelector('div').textContent=img.src;
modal.open();
}));
/* unmodified rules */
.text {
font-family: "Sofia", sans-serif;
font-size: 30px;
text-shadow: 5px 5px 5px #ababab;
margin: 0;
padding: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.link {
color: black;
font-weight: bold;
text-decoration: none;
}
.link:hover {
color: grey;
font-weight: normal;
text-decoration: none;
}
.text2 {
font-family: Comic Sans MS;
font-size: 1em;
display: inline;
}
div.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 200px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
font-family: Comic Sans MS;
font-size: 2em;
}
* {
box-sizing: border-box;
}
.column {
float: left;
width: 25%;
padding: 10px;
}
.column img {
opacity: 0.8;
cursor: pointer;
}
.column img:hover {
opacity: 1;
}
.row:after {
content: "";
display: table;
clear: both;
}
.container {
position: relative;
display: none;
}
#imgtext {
position: absolute;
bottom: 15px;
left: 15px;
color: white;
font-size: 20px;
}
.closebtn {
position: absolute;
top: 10px;
right: 15px;
color: white;
font-size: 35px;
cursor: pointer;
}
/* new rules */
dialog::backdrop{
background:rgba(0,0,0,0.85)
}
.columns{
display:flex;
flex-direction:row;
flex-wrap: wrap;
}
.columns > .column{
margin:1rem!important;
width:300px;
}
dialog[open]{
border:5px solid black;
border-radius:1rem;
padding:1rem;
min-width:500px;
min-height:300px;
display:block;
z-index:10;
}
dialog[open] img{
margin:1rem;
outline:1px solid grey;
}
dialog[open] div{
margin:0.25rem 0;
color:blue;
}
.column > img{
width:200px;
}
<center>
<!--
rather than using <br> tags to create layout
or adding inline styles to elements that
should all be handled in CSS. The aim always
is to separate presentation, style and behaviour
by using separate files to help with maintenance
and development.
The fewer tags you can use the
quicker a page will load (might be hard to
discern sometimes)
Leverage the power in CSS to control the layout!
-->
<p class='text'>Tyler Rawlings</p>
<p class='text'>Photography</p>
<a class='link' href='/'>Home</a>
<a class='link' href='/about'>About</a>
<a class='link' href='/equipment'>Equipment</a>
<a class='link' href='//www.instagram.com/drumsnaps' target='_blank'>Instagram</a>
<p class='text' >Portraits</p>
<div class="row columns">
<div class="column">
<img src="//placekitten.com/300/500?image=1" alt="Portraits" />
</div>
<div class="column">
<img src="//placekitten.com/300/500?image=2" alt="Portraits" />
</div>
<div class="column">
<img src="//placekitten.com/300/500?image=3" alt="Portraits" />
</div>
<div class="column">
<img src="//placekitten.com/300/500?image=4" alt="Portraits" />
</div>
<div class="column">
<img src="//placekitten.com/300/500?image=5" alt="Portraits" />
</div>
<div class="column">
<img src="//placekitten.com/300/500?image=6" alt="Portraits" />
</div>
<div class="column">
<img src="//placekitten.com/300/500?image=7" alt="Portraits" />
</div>
<div class="column">
<img src="//placekitten.com/300/500?image=8" alt="Portraits" />
</div>
<div class="column">
<img src="//placekitten.com/300/500?image=9" alt="Portraits" />
</div>
<div class="column">
<img src="//placekitten.com/300/500?image=10" alt="Portraits" />
</div>
</div>
<dialog>
<img />
<div id='imgtext'></div>
</dialog>
</center>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/348963.html
標籤:javascript Python html css 瓶子
