首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >顺风CSS:防止行间距垂直拉伸。

顺风CSS:防止行间距垂直拉伸。
EN

Stack Overflow用户
提问于 2022-03-27 06:40:46
回答 1查看 1.6K关注 0票数 0

下面的HTML有一个左列(图像)和一个右列。

正确的列之间有太多的间距,很可能是因为网格垂直地将项目分散在右边。我不希望在它们之间有任何垂直空间,并使用边距来控制间距。我怎样才能做到这一点?

请注意,第一个网格子是徽标,而不是图像,因为在较小的屏幕上,我希望它出现在图像的顶部。

代码语言:javascript
复制
<div class="lg:grid lg:grid-cols-7 grid-rows-4 items-start lg:gap-x-8 xl:gap-x-16">
  
  <!-- Logo, name and tagline -->
  <div class="lg:col-span-3 lg:col-start-5">
  </div>         

  <!-- Images -->
  <div class="lg:col-span-4 lg:col-start-1 lg:row-span-4 lg:row-start-1">
  </div>        

  <!-- More info -->
  <div class="border-t border-gray-200 lg:col-span-3 lg:col-start-5 pt-10 grow-0">
    <h3 class="text-sm font-medium text-gray-900">More info</h3>
  </div>

  <!-- Contact -->
  <div class="border-t border-gray-200 lg:col-span-3 lg:col-start-5 pt-10 grow-0">
    <h3 class="text-sm font-medium text-gray-900 mb-4">Contact</h3>
  </div>

  <!-- Social -->
  <div class="border-t border-gray-200 lg:col-span-3 lg:col-start-5 pt-10 grow-0">
    <h3 class="text-sm font-medium text-gray-900 mb-4">Social</h3>
  </div>
            
</div>

代码语言:javascript
复制
<script src="https://cdn.tailwindcss.com"></script>

<div class="bg-white">
  <div class="mx-auto py-16 px-4 sm:py-24 sm:px-6 lg:max-w-7xl lg:px-8">
    <div class="lg:grid lg:grid-cols-7 grid-rows-4 items-start lg:gap-x-8 xl:gap-x-16 place-content-start">
      
      <!-- Logo, name and tagline -->
      <div class="lg:col-span-3 lg:col-start-5">
        <div class="flex flex-row">

          <img src="https://images.unsplash.com/photo-1502685104226-ee32379fefbe?ixlib=rb-=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=256&h=256&q=80" alt="" class="h-16 rounded-md">

          <div class="ml-7">
            <h1 class="text-2xl font-extrabold tracking-tight text-gray-900 sm:text-3xl">Mother Cho&#39;s</h1>
          </div>
        </div>
      </div>         

      <!-- Images -->
      <div class="lg:col-span-4 lg:col-start-1 lg:row-span-4 lg:row-start-1 mt-14 sm:mt-16 lg:mt-0">

        <!-- Gallery -->
        <div class="flex flex-col-reverse">
          
          <!-- Image selector -->
          <div class="mt-6 w-full max-w-2xl mx-auto lg:max-w-none">
            <div class="grid grid-cols-4 gap-6" aria-orientation="horizontal" role="tablist">
              
              <button id="tabs-1-tab-1" class="relative h-24 bg-white rounded-md flex items-center justify-center text-sm font-medium uppercase text-gray-900 cursor-pointer hover:bg-gray-50 focus:outline-none focus:ring focus:ring-offset-4 focus:ring-opacity-50" aria-controls="tabs-1-panel-1" role="tab" type="button">
                <span class="sr-only"> Angled view </span>
                <span class="absolute inset-0 rounded-md overflow-hidden">
                  <img src="https://images.unsplash.com/photo-1502685104226-ee32379fefbe?ixlib=rb-=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=256&h=256&q=80" alt="" class="w-full h-full object-center object-cover">
                </span>
                <span class="ring-transparent absolute inset-0 rounded-md ring-2 ring-offset-2 pointer-events-none" aria-hidden="true"></span>
              </button>

              <button id="tabs-1-tab-1" class="relative h-24 bg-white rounded-md flex items-center justify-center text-sm font-medium uppercase text-gray-900 cursor-pointer hover:bg-gray-50 focus:outline-none focus:ring focus:ring-offset-4 focus:ring-opacity-50" aria-controls="tabs-1-panel-1" role="tab" type="button">
                <span class="sr-only"> Angled view </span>
                <span class="absolute inset-0 rounded-md overflow-hidden">
                  <img src="https://images.unsplash.com/photo-1502685104226-ee32379fefbe?ixlib=rb-=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=256&h=256&q=80" alt="" class="w-full h-full object-center object-cover">
                </span>
                <span class="ring-transparent absolute inset-0 rounded-md ring-2 ring-offset-2 pointer-events-none" aria-hidden="true"></span>
              </button>
            </div>
          </div>

          <div class="w-full aspect-w-1 aspect-h-1">            
            <!-- Tab panel, show/hide based on tab state. -->
            <div id="tabs-1-panel-1" aria-labelledby="tabs-1-tab-1" role="tabpanel" tabindex="0">
              <img src="https://images.unsplash.com/photo-1502685104226-ee32379fefbe?ixlib=rb-=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=256&h=256&q=80" alt="Angled front view with bag zipped and handles upright." class="w-full h-full object-center object-cover sm:rounded-lg">
            </div>
          </div>
        </div>        
      </div>


        <div class="border-t border-gray-200 lg:col-span-3 lg:col-start-5 pt-2 grow-0">
          <h3 class="text-sm font-medium text-gray-900">More info</h3>
          <p class="mt-4 text-sm text-gray-500">Taiwanese vegan food</p>
        </div>

      <div class="border-t border-gray-200 lg:col-span-3 lg:col-start-5 grow-0">
        <h3 class="text-sm font-medium text-gray-900 mb-4">Contact</h3>

          <div class="flex items-center space-x-2 my-2">
            <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
              <path stroke-linecap="round" stroke-linejoin="round" d="M16 12a4 4 0 10-8 0 4 4 0 008 0zm0 0v1.5a2.5 2.5 0 005 0V12a9 9 0 10-9 9m4.5-1.206a8.959 8.959 0 01-4.5 1.207" />
            </svg>
            <a href="mailto:info@motherchos.com.au"><span class="text-gray-500 text-sm font-medium">info@motherchos.com.au</span></a>
          </div>

          <div class="flex items-center space-x-2 my-2">
            <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
              <path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9" />
            </svg>
            <a href="https://www.motherchos.com.au"><span class="text-gray-500 text-sm font-medium">https://www.motherchos.com.au</span></a>
          </div>



      </div>


        <div class="border-t border-gray-200 lg:col-span-3 lg:col-start-5 pt-2 grow-0">
          <h3 class="text-sm font-medium text-gray-900">Social</h3>
          <ul role="list" class="flex items-center space-x-6 mt-4">
            

              <li>
                <a href="https://www.instagram.com/mothercho" class="flex items-center justify-center w-6 h-6 text-gray-400 hover:text-gray-500">
                  <span class="sr-only">Visit on Instagram</span>
                  <svg class="w-6 h-6" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
                    <path fill-rule="evenodd" d="M12.315 2c2.43 0 2.784.013 3.808.06 1.064.049 1.791.218 2.427.465a4.902 4.902 0 011.772 1.153 4.902 4.902 0 011.153 1.772c.247.636.416 1.363.465 2.427.048 1.067.06 1.407.06 4.123v.08c0 2.643-.012 2.987-.06 4.043-.049 1.064-.218 1.791-.465 2.427a4.902 4.902 0 01-1.153 1.772 4.902 4.902 0 01-1.772 1.153c-.636.247-1.363.416-2.427.465-1.067.048-1.407.06-4.123.06h-.08c-2.643 0-2.987-.012-4.043-.06-1.064-.049-1.791-.218-2.427-.465a4.902 4.902 0 01-1.772-1.153 4.902 4.902 0 01-1.153-1.772c-.247-.636-.416-1.363-.465-2.427-.047-1.024-.06-1.379-.06-3.808v-.63c0-2.43.013-2.784.06-3.808.049-1.064.218-1.791.465-2.427a4.902 4.902 0 011.153-1.772A4.902 4.902 0 015.45 2.525c.636-.247 1.363-.416 2.427-.465C8.901 2.013 9.256 2 11.685 2h.63zm-.081 1.802h-.468c-2.456 0-2.784.011-3.807.058-.975.045-1.504.207-1.857.344-.467.182-.8.398-1.15.748-.35.35-.566.683-.748 1.15-.137.353-.3.882-.344 1.857-.047 1.023-.058 1.351-.058 3.807v.468c0 2.456.011 2.784.058 3.807.045.975.207 1.504.344 1.857.182.466.399.8.748 1.15.35.35.683.566 1.15.748.353.137.882.3 1.857.344 1.054.048 1.37.058 4.041.058h.08c2.597 0 2.917-.01 3.96-.058.976-.045 1.505-.207 1.858-.344.466-.182.8-.398 1.15-.748.35-.35.566-.683.748-1.15.137-.353.3-.882.344-1.857.048-1.055.058-1.37.058-4.041v-.08c0-2.597-.01-2.917-.058-3.96-.045-.976-.207-1.505-.344-1.858a3.097 3.097 0 00-.748-1.15 3.098 3.098 0 00-1.15-.748c-.353-.137-.882-.3-1.857-.344-1.023-.047-1.351-.058-3.807-.058zM12 6.865a5.135 5.135 0 110 10.27 5.135 5.135 0 010-10.27zm0 1.802a3.333 3.333 0 100 6.666 3.333 3.333 0 000-6.666zm5.338-3.205a1.2 1.2 0 110 2.4 1.2 1.2 0 010-2.4z" clip-rule="evenodd" />
                  </svg>
                </a>
              </li>
          </ul>
        </div>

                
    </div>
  </div>
</div>

EN

回答 1

Stack Overflow用户

发布于 2022-03-28 05:32:41

更新后的答案,OP上传完整的代码。

您的代码有许多不必要的样式。左边底部的两幅图片导致垂直间距(如果您删除它们,您可以看到),我没有在您的代码中得到更正,所以我已经编写了我的代码来构建您的页面。我用简单的flex来构建页面。

这是我使用flex时使用的基本布局。

代码语言:javascript
复制
<script src="https://cdn.tailwindcss.com"></script>

<div class="flex flex-row">
  <div class="flex flex-col bg-red-300 p-2">Left
    <div class="bg-green-200 m-2">Big Pic</div>
    <div class="flex flex-row m-2">
      <div class="bg-blue-200">photo-1</div>
      <div class="bg-blue-400">photo-2</div>
    </div>
  </div>
  <div class="flex flex-col bg-red-300">Right
    <div class="flex flex-row ">
      <div class="bg-pink-200">photo-1</div>
      <div class="bg-pink-400">Heading</div>
    </div> 
    <div class="bg-yellow-200">More info</div>
    <div class="bg-orange-200">Contact</div>
    <div class="bg-amber-500">Social></div>
  </div>
</div>

现在,这是使用flex时页面的样子。

代码语言:javascript
复制
<script src="https://cdn.tailwindcss.com"></script>


<div class="flex flex-row">
  <div class="flex flex-col bg-white p-2">
    <div class="w-full aspect-w-1 aspect-h-1">
      <div id="tabs-1-panel-1" aria-labelledby="tabs-1-tab-1" role="tabpanel" tabindex="0">
        <img src="https://images.unsplash.com/photo-1502685104226-ee32379fefbe?ixlib=rb-=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=256&h=256&q=80" alt="Angled front view with bag zipped and handles upright." class="w-full h-full object-center object-cover sm:rounded-lg" />
      </div>
    </div>
    <div class="flex flex-row m-2 mt-6 w-full space-x-4 max-w-2xl mx-auto lg:max-w-none">
      <div class="bg-blue-200">
        <button id="tabs-1-tab-1" class="relative h-16 w-24 bg-green-200 rounded-md flex items-center justify-center text-sm font-medium uppercase text-gray-900 cursor-pointer hover:bg-gray-50 focus:outline-none focus:ring focus:ring-offset-4 focus:ring-opacity-50" aria-controls="tabs-1-panel-1" role="tab" type="button">
          <span class="absolute inset-0 rounded-md overflow-hidden">
            <img src="https://images.unsplash.com/photo-1502685104226-ee32379fefbe?ixlib=rb-=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=256&h=256&q=80" alt="" class="w-full h-full object-center object-cover" />
          </span>
          <span class="ring-transparent absolute inset-0 rounded-md ring-2 ring-offset-2 pointer-events-none" aria-hidden="true"></span>
        </button>
      </div>
      <div class="bg-blue-400">
        <button id="tabs-1-tab-1" class="relative w-24 h-16 bg-white rounded-md flex items-center justify-center text-sm font-medium uppercase text-gray-900 cursor-pointer hover:bg-gray-50 focus:outline-none focus:ring focus:ring-offset-4 focus:ring-opacity-50" aria-controls="tabs-1-panel-1" role="tab" type="button">
          <span class="absolute inset-0 rounded-md overflow-hidden">
            <img src="https://images.unsplash.com/photo-1502685104226-ee32379fefbe?ixlib=rb-=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=256&h=256&q=80" alt="" class="w-full h-full object-center object-cover" />
          </span>
          <span class="ring-transparent absolute inset-0 rounded-md ring-2 ring-offset-2 pointer-events-none" aria-hidden="true"></span>
        </button>
      </div>
    </div>
  </div>
  <div class="flex flex-col bg-white p-2">
    <div class="flex flex-row">
      <img src="https://images.unsplash.com/photo-1502685104226-ee32379fefbe?ixlib=rb-=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=256&h=256&q=80" alt="" class="h-16 rounded-md" />

      <div class="ml-7">
        <h1 class="text-2xl font-extrabold tracking-tight text-gray-900 sm:text-3xl">Mother Cho&#39;s</h1>
      </div>
    </div>
    <div class="bg-white mt-3">
      <div class="border-t border-gray-200 lg:col-span-3 lg:col-start-5 pt-2 grow-0">
        <h3 class="text-sm font-medium text-gray-900">More info</h3>
        <p class="mb-3 text-sm text-gray-500">Taiwanese vegan food</p>
      </div>
    </div>
    <div class="bg-white">
      <div class="border-t border-gray-200 lg:col-span-3 lg:col-start-5 grow-0 pt-4">
        <h3 class="text-sm font-medium text-gray-900">Contact</h3>

        <div class="flex items-center space-x-2 my-1">
          <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
            <path stroke-linecap="round" stroke-linejoin="round" d="M16 12a4 4 0 10-8 0 4 4 0 008 0zm0 0v1.5a2.5 2.5 0 005 0V12a9 9 0 10-9 9m4.5-1.206a8.959 8.959 0 01-4.5 1.207" />
          </svg>
          <a href="mailto:info@motherchos.com.au"><span class="text-gray-500 text-sm font-medium">info@motherchos.com.au</span></a>
        </div>

        <div class="flex items-center space-x-2 my-1">
          <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
            <path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9" />
          </svg>
          <a href="https://www.motherchos.com.au"><span class="text-gray-500 text-sm font-medium">https://www.motherchos.com.au</span></a>
        </div>
      </div>
    </div>
    <div class="bg-white mt-3">
      <div class="border-t border-gray-200 lg:col-span-3 lg:col-start-5 pt-2 grow-0">
        <h3 class="text-sm font-medium text-gray-900">Social</h3>
        <ul role="list" class="flex items-center space-x-6 mt-2">
          <li>
            <a href="https://www.instagram.com/mothercho" class="flex items-center justify-center w-6 h-6 text-gray-400 hover:text-gray-500">
              <span class="sr-only">Visit on Instagram</span>
              <svg class="w-6 h-6" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
                <path fill-rule="evenodd" d="M12.315 2c2.43 0 2.784.013 3.808.06 1.064.049 1.791.218 2.427.465a4.902 4.902 0 011.772 1.153 4.902 4.902 0 011.153 1.772c.247.636.416 1.363.465 2.427.048 1.067.06 1.407.06 4.123v.08c0 2.643-.012 2.987-.06 4.043-.049 1.064-.218 1.791-.465 2.427a4.902 4.902 0 01-1.153 1.772 4.902 4.902 0 01-1.772 1.153c-.636.247-1.363.416-2.427.465-1.067.048-1.407.06-4.123.06h-.08c-2.643 0-2.987-.012-4.043-.06-1.064-.049-1.791-.218-2.427-.465a4.902 4.902 0 01-1.772-1.153 4.902 4.902 0 01-1.153-1.772c-.247-.636-.416-1.363-.465-2.427-.047-1.024-.06-1.379-.06-3.808v-.63c0-2.43.013-2.784.06-3.808.049-1.064.218-1.791.465-2.427a4.902 4.902 0 011.153-1.772A4.902 4.902 0 015.45 2.525c.636-.247 1.363-.416 2.427-.465C8.901 2.013 9.256 2 11.685 2h.63zm-.081 1.802h-.468c-2.456 0-2.784.011-3.807.058-.975.045-1.504.207-1.857.344-.467.182-.8.398-1.15.748-.35.35-.566.683-.748 1.15-.137.353-.3.882-.344 1.857-.047 1.023-.058 1.351-.058 3.807v.468c0 2.456.011 2.784.058 3.807.045.975.207 1.504.344 1.857.182.466.399.8.748 1.15.35.35.683.566 1.15.748.353.137.882.3 1.857.344 1.054.048 1.37.058 4.041.058h.08c2.597 0 2.917-.01 3.96-.058.976-.045 1.505-.207 1.858-.344.466-.182.8-.398 1.15-.748.35-.35.566-.683.748-1.15.137-.353.3-.882.344-1.857.048-1.055.058-1.37.058-4.041v-.08c0-2.597-.01-2.917-.058-3.96-.045-.976-.207-1.505-.344-1.858a3.097 3.097 0 00-.748-1.15 3.098 3.098 0 00-1.15-.748c-.353-.137-.882-.3-1.857-.344-1.023-.047-1.351-.058-3.807-.058zM12 6.865a5.135 5.135 0 110 10.27 5.135 5.135 0 010-10.27zm0 1.802a3.333 3.333 0 100 6.666 3.333 3.333 0 000-6.666zm5.338-3.205a1.2 1.2 0 110 2.4 1.2 1.2 0 010-2.4z" clip-rule="evenodd" />
              </svg>
            </a>
          </li>
        </ul>
      </div>
    </div>
  </div>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71634230

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档