duanfeng3879 2016-10-04 18:45
浏览 36
已采纳

大图像,保持右侧内容的大小

I have two sizes of images (vertical and horizontal), they will always be the same size, respectfully. I am trying to create a container that would hold the image but not push the content over and stay a similar height or width. I also dont want to show the image full size so I was thinking about using overflow:hidden. I have attempted this in a JSFiddle seen here but it stretches the container. Any help is appreciated.

<div>
  <span class="mixSpanLeft">
    <a href="somePlace.html"><img src="http://cdn.wallpapersafari.com/26/79/HoFC0h.jpg" /></a>
  </span>
  <span class="mixSpanRight">
    <p>The images will always be on the left and will be only two sizes, 1000x500 or 500x1000. What is the best way to show them if they have alternating sizes?  Should I have completely different styles for them?
    </p>
  </span>
</div>

http://jsfiddle.net/hmjoLmej/4/

  • 写回答

1条回答 默认 最新

  • duanjia9577 2016-10-04 19:27
    关注

    What about something like this.

    I used the more appropriate flexbox instead of float, which gives greater control of the layout.

    The image is added using background, which gives greater control to scale, clip, etc.

    Note, since the p is block element they should not be children of a span (which is inline element), so I updated your markup/CSS with a div

    Updated, showing how you can add the image source in the markup

    .wrapper {
      display: flex;
    }
    
    .mixSpanLeft {
      width: 50%;
      background-color: #abc;
      background-repeat: no-repeat;
      background-position: center top;
      background-size: cover;
    }
    
    .mixSpanLeft a {
      display: inline-block;
      height: 100%;
      width: 100%;
    }
    
    .mixDivRight {
      width: 50%;
      background: #def;
    }
    
    .mixDivRight p {
      padding: 2%;
    }
    <div class="wrapper">
      <span class="mixSpanLeft" style="background-image: url(http://cdn.wallpapersafari.com/26/79/HoFC0h.jpg)">
      <a href="somePlace.html"></a>
      </span>
      <div class="mixDivRight">
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
      </div>
    </div>
    
    <div class="wrapper">
      <span class="mixSpanLeft" style="background-image: url(http://cdn.wallpapersafari.com/29/20/3HE5Mx.jpg)">
      <a href="somePlace.html"></a>
      </span>
      <div class="mixDivRight">
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
      </div>
    </div>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题