gpt4 book ai didi

javascript - 将列表项图像对齐到 html 中心

转载 作者:行者123 更新时间:2023-11-28 01:23:04 26 4
gpt4 key购买 nike

我正在学习响应式设计的网络开发(还是菜鸟)所以请放轻松!我会尽量做到详尽,但如果您需要更多信息,请告诉我!

所以我正在尝试设计一个对图像具有 jquery 悬停效果的页面。你会认为我在 JS 上遇到了麻烦,但我的问题要简单得多,这让我非常沮丧。我希望我的图像在最左边对齐时居中对齐。图像框是 li 的,我试图将它们添加到 div 并将 div 对齐到中心。

请注意,我还需要它能够响应,所以不能简单地添加边距或填充。

以下是我的 html 正文:

<body>
<div class="body">

<div> <img src="images/logo.png" class="image"></div>

<div class="imgs">
<ul id="da-thumbs" class="da-thumbs">
<li>
<a href="http://dribbble.com/shots/502538-Natalie-Justin-Cleaning">
<img src="images/7.jpg" />
<div><span>Natalie & Justin Cleaning by Justin Younger</span></div>
</a>
</li>
<li>
<a href="http://dribbble.com/shots/501695-Cornwall-Map">
<img src="images/9.jpg" />
<div><span>Cornwall Map by Katharina Maria Zimmermann</span></div>
</a>
</li>

</ul>
</div>
</div>


<script type="text/javascript">
$(function() {

$(' #da-thumbs > li ').each( function() { $(this).hoverdir({
hoverDelay : 75
}); } );

});
</script>
</body>

这是我的 CSS:

.body {
width: 100%;
height: 1000px;
animation-name: colorChange;
animation-duration: 10s;
animation-iteration-count: infinite;
text-align: center;
}

@keyframes colorChange {
0% {
background: #4BB4BF;
}
20% {
background: #306F7A;
}
40% {
background: #207DFF;
}
60% {
background: #1B98E0;
}
80% {
background: #7EA0E0;
}
100% {
background: #4BB4BF;
}


}

.button {
padding: 10px;
margin-top: 40px;
font-size: 20px;
}



.da-thumbs {
list-style: none;
width: 100%;
height: 100%;
position: relative;
margin: 20px auto;
padding: 0;

}
.da-thumbs li {
float: left;
margin: 5px;
background: #fff;
padding: 8px;
position: relative;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.da-thumbs li a,
.da-thumbs li a img {
display: block;
position: relative;
}
.da-thumbs li a {
overflow: hidden;
}
.da-thumbs li a div {
position: absolute;
background: #333;
background: rgba(75,75,75,0.7);
width: 100%;
height: 100%;
}
.da-thumbs li a div span {
display: block;
padding: 10px 0;
margin: 40px 20px 20px 20px;
text-transform: uppercase;
font-weight: normal;
color: rgba(255,255,255,0.9);
text-shadow: 1px 1px 1px rgba(0,0,0,0.2);
border-bottom: 1px solid rgba(255,255,255,0.5);
box-shadow: 0 1px 0 rgba(0,0,0,0.1), 0 -10px 0 rgba(255,255,255,0.3);
}





<!-- Demo content here -->





*,
*:after,
*:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 0;
margin: 0;
}

/* Clearfix hack by Nicolas Gallagher: http://nicolasgallagher.com/micro-clearfix-hack/ */
.clearfix:before,
.clearfix:after {
content: " "; /* 1 */
display: table; /* 2 */
}

.clearfix:after {
clear: both;
}

.clearfix {
*zoom: 1;
}

/* General Demo Style */
body{
font-family: Cambria, Palatino, "Palatino Linotype", "Palatino LT STD", Georgia, serif;

font-weight: 400;
font-size: 15px;

}
a{
color: #555;
text-decoration: none;
}
.container{
width: 100%;
position: relative;
min-height: 750px;
}
.clr{
clear: both;
padding: 0;
height: 0;
margin: 0;
}

.image {
max-width: 100%;
max-height: 100%;
background-size: cover;
}

.imgs {margin: 0 auto;
align: center;
}

请就如何对齐这些元素提出您的想法?

fiddle 案例: https://jsfiddle.net/eqyfm41r/3/

最佳答案

您编辑的代码:

.da-thumbs li {
display:inline-block;
width:46%;
margin: 5px;
padding: 8px;
position: relative;
}
.da-thumbs li img{
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

JSFiddle 在这里:https://jsfiddle.net/1zq95tzp/

一方面,您要使 li float ,而且您还想将框阴影添加到图像,而不是 li。这样做的原因是 li 会比图像大,所以盒子阴影会出现在远离实际图像边缘的地方。随着屏幕缩小,图像将堆叠。您可能最终需要为图像提供以下样式:

max-width:100%;

这样他们就不会以手机宽度离开页面(我没有看图片的大小)。希望对您有所帮助。

关于javascript - 将列表项图像对齐到 html 中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33223075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com