【问题标题】:Two equal columns with image that crops from the right - CSS两个相等的列,图像从右侧裁剪 - CSS
【发布时间】:2016-05-26 15:05:15
【问题描述】:

我正在创建一个两列等宽的部分,使用它在左列/部分中有一个图像,我想在屏幕调整大小时从右侧裁剪。

如果右列文本中的文本最终大于图像大小,我想修复图像的高度(在左侧),以及拉伸元素(并保持背景颜色)。

我已经尝试过“普通”css 以及带有拉伸和 flex-grow 的 flexbox,但我无法让它工作。

我不知道如何让 a) 尺寸正常工作或 b) 让它从侧面裁剪

<div class="section">
 <div class="image">
   <img src="http://xxx.jpg">
  </div>
  <div class="text">
   text_abc
  </div>
</div>

这不起作用:

.section {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: centre;
}

.image {
  background-color: #f9f6ec;
   width: 428px;
   flex-grow: 1;
 }

 .text {
   font-size: 1.25em;
   padding: 31px;
   background-color: #f9f6ec;
   flex-grow: 1;
 }

也没有:

.section {
  height: 100%;
}

.image {
  background-color: #f9f6ec;
  width: 50%;
  float: left;
}

.text {
  font-size: 1.25em;
  padding: 31px;
  background-color: #f9f6ec;
  width: 50%;
  float: right;
}

【问题讨论】:

    标签: html css flexbox


    【解决方案1】:

    据我从你的问题中了解到,你想要这样的东西:

    .section
    {
      display: flex;
      width: 500px;
      height: 500px;
      border: 1px dotted black;
    }
    
    .image
    {
      flex: 1;
      background-color: #f9f6ec;
      background-image: url('http://lorempixel.com/image_output/nightlife-q-c-640-480-5.jpg');
      background-position: center center;
    }
    
    .text
    {
      flex: 1;
       font-size: 1.25em;
       background-color: #f9f6ec;
    }
    <div class="section">
     <div class="image"></div>
      <div class="text">
       text_abc
      </div>
    </div>

    您可以使用background-sizebackground-position 任意裁剪图像

    【讨论】:

    • 谢谢。我希望该部分是全宽的,但我想我可以在那里去掉“宽度”。另外我不知道 URL 背景图像,因为我在 html 中调用图像
    猜你喜欢
    • 2019-03-12
    • 1970-01-01
    • 2023-02-05
    • 1970-01-01
    • 2013-08-28
    • 1970-01-01
    • 1970-01-01
    • 2012-09-29
    • 2013-01-13
    相关资源
    最近更新 更多