【问题标题】:How to center image gallery with text in Shopify without making the images smaller (HTML, CSS)如何在 Shopify 中以文本居中图片库而不使图片变小(HTML、CSS)
【发布时间】:2023-03-18 21:06:01
【问题描述】:

我正在尝试在不减小图像大小的情况下将我的图片库居中。我尝试使用类似问题中的一些解决方案,但它们需要使图像超小。有没有办法保持我的图像大小,让我的图像并排,让整个东西居中? :D 提前非常感谢!

这是我的代码:

<style>

div.gallery {
margin: 5px;
border: 0px solid #ccc;
float: left;
text-align: center;
width: 330px;
}

div.gallery:hover {
border: 0px solid #777;
}

div.gallery img {
width: 100%;
height: auto;
}

div.desc {
padding: 9px;
text-align: center;
display: block; 
margin: 0 auto;
}
</style>

<div id="container">
<div class="gallery">
<a target="_blank" href="img.jpg">
</a><a target="_blank" href="img.jpg"><img src="img.jpg" alt="Select Your Flavors" width="600" height="400">
</a>
<div class="desc"><h3>Choose Your Flavors</h3></div>
<div class="desc">
<p>Text</p>
<div class="center-section"><a class="btn button" href="https://completeats.myshopify.com/collections/shop">Find Your Box</a></div>
</div>
<p></p>
</div>


<div class="gallery">
<a target="_blank" href="img.jpg">
</a><a target="_blank" href="img.jpg"><img src="img" alt="Get Your Box" width="600" height="400">
</a>
<div class="desc"><h3>Get Your Box</h3></div>
<div class="center-section">
<a class="btn button" href="https://completeats.myshopify.com/collections/shop">Find Your Box</a><p></p>
</div>
</div>
<p></p>
</div>


<div class="gallery">
<a target="_blank" href="img.jpg">
</a><a target="_blank" href="img.jpg"><img src="img" width="600" height="400">
</a>
<div class="desc"><h3>text</h3></div>
<div class="center-section"><a class="btn button" href="">Shop Now</a></div>
</div>
<p></p>
</div></div>

【问题讨论】:

    标签: html css shopify


    【解决方案1】:

    我添加 "cover" 你的 "gallery" div 和 "gallery-wrapper" 类并添加 css 用于中心图像对齐。

    .gallery-wrapper{
      display:table;
      margin:0 auto;
    }
    <style>
    div.gallery {
    margin: 5px;
    border: 0px solid #ccc;
    float: left;
    text-align: center;
    width: 330px;
    }
    div.gallery:hover {
    border: 0px solid #777;
    }
    div.gallery img {
    width: 100%;
    height: auto;
    }
    div.desc {
    padding: 9px;
    text-align: center;
    display: block;
    margin: 0 auto;
    }
    </style>
    <div id="container">
    <div class="gallery-wrapper">   
        <div class="gallery">
            <a target="_blank" href="img.jpg">
                </a><a target="_blank" href="img.jpg"><img src="https://images.unsplash.com/photo-1469317835793-6d02c2392778?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1352&q=80" alt="Select Your Flavors" width="600" height="400">
            </a>
            <div class="desc"><h3>Choose Your Flavors</h3></div>
            <div class="desc">
                <p>Text</p>
                <div class="center-section"><a class="btn button" href="https://completeats.myshopify.com/collections/shop">Find Your Box</a></div>
            </div>
            
        </div>
        <div class="gallery">
            <a target="_blank" href="img.jpg">
                </a><a target="_blank" href="img.jpg"><img src="https://images.unsplash.com/photo-1469317835793-6d02c2392778?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1352&q=80" alt="Get Your Box" width="600" height="400">
            </a>
            <div class="desc"><h3>Get Your Box</h3></div>
            <div class="center-section">
                <a class="btn button" href="https://completeats.myshopify.com/collections/shop">Find Your Box</a><p></p>
            </div>
        </div>
        
    
        <div class="gallery">
        <a target="_blank" href="img.jpg">
            </a><a target="_blank" href="img.jpg"><img src="https://images.unsplash.com/photo-1469317835793-6d02c2392778?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1352&q=80" width="600" height="400">
            </a>
            <div class="desc"><h3>text</h3></div>
            <div class="center-section"><a class="btn button" href="">Shop Now</a></div>
        </div>
        
    </div>

    【讨论】:

    • 感谢您的帮助萨蒂什。但是,这似乎并不能解决我的问题。可能我描述的不够好。我试图让画廊位于我网站页面的顶部中心。我尝试了gallery-wrapper,但没有改变。
    • 您需要发布当前页面的工作示例或 URL。
    • @Onkar 我在上面链接了它
    • @JudithPrugger 很抱歉,但链接返回 404
    【解决方案2】:

    像这样:https://i.ibb.co/pzz0MxF/846c4b24-6934-4447-82c1-a25b11ea581c.png

    注意:始终使用类名作为部分名称,如“club-works”,以获得良好的 CSS 理解

    你必须在这个类中添加css

    .custom-html .custom-html__code {
      display: table;
      margin: 0 auto;
    }
    

    【讨论】:

    • 天哪。谢谢!我花了很多时间找出问题所在! :D
    猜你喜欢
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2022-10-08
    • 2015-12-15
    • 1970-01-01
    • 2022-01-25
    • 2023-01-27
    相关资源
    最近更新 更多