【问题标题】:2 images in row responsive2 行响应式图像
【发布时间】:2017-10-07 16:49:01
【问题描述】:

我想在页面中心连续制作 2 张图像。 我的图像大小不同,但我希望它们位于中心并位于同一行。 首先,我尝试在框架 7 中使用 row 和 col-50

<div class="row">
    <div class="col-50"><img src="1.jpg"></div>
    <div class="col-50"><img src="2.jpg"></div>
</div>   

但它不能正常工作,然后我以这种方式使用 css 样式手动完成

<div style="width:100%;display:inline-block;">
    <div style="width:50%;float:left">
        <img src="1.jpg" style="margin:auto;display:block" />
    </div>
    <div style="width:50%;float:left">
        <img src="2.jpg" style="margin:0 auto;display:block;"/>
        <span style="font-size: 40px; color: #4c4c4c; font-family: Calibri;">Logo company</span>
        <br />
        <span style="font-size: 12px; color: #4c4c4c; font-family: 'Helvetica Neue',sans-serif;">write here your brand</span>
    </div>
</div>

【问题讨论】:

    标签: html image css css-float


    【解决方案1】:

    请使用此代码并检查 sn-p 这是如何工作的。希望对你有帮助。

    <style>
    .row img {
       display:inline-block;
    }
    .row{
      text-align:center;
    }
    </style>
    
    <div class="row">
    <img src="1.jpg">
    <img src="2.jpg">
    </div>

    谢谢,

    【讨论】:

    • 感谢您的宝贵时间,但它不起作用。不要忘记在第二张照片(左图)中我在照片后面有文字,所以我需要把它放到 div 中。
    【解决方案2】:

    你也可以使用 flexbox,像这样

    .row {
      display: flex;
      align-items: center;
      justify-content: center;
      
    }
    <body style="background-color: #f6f6f6">
    
    <div dir="ltr" class="page-content center" style="min-width: 400px; min-height: 400px; margin: auto; width: 58%; padding: 20px;">
    
        <!-- Logo -->
        <!--<p style="text-align: center;">-->
            <div class="row">
                <div class="col-50">
                 <img src="http://i64.tinypic.com/2ni7hjk.jpg" />
                </div>
                <div class="col-50">
                    <img src="http://i68.tinypic.com/dunp0.png"/>
                    <span style="font-size: 40px; color: #4c4c4c; font-family: Calibri;">logoeri</span>
                    <br />
                    <span style="font-size: 12px; color: #4c4c4c; font-family: 'Helvetica Neue',sans-serif;">logo company is here</span>
                </div>
             </div>
    
        <!-- Header -->
    
        <div id="Header" style="font-family: 'Helvetica Neue',sans-serif; text-align: center; font-size: 30px; padding: 20px; color: white; background-color: #3eb780">
        the header is here
        </div>
    
    
        <!-- Center Container -->
    
        <div style="font-family: 'Helvetica Neue',sans-serif; background: white;padding: 20px; font-size: 14px; font-family: Arial; direction: ltr; text-align: left;">           <p>
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    
    Why do we use it?
    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
    
    
        </p>
    
    
    
    
    
            <!-- Footer -->
            <div style="text-align: center; color: #a2a2a2">
                <div style="width: 90%; margin: auto; padding: 20px;">
                    Do not reply<br />
    
    
                </div>
            </div>
            </div>
        </div>

    【讨论】:

    • 这很奇怪,因为我可以正确地看到它@AdirZoari
    • 再看我的帖子,我编辑了它并发布了snipcode
    • 我更改了代码,这是您要找的吗? @AdirZoari 这一行是额外的
    • 如果您使用的是 Visual Studio,请检查此堆栈stackoverflow.com/questions/24124198/…@AdirZoari
    • 你知道另一种更新视觉工作室的方法吗?
    【解决方案3】:

    使用 display flex 和行内的相关容器,您将能够在图像内添加文本。

    .row{
      width: 50%;
      display: flex;
      
      justify-content: center;
      margin: 0 auto;
    }
    .col-50{
      width: 48.5%;
      text-align: center;
    }
    img{max-width: 100%;}
    
    .rel{position:relative;}
    .rel p{position:absolute; top:0; left:0; right:0;}
    <div class="row">
      <div class="col-50">
        <img src="https://placehold.it/200x200"></div>
      <div class="col-50">
        <div class="rel">
         <img src="https://placehold.it/200x300">
          <p>TEXT INSIDE THE IMAGE</p>
        </div>
      </div>
    </div>

    JSFiddle

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签