如何让卡片在缩小页面时保持相同的宽高比?

问题描述 投票:0回答:1

我意识到这必须有一个相当简单的解决方案,但我一直被这个问题困扰,而且我似乎无法使其工作。
This photo shows the card when the screen is full (it has the correct ratio)
And this photo shows what happens when i shrink the page (the height and weight change)

有人可以分析我的代码并告诉我错误在哪里或者我该如何修复它吗?提前非常感谢您。

.book {
  position: relative;
  border-radius: 10px;
  max-width: 250px;
  max-height: 380px;
  background-color: whitesmoke;
  box-shadow: 1px 1px 12px rgb(0, 0, 0, .7);
  border: 1px solid rgb(0, 0, 0, .2);
  transform: preserve-3d;
  perspective: 2000px;
  display: flex;
  align-items: left;
  justify-content: center;
  color: #000;
  flex-direction: column;
  margin: 0px;
}
  
.cover {
  top: 0;
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.5s;
  transform-origin: 0;
  box-shadow: 1px 1px 12px rgb(0, 0, 0, .1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cover img {
  width: 100%;
  height: 100%;
  border-radius: 10px;
}

.book:hover .cover {
  transition: all 0.5s;
  transform: rotatey(-80deg);
}

.book-content {
  margin-left: 45px;
  margin-right: 10px;
  padding-top: 10px;
}

.book p {
  font-size: 15px;
}

.book p strong {
  font-size: 16px;
}

.book h3 {
  line-height: 15px;
  margin-left: 0;
}

.book-section {
  display: flex;
  justify-content: center;
  align-items: center;
  background: white;
  padding: 30px;
  border-radius: 5px;
  margin-bottom: 10px;
  height: 100%;
}
Wait for the cover image to appear, then hover over it.

<div class="book-section">

  <div class="book">

    <div class="book-content">

      <h3>The Favourite</h3>

      <p><strong>Director:</strong> Yorgos Lanthimos
      <br><strong>Writers:</strong> Tony McNamara & Deborah Davis
      <br><strong>Cast:</strong> Emma Stone, Olivia Colman, Rachel Weisz, Nicholas Hoult...</p>

      <p><strong>Synopsis:</strong> England, early 18th century. The close relationship between Queen Anne and Sarah Churchill is threatened by the arrival of Sarah's cousin, Abigail Hill, resulting in a bitter rivalry between the two cousins to be the Queen's favourite.</p>

    </div>

    <div class="cover">
      <img src="https://picsum.photos/210/297">
    </div>

  </div>

</div>

html css responsive-design
1个回答
0
投票

一个简单的修复方法是向图像添加

object-fit: cover
样式。

© www.soinside.com 2019 - 2024. All rights reserved.