仅垂直对齐一种类型的内容
我一直在尝试制作自己的链接,但是我正在努力在内容的位置上挣扎,我想让我的文本固定在中间,然后根据屏幕的大小更改图标的位置
img {
width: 5em;
}
ul {
display: flex;
flex-direction: column;
align-items: center;
}
li {
border: 0.15em solid white;
border-radius: 5em;
display: flex;
align-items: center;
width: 21rem;
margin-bottom: 0.5rem;
justify-content: space-evenly;
}
a {
text-decoration: none;
color: white;
}
<main>
<ul>
<a href="#" target="_blank">
<li>
<img src="./img/last.fm.png" alt="Last.fm">
<p>Last.fm</p>
</li>
</a>
<a href="#" target="_blank">
<li>
<img src="./img/MyAnimeList.png" alt="MyAnimeList">
<p>MyAnimeList</p>
</li>
</a>
<a href="#" target="_blank">
<li>
<img src="./img/Backloggd.png" alt="Backloggd">
<p>Backloggd</p>
</li>
</a>
<a href="#" target="_blank">
<li>
<img src="./img/Letterboxd.png" alt="Letterboxd">
<p>Letterboxd</p>
</li>
</a>
<a href="#" target="_blank">
<li>
<img src="./img/MyDramaList.png" alt="MyDramaList">
<p>MyDramaList</p>
</li>
</a>
<a href="#" target="_blank">
<li>
<img src="./img/Serializd.png" alt="Serializd">
<p>Serializd</p>
</li>
</a>
</ul>
</main>
我将留下两个图像:页面的外观: https://i.sstatic.net/5ykaq .png
以及我希望它如何:
https://i.sstatic.net/ylmu8.png ://i.sstatic.net/lq2xy.png“ rel =“ nofollow noreferrer”> https://i.sstatic.net/lq2xy.png
I've been trying to make my own linktree, but i'm struggling with the positions of my content, I want to let my text fixed on the center and just change the position of the icon according to the size of the screen
img {
width: 5em;
}
ul {
display: flex;
flex-direction: column;
align-items: center;
}
li {
border: 0.15em solid white;
border-radius: 5em;
display: flex;
align-items: center;
width: 21rem;
margin-bottom: 0.5rem;
justify-content: space-evenly;
}
a {
text-decoration: none;
color: white;
}
<main>
<ul>
<a href="#" target="_blank">
<li>
<img src="./img/last.fm.png" alt="Last.fm">
<p>Last.fm</p>
</li>
</a>
<a href="#" target="_blank">
<li>
<img src="./img/MyAnimeList.png" alt="MyAnimeList">
<p>MyAnimeList</p>
</li>
</a>
<a href="#" target="_blank">
<li>
<img src="./img/Backloggd.png" alt="Backloggd">
<p>Backloggd</p>
</li>
</a>
<a href="#" target="_blank">
<li>
<img src="./img/Letterboxd.png" alt="Letterboxd">
<p>Letterboxd</p>
</li>
</a>
<a href="#" target="_blank">
<li>
<img src="./img/MyDramaList.png" alt="MyDramaList">
<p>MyDramaList</p>
</li>
</a>
<a href="#" target="_blank">
<li>
<img src="./img/Serializd.png" alt="Serializd">
<p>Serializd</p>
</li>
</a>
</ul>
</main>
I'll leave two images: how the page looks like: https://i.sstatic.net/5yKAQ.png
and how I want it to be:
https://i.sstatic.net/YLMU8.png and https://i.sstatic.net/LQ2xY.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种可能的解决方案 - 将标签保持为中心,并使用绝对将
其添加到现有样式中
One possible solution - Keep label centered and use absolute for img
add these to your existing styles
主要问题:您有一个静态
宽度:21EM;
在主父和内容上定义的超过该宽度。需要定义孩子的宽度。而不是
width:21EM
,请根据最多的内容找到width
,如果您有类似的DIVS。我发现250px
是基于最长文本的好地方。接下来,定义孩子的宽度。由于您只有两个孩子,每个
li
,我发现li&gt;* {width:50%;}
最好是最好的,因此每个人都占一半。最后,一旦完成此操作,您将拥有类似于 this 的东西。我更喜欢使用
填充
从这里实现间距。另外,如果您喜欢左右的文本合理性,则可以使用GAP
或保证金
替换text-align:center;
。这都是个人偏爱。Main problem: you have a static
width: 21em;
defined on the main parent and content exceeding that width. Need children width defined.Instead of a
width: 21em
, find awidth
based on the most amount of content if you have similar divs. I found that250px
was a good spot based on the longest amount of text.Next, define the children's width. Since you only have two children for each
li
I figuredli>* { width: 50%;}
would be best so they each take up half.Finally, once you have done this you will have something that looks similar to this. I prefer using
padding
to achieve spacing from here. Also, if you like your text justified either left or right so you can usegap
ormargin
to replacetext-align: center;
. That is all personal preference.