【问题标题】:Unable to make icons align top with <li> containers无法使图标与 <li> 容器顶部对齐
【发布时间】:2018-06-10 20:47:09
【问题描述】:

现场演示在ashenglowgaming.com

在以下列表中,我无法使我的图标与&lt;li&gt; 容器的顶部对齐。我试过vertical-align: text-topvertical-align: top 无济于事。

请注意,图标是向左浮动的,如果我删除此样式,它们会消失。

在你建议之前 - 我不允许使用绝对定位。

图标也使用transform: scale(0.75); - 我不知道这是否相关。

HTML:

<div class="right-widget">
<div class="execphpwidget">
<div class="narrowed games-list" style="text-align: left">
<p>Games I am writing/YouTubing about (more to come):</p>
<ul style="list-style-type: none;">
<li class="game-list-item age-of-empires-iii"><a href="https://www.ashenglowgaming.com/category/age-of-empires-iii/"><div style="display: block; overflow: hidden;">Age of Empires III</div></a></li>
<li class="game-list-item civilization-iii"><a href="https://www.ashenglowgaming.com/category/civilization-iii/"><div style="display: block; overflow: hidden;">Civilization III</div></a></li>
<li class="game-list-item factorio"><a href="https://www.ashenglowgaming.com/category/factorio/"><div style="display: block; overflow: hidden;">Factorio</div></a></li>
<li class="game-list-item heroes-of-the-storm"><a href="https://www.ashenglowgaming.com/category/heroes-of-the-storm/"><div style="display: block; overflow: hidden;">Heroes of the Storm</div></a></li>
<li class="game-list-item league-of-legends"><a href="https://www.ashenglowgaming.com/category/league-of-legends/"><div style="display: block; overflow: hidden;">League of Legends</div></a></li>
<li class="game-list-item pubg"><a href="https://www.ashenglowgaming.com/category/pubg/"><div style="display: block; overflow: hidden;">PUBG</div></a></li>
<li class="game-list-item stellaris"><a href="https://www.ashenglowgaming.com/category/stellaris/"><div style="display: block; overflow: hidden;">Stellaris</div></a></li>
</ul>
</div>
</div>

CSS:

.category-civilization-iii .entry-title:before, .civilization-iii a:before {
float: left;
content: "";
background: url("https://www.ashenglowgaming.com/wp-content/uploads/2017/12/category-game-icons.png"); 
background-position: -100px -95px;
background-repeat: no-repeat;
width: 90px;
height: 90px;
margin-bottom: 10px;
margin-right: 10px;
}

.civilization-iii :before{
transform: scale(0.75);
}

.category-age-of-empires-iii .entry-title:before, .age-of-empires-iii a:before {
float: left;
content: "";
background: url("https://www.ashenglowgaming.com/wp-content/uploads/2017/12/category-game-icons.png"); 
background-position: -5px -0px;
background-repeat: no-repeat;
width: 90px;
height: 90px;
margin-bottom: 10px;
margin-right: 10px;
}
.age-of-empires-iii :before {
transform: scale(0.75);
}

.category-heroes-of-the-storm .entry-title:before, .heroes-of-the-storm a:before {
float: left;
content: "";
background: url("https://www.ashenglowgaming.com/wp-content/uploads/2017/12/category-game-icons.png");
background-position: -100px -190px;
background-repeat: no-repeat;
width: 90px;
height: 90px;
margin-bottom: 10px;
margin-right: 10px;
}

.heroes-of-the-storm :before {
transform: scale(0.75);
}

.category-pubg .entry-title:before, .pubg a:before{
float: left;
content: "";
background: url("https://www.ashenglowgaming.com/wp-content/uploads/2017/12/category-game-icons.png");
background-position: -5px -95px;
background-repeat: no-repeat;
width: 90px;
height: 90px;
margin-bottom: 10px;
margin-right: 10px;
}

.pubg :before{
transform: scale(0.75);
}

.category-stellaris .entry-title:before,
 .stellaris a:before{
float: left;
content: "";
background: url("https://www.ashenglowgaming.com/wp-content/uploads/2017/12/category-game-icons.png"); 
background-position: -5px -285px;
background-repeat: no-repeat;
width: 90px;
height: 90px;
margin-bottom: 10px;
margin-right: 10px;
}

.stellaris :before{
transform: scale(0.75);
}


.category-factorio .entry-title:before, .factorio a:before {
float: left;
content: "";
background: url("https://www.ashenglowgaming.com/wp-content/uploads/2017/12/category-game-icons.png"); 
background-position: -5px -190px;
background-repeat: no-repeat;
width: 90px;
height: 90px;
margin-bottom: 10px;
margin-right: 10px;
}

.factorio :before {
transform: scale(0.75);
}

.category-league-of-legends .entry-title:before, .league-of-legends a:before {
float: left;
content: "";
width: 90px;
height: 90px;
background: url("https://www.ashenglowgaming.com/wp-content/uploads/2017/12/category-game-icons.png");
background-position: -100px -0px;
width: 90px; 
height: 90px; 
background-repeat: no-repeat;
margin-bottom: 10px;
margin-right: 10px;
-webkit-border-radius: 5px 5px 5px 5px;
-moz-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
}

.league-of-legends :before {
transform: scale(0.75);
}

/* styling games list bullets */

.games-list ul {
margin-top: 10px;
margin-left: 0;
margin-bottom: 0;
}

.games-list li {
display: block;
overflow: hidden;
}

【问题讨论】:

    标签: html css list layout vertical-alignment


    【解决方案1】:

    简单的解决方案是在 before 伪元素 中添加一行代码。由于您正在使用背景并转换以缩小图像,这就是它未与顶部对齐的原因。

    您可以使用:

    transform-origin:top
    

    【讨论】:

    • 漂亮而简单,而且有效。先生,谢谢您,祝您新年快乐!已接受解决方案。
    • @ptrcao 没问题,也祝你新年快乐 :)
    猜你喜欢
    • 2013-04-04
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 2017-03-17
    相关资源
    最近更新 更多