html - 当我只使用 CSS 和 HTML 时,内容在加载时跳跃
问题描述
我有一个内部票务系统,它不允许JS,也不完全允许所有CSS标签。出于这个原因,我不得不调整所有可能的方法来为某些图像构建一个简单的CSS滑块(仅使用CSS和HTML)。
我唯一的问题是,每当我单击 Next/Prev 按钮时,都会创建 Jump 效果,然后加载下一张图片。我试图找到一种方法,在加载下一张图片时图片保持在同一位置。我已经尝试过 max-width: 100%; height: auto;
,但仍然没有:(。
有什么建议???非常感谢提前
<style>
#slidepicswrap {
width:640px;
height:450px;
margin:0 auto;
position:relative;
font-family:verdana, arial, sans-serif;
}
#slidepicswrap #slides {
position:absolute;
left:0;
top:0;
height:450px;
width:640px;
overflow:hidden;
text-align:center;
}
#gallerywrapper #gallery div {
width:640px; height:900px;
padding-top:10px;
position:relative;
}
#gallerywrapper #gallery div img {
clear:both;
display:block;
margin:0 auto;
border:0;
}
#gallerywrapper #gallery div h3 {
padding:10px 0 0 0;
margin:0;
font-size:18px;
}
#gallerywrapper #gallery div p {
padding:5px 0;
margin:0;
font-size:12px;
line-height:18px;
}
a {
text-decoration: none;
display: inline-block;
padding: 8px 16px;
}
a:hover {
background-color: #ddd;
color: black;
}
.previous {
background-color: #f1f1f1;
color: black;
display:inline;
float:left;
margin-left:80px;
}
.next {
background-color: #4CAF50;
color: white;
display:inline;
float:right;
margin-right:80px;<span id="CmCaReT"></span>
text-decoration:none;
}
.round {
border-radius: 50%;
}
</style>
<div id="slidepicswrap">
<div id="slides">
<div id="pic1"><img src="https://unsplash.it/g/500/350?random" alt="Image 1" width="500" height="350" /> <a class="previous" href="#pic5" rel="nofollow"><</a> <a class="next" href="#pic2" rel="nofollow">></a>
<h3>Image 1</h3>
<p>Text of image 1.</p>
</div>
<div id="pic2"><img src="https://unsplash.it/g/500/350" alt="Image 2" width="500" height="350" /> <a class="previous" href="#pic1" rel="nofollow"><</a> <a class="next" href="#pic3" rel="nofollow">></a>
<h3>Image 2</h3>
<p>Text of image 2.</p>
</div>
<div id="pic3"><img src="https://unsplash.it/g/500/350?random" alt="Image 3" width="500" height="350" /> <a class="previous" href="#pic2" rel="nofollow"><</a> <a class="next" href="#pic1" rel="nofollow">></a>
<h3>Image 3</h3>
<p>Text of image 3.</p>
</div>
</div>
</div>
解决方案
基本上你的图像在跳跃,因为你没有固定 padding-top 因此#slide的总高度正在改变
<div id="slidepicswrap">
<div id="slides">
<div id="pic1">
<img src="https://unsplash.it/g/500/350?random" alt="Image 1" width="500" height="350" />
<div>
<a class="previous" href="#pic5" rel="nofollow"><</a>
<a class="next" href="#pic2" rel="nofollow">></a>
</div>
<h3>Image 1</h3>
<p>Text of image 1.</p>
</div>
<div id="pic2"><img src="https://unsplash.it/g/500/350" alt="Image 2" width="500" height="350" />
<div>
<a class="previous" href="#pic1" rel="nofollow"><</a>
<a class="next" href="#pic3" rel="nofollow">></a>
</div>
<h3>Image 2</h3>
<p>Text of image 2.</p>
</div>
<div id="pic3"><img src="https://unsplash.it/g/500/350?random" alt="Image 3" width="500" height="350" />
<div>
<a class="previous" href="#pic2" rel="nofollow"><</a>
<a class="next" href="#pic1" rel="nofollow">></a>
</div>
<h3>Image 3</h3>
<p>Text of image 3.</p>
</div>
</div>
</div>
<style>
#slidepicswrap {
width: 640px;
height: 450px;
margin: 0 auto;
position: relative;
font-family: verdana, arial, sans-serif;
/* background: violet; */
overflow: hidden;
}
#slidepicswrap #slides {
position: absolute;
left: 0;
top: 0;
height: 450px;
width: 640px;
overflow: hidden;
text-align: center;
}
#gallerywrapper #gallery div {
width: 640px;
height: 920px;
padding-top: 10px;
position: relative;
}
#gallerywrapper #gallery div img {
clear: both;
display: block;
margin: 0 auto;
border: 0;
}
#gallerywrapper #gallery div h3 {
padding: 10px 0 0 0;
margin: 0;
font-size: 18px;
}
#gallerywrapper #gallery div p {
padding: 5px 0;
margin: 0;
font-size: 12px;
line-height: 18px;
}
a {
text-decoration: none;
display: inline-block;
padding: 8px 16px;
}
a:hover {
background-color: #ddd;
color: black;
}
.previous {
background-color: #f1f1f1;
color: black;
display: inline;
float: left;
margin-left: 80px;
}
.next {
background-color: #4CAF50;
color: white;
display: inline;
float: right;
margin-right: 80px;
text-decoration: none;
}
.round {
border-radius: 50%;
}
img {
padding-top: 10px;
}
</style>
推荐阅读
- javascript - 状态码 405(不允许的方法)试图将画布保存到数据库中
- android-studio - 升级 Android Studio 但 AVD 管理器不起作用
- html - 如何使引导图像网格响应
- gitlab - 在 Gitlab CI 中使用 gomodules 测试 Go 项目失败,并显示“包不在 GOROOT 中”
- jsf - 我可以在 JSF 渲染响应阶段跳过生成 html 并更新组件吗?
- php - htaccess 将 PHP 重写为 PNG,然后 PHP 文件旋转图像数组 - 在 PNG 重写中不起作用
- amazon-web-services - AWS CodeBuild 集内部版本号
- php - 在php中用某些属性替换元素的简单方法
- typescript - Dexie.js:Table.where() 错误,“无法读取未定义的属性‘绑定’”
- python - 从 Python 中删除字符串方括号中的元素