gpt4 book ai didi

html - CSS中的垂直对齐菜单

转载 作者:行者123 更新时间:2023-11-28 12:40:46 25 4
gpt4 key购买 nike

我一直在创建以下菜单。不能让它居中。似乎 span 中的 img 正在破坏显示。

期望的结果: menu

HTML:

<ul id="rounded-cats" class="cleardiv">
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
<li>
<a href="#">
<span>
<img src="http://placehold.it/70" height="70" />
</span>
<strong>
Category name
</strong>
</a>
</li>
</ul>

CSS:

#rounded-cats {
text-align: center;
//display: table;
border: 1px solid red;
width: 100%
}
#rounded-cats li {
//margin-bottom: 20px;
//height: 190px;
display: inline;
}
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span img {
display: inline !important
}
#rounded-cats a:hover span {
background: #7c6eb0
}
#rounded-cats a:hover {
color: #7c6eb0
}
#rounded-cats img {
margin: auto;
display: block;
}

JSFIDDLE: http://jsfiddle.net/gtux2snu/

最佳答案

看看这个demo

我更改了 #rounded-cats li#rounded-cats span img 样式。

#rounded-cats {
text-align: center;
//display: table;
border: 1px solid red;
width: 100%
}
#rounded-cats li {
//margin-bottom: 20px;
//height: 190px;
display: inline-block;
width:150px;//added some width to each li
float:left;//floated elements left
text-align:left;//aligned category name with image
padding:20px;//add padding so it looks good and separated.
}
#rounded-cats span {
background: #c7c7c7;
width: 112px;
height: 112px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
text-align: center;
display: block;
vertical-align:middle;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
#rounded-cats span img {
display: inline !important;
margin-top:18px;//centered img inside circle
}
#rounded-cats a:hover span {
background: #7c6eb0
}
#rounded-cats a:hover {
color: #7c6eb0
}
#rounded-cats img {
margin: auto;
display: block;
}

关于html - CSS中的垂直对齐菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26489141/

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