【问题标题】:make two elements the same width in CSS在 CSS 中使两个元素的宽度相同
【发布时间】:2023-02-02 19:41:40
【问题描述】:

我在一个链接元素中有两个元素(一个段落和一个 img),我希望段落与 img 的宽度相同,我尝试做display: inline-block; 和其他一些事情,但似乎无法让它工作。谁能帮忙?

<li>
    <a href="https://store.steampowered.com/app/4000/Garrys_Mod/" target="_blank" >
        <img src="/Photos/garrysmod.jpg">
        <p>Garrys Mod is a physics sandbox game in which you can do allmost anything you want, including playing hide and seek, fighting monster, fighting eachother, escape from jail, and much more</p>
    </a>
</li>

【问题讨论】:

  • 你可以给 img,p{width:50%}

标签: html css


【解决方案1】:

只需为 imgp 标签添加一个类,并为它们分配 css width 属性

.pic,.par{
   width:100px;
}
<li>
    <a href="https://store.steampowered.com/app/4000/Garrys_Mod/" target="_blank" >
        <img class="pic" src="/Photos/garrysmod.jpg">
        <p class="par">Garrys Mod is a physics sandbox game in which you can do allmost anything you want, including playing hide and seek, fighting monster, fighting eachother, escape from jail, and much more</p>
    </a>
</li>

【讨论】:

    猜你喜欢
    • 2013-08-14
    • 2014-05-29
    • 2020-09-12
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 2010-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多