如何将每个设备的两个图片链接集中在一起?

问题描述 投票:0回答:2

我的页面结构如下:

<body>
  <a href="...">
    <img src="..." height="160" width="261">
    <img src="..." height="160" width="160">
  </a>
</body>
  • 对于每个设备,将这两张图片准确地放在中间(彼此相邻)的最佳方法是什么?
  • 是否有可能没有额外的div?
  • 请不要让我使用表格

提前致谢

html css position css-position
2个回答
0
投票

在许多方面,你可以实现这一目标。如果你想保持html结构相同,那么你可以定位你的锚标签,然后是50%的水平和垂直间距,并将它推回自己的高度和宽度。

a{
  position: absolute;
  top: 50%; left: 50%; /* push it to vertically & horizontally */
  transform: translate(-50%, -50%); /* push it back of it's own width & height */
}

View the demo


0
投票
     a {
        display: flex;
        width:auto;
     }
© www.soinside.com 2019 - 2024. All rights reserved.