我是CSS和网站开发的新手,并且经常使用格式。我使用了预先构建的主题,并对其进行了自定义以满足其客户的需求,并且无法更改悬停在图像上的文本的位置。
我添加了一半的html代码。有人可以帮我吗
我试图在css中使用float:center,align-text:center但没有任何作用
.home-category .block-center .inner-top a{
float:center;/* changed left*/
left:9px;
}
.home-category .block-center .inner-top a.frist{
margin-right:28px;
}
.home-category .block-center .inner-bottom{
margin-top: 14px;
float:center;/* changed left*/
}
.home-category .block-right .inner-bottom{
margin-top: 14px;
}
.home-category .info{
position:absolute;
top:50%;
left:50%; /*removed */
margin-top:-13px;
}
.home-category .info a{
color:#fff;
font-size:0;
float:center;
text-transform:uppercase;
position:relative;
font-weight:bold;
transition: all 0.3s;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
white-space:nowrap;
}
.home-category .info a:before{
float:center;
content: "";
height: 0px;
opacity: 0;
position: absolute;
left:50%;
top: 50%;
transition: all 0.2s ease-out 0s;
-webkit-transition: all 0.2s ease-out 0s;
-moz-transition: all 0.2s ease-out 0s;
-o-transition: all 0.2s ease-out 0s;
visibility: hidden;
width: 0px;
}
/*hover block left*/
.home-category .block-left:hover .info a{
font-size:128.57%;
transition: all 0.3s;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
margin-left:-25px;
margin-top:-13px;
}
.home-category .block-left:hover .image:before{
transform: scale(1);
visibility:visible;
transition: all 0.3s ease-in-out 0s;
-webkit-transition: all 0.3s ease-out 0s;
-moz-transition: all 0.3s ease-out 0s;
-o-transition: all 0.3s ease-out 0s;
opacity:1;
}
.home-category .info a:hover{
color:#25bce9
}
.home-category .block-left:hover .info a:before{
transition: all 0.2s ease-out 0s;
-webkit-transition: all 0.2s ease-out 0s;
-moz-transition: all 0.2s ease-out 0s;
-o-transition: all 0.2s ease-out 0s;
height:150px;
width:150px;
visibility:visible;
opacity:1;
margin-top:-75px;
margin-left:-75px;
}
<section class="home-category">
<div class="container">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12 block block-left">
<a href="#" class="image">
<img src="images/banner/category/1.png" alt=" Vector vector created by freepik - www.freepik.com"/>
</a>
<div class="info">
<a href="wide_format_print.html" style="justify">Wide Format<br>Printing</a>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 block block-center">
<div class="inner-top">
<div class="box-left">
<a href="#" class="image frist">
<img src="images/banner/category/2.jpg" alt="<Brochure psd created by freepik - www.freepik.com"/>
</a>
<div class="info">
<a href="promotion-material.html" style="center">Promotional Material</a>
</div>
</div>
答案 0 :(得分:0)
我发现需要对您在此处发布的css文件进行一些调整,请尝试以下更改
.home-category .info{
position:absolute;
top:50%;
width:100%;
left:0;
}
.home-category .info a{
color:#fff;
text-align:center
text-transform:uppercase;
font-weight:bold;
transition: all 0.3s;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-o-transition: all 0.3s;
white-space:nowrap;
}
答案 1 :(得分:0)
您可以这样:
.image {
display: inline-block;
position: relative;
padding: 5px;
line-height: 0;
}
.image span {
position: absolute;
left: 0;
top: 50%;
width: 100%;
text-align: center;
display: none;
font-size: 20px;
}
.image:hover span {
display: inline-block;
}
<div class="container">
<div class="image"><img src="https://via.placeholder.com/250x150" /> <span>Some text</span></div>
<div class="image"><img src="https://via.placeholder.com/125x150" /> <span>Some text</span></div>
<div class="image"><img src="https://via.placeholder.com/175x150" /> <span>Some text</span></div>
<div class="image"><img src="https://via.placeholder.com/400x150" /> <span>Some text</span></div>
<div class="image"><img src="https://via.placeholder.com/175x150" /> <span>Some text</span></div>
</div>
首先,您需要设置line-height: 0
以防止垂直间隙。
使用position: absolute
并将top: 50%
设置为垂直居中。
接下来,使用width: 100%
和text-align: center
进行水平居中。
答案 2 :(得分:0)
您可以使用display: flex;
将div从顶部和左侧居中。在CSS下方使用:
.home-category .info{
position:absolute;
top:0%;
left:0%;
margin-top:0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}