gpt4 book ai didi

html - 列表中的图像和文本内联

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

我希望将图像和文本保持内联(彼此相邻)并且在 href 中同时超链接,但每个超链接元素都在一个 2 列列表中,如下所示:

.links {
display: block;
margin: 0 -1em;
overflow: hidden;
padding: 1em 0;

li {
box-sizing: border-box;
float: left;
padding: 1em;
list-style: none;
width: 50%;
&:nth-of-type(2n+1) {
clear: left;
}

.grid-pic{
height:200px;
background-image: url(../images/site/thumbs/boss-holder.png);
background-size:contain;
background-position: center center;
background-repeat:no-repeat;
}

a {
color: $color-secondary;
border:3px solid $color-secondary;
display: block;
font-size: 2em;
@extend %font-semibold;
line-height: 1;
padding: 25% 1em;
position: relative;
text-align: left;
text-decoration: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
} }}
<ul class="links">
<li><a href="#section1"><div class="grid-pic"></div>Text</a></li>
<li><a href="#section2"><div class="grid-pic"></div>Text</a></li>
<li><a href="#section3"><div class="grid-pic"></div>Text</a></li>
<li><a href="#section4"><div class="grid-pic"></div>Text</a></li>
</ul>

It currently looks like this
I'd like it to look like this

我正在使用 this expanding grid pen作为一个框架,如果有帮助的话。我认为是这份 list 让我无法解决问题。

最佳答案

我添加了 display:inline-block;vertical-align:middle; 到你的 .grid-pic class 来放置图像在文本旁边。

.links {
display: block;
margin: 0 -1em;
overflow: hidden;
padding: 1em 0;
}

.links li {
box-sizing: border-box;
float: left;
padding: 1em;
list-style: none;
width: 50%;
&:nth-of-type(2n+1) {
clear: left;
}
}

.links li .grid-pic {
height: 100px;
width: 100px;
background-image: url(http://via.placeholder.com/100x100);
background-size: contain;
background-position: center center;
background-repeat: no-repeat;
display: inline-block;
vertical-align: middle;
margin-right: 10px;
}

.links li a {
color: $color-secondary;
border: 3px solid $color-secondary;
display: block;
font-size: 2em;
@extend %font-semibold;
line-height: 1;
padding: 25% 1em;
position: relative;
text-align: left;
text-decoration: none;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
<ul class="links">
<li>
<a href="#section1">
<div class="grid-pic"></div>Text</a>
</li>
<li>
<a href="#section2">
<div class="grid-pic"></div>Text</a>
</li>
<li>
<a href="#section3">
<div class="grid-pic"></div>Text</a>
</li>
<li>
<a href="#section4">
<div class="grid-pic"></div>Text</a>
</li>
</ul>

关于html - 列表中的图像和文本内联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48314048/

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