仅垂直对齐一种类型的内容

发布于 2025-02-03 01:11:09 字数 2154 浏览 2 评论 0原文

我一直在尝试制作自己的链接,但是我正在努力在内容的位置上挣扎,我想让我的文本固定在中间,然后根据屏幕的大小更改图标的位置

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满天都是小星星 2025-02-10 01:11:09
一种可能的解决方案 - 将标签保持为中心,并使用绝对将

其添加到现有样式中

img {
  ...
  position: absolute;
  left: 0; // Change this on screen size with media query
}

li {
   ... 
   position: relative;
   justify-content: center;
}
One possible solution - Keep label centered and use absolute for img

add these to your existing styles

img {
  ...
  position: absolute;
  left: 0; // Change this on screen size with media query
}

li {
   ... 
   position: relative;
   justify-content: center;
}
So要识趣 2025-02-10 01:11:09

主要问题:您有一个静态宽度:21EM;在主父和内容上定义的超过该宽度。需要定义孩子的宽度。

而不是width:21EM,请根据最多的内容找到width,如果您有类似的DIVS。我发现250px是基于最长文本的好地方。

接下来,定义孩子的宽度。由于您只有两个孩子,每个li,我发现li&gt;* {width:50%;}最好是最好的,因此每个人都占一半。

最后,一旦完成此操作,您将拥有类似于 this 的东西。我更喜欢使用填充从这里实现间距。另外,如果您喜欢左右的文本合理性,则可以使用GAP保证金替换text-align:center;。这都是个人偏爱。

body {
  background-color: #414042;
}

img {
  max-width: 100%;
  border-radius: 2em;
}

ul {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

li {
  display: flex;
  align-items: center;
  gap: 35px;
  justify-content: space-evenly;
  padding: 10px 1.5em;
}

li>* {
  width: 50%;
}

a {
  width: 250px;
  border: 0.15em solid white;
  border-radius: 2em;
  text-decoration: none;
  color: white;
}

h1 {
  color: white;
  text-align: center;
  padding-left: 1em;
}
<main>
  <h1>Title</h1>
  <ul>
    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="Last.fm">
        <p>Last.fm</p>
      </li>
    </a>

    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="MyAnimeList">
        <p>MyAnimeList</p>
      </li>
    </a>

    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="Backloggd">
        <p>Backlogged</p>
      </li>
    </a>

    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="Letterboxd">
        <p>Letterboxed</p>
      </li>
    </a>

    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="MyDramaList">
        <p>MyDramaList</p>
      </li>
    </a>

    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="Serializd">
        <p>Serialized</p>
      </li>
    </a>
  </ul>
</main>

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 a width based on the most amount of content if you have similar divs. I found that 250px 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 figured li>* { 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 use gap or margin to replace text-align: center;. That is all personal preference.

body {
  background-color: #414042;
}

img {
  max-width: 100%;
  border-radius: 2em;
}

ul {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

li {
  display: flex;
  align-items: center;
  gap: 35px;
  justify-content: space-evenly;
  padding: 10px 1.5em;
}

li>* {
  width: 50%;
}

a {
  width: 250px;
  border: 0.15em solid white;
  border-radius: 2em;
  text-decoration: none;
  color: white;
}

h1 {
  color: white;
  text-align: center;
  padding-left: 1em;
}
<main>
  <h1>Title</h1>
  <ul>
    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="Last.fm">
        <p>Last.fm</p>
      </li>
    </a>

    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="MyAnimeList">
        <p>MyAnimeList</p>
      </li>
    </a>

    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="Backloggd">
        <p>Backlogged</p>
      </li>
    </a>

    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="Letterboxd">
        <p>Letterboxed</p>
      </li>
    </a>

    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="MyDramaList">
        <p>MyDramaList</p>
      </li>
    </a>

    <a href="#" target="_blank">
      <li>
        <img src="https://dummyimage.com/50/e1e1e1/000" alt="Serializd">
        <p>Serialized</p>
      </li>
    </a>
  </ul>
</main>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文