代码之家  ›  专栏  ›  技术社区  ›  parsecer

顺风:如何在导航栏父div中调整图像

  •  0
  • parsecer  · 技术社区  · 5 年前

    我有一个简单的标题,我想在其中插入一个配置文件图像。然而,配置文件图像不适合标题,我不知道如何以响应的方式接近它。我不想以任何方式硬核化图像的宽度/高度,而是希望它始终适合页眉的高度,并带有一些填充物。

    我的代码是:

        <div class="flex flex-wrap items-center justify-start
              m-3 p-2 pl-6  ">
          <span class="title-text light-text text-xl">Some Title</span>
          <span class="pl-10">Some link</span>
          <span class="pl-10">Some link</span>
          <span class="pl-10">Some link</span>
          <span class="pl-10">Some link</span>
    
          <div class="rounded">
            <img class= "relative rounded-full border
                  border-gray-100 shadow-sm
             max-w-max   h-full " src="../../assets/dog.jpeg" />
          </div>
        </div>
    

    如果没有图像,它看起来是这样的:

    enter image description here

    但对于图像,它看起来是这样的:

    enter image description here

    但我希望它看起来:

    enter image description here

    我如何利用顺风实现它?

    0 回复  |  直到 5 年前
        1
  •  0
  •   Gildas.Tambo    5 年前

    你可以用 object-fit :cover,请注意,您必须将带和img高度设置为100%。

    .rounded{
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .rounded img {
        height: 100%;
        width: 100%;
        object-fit: cover;
    }
    

    这是你的链接 tailwind-css 意思是你可以使用这个类 object-cover 只有

      <div class="rounded">
        <img class= "object-cover relative rounded-full border
              border-gray-100 shadow-sm
         max-w-max   h-full " src="../../assets/dog.jpeg" />
      </div>
    
        2
  •  0
  •   Darpan Kulkarni    5 年前

    为导航和图像容器提供固定高度,

    <div class="flex flex-wrap items-center justify-start px-4 bg-gray-800 text-white h-20">
      <span class="title-text light-text text-xl">Some Title</span>
      <span class="pl-10">Some link</span>
      <span class="pl-10">Some link</span>
      <span class="pl-10">Some link</span>
      <span class="pl-10">Some link</span>
    
      <div class="h-16 ml-auto">
        <img class= "rounded-full border border-gray-100 shadow-sm h-full" src="../../assets/dog.jpeg" />
      </div>
    </div>