html - 淡化一个 div 溢出到相邻的 div

标签 html css user-interface responsive-design

我正在尝试在以下位置创建卡片 UI:https://codepen.io/sarimabbas/pen/qjZYvr

.book_left {
  width: 35%;
  height: 300px;
  float: left;
  overflow-x: hidden;
  background: transparent;
}
.book_left img {
  width: auto;
  height: 100%;
  border-radius: 10px 0 0 10px;
  -webkit-border-radius: 10px 0 0 10px;
  -moz-border-radius: 10px 0 0 10px;
  position: relative;
}
.book_right {
  width: 65%;
  height: 300px;
  float: left;
  background: #000000;
  border-radius: 0 10px 10px 0;
  -webkit-border-radius: 0 10px 10px 0;
  -moz-border-radius: 0 10px 10px 0;
}

我遇到的问题是卡片的左侧(包含图像)会溢出到右侧。而不是隐藏这个溢出,我想把它混合到右边的 div 中,这样文本就不会被隐藏并且可以阅读。

这样的事情可能吗?我曾尝试研究 float 、背景图像淡入淡出和 div 的组合,但没有成功。

在相关说明中,要使此类卡片具有响应性,需要采取哪些步骤?

最佳答案

我不确定我是否完全理解,但使用下面的代码可以提供透明度,允许看到溢出图像顶部的文本。不能选择全黑背景。

.book_right {
  width: 65%;
  height: 300px;
  float: left;
  background: rgba(0,0,0, 0.5);
  border-radius: 0 10px 10px 0;
  -webkit-border-radius: 0 10px 10px 0;
  -moz-border-radius: 0 10px 10px 0;
  position: relative;
}

关于响应能力,我会选择 flexbox 而不是 float ,并使用百分比而不是像素来确定宽度和高度。

@import url(https://fonts.googleapis.com/css?family=Montserrat:400,700);
@import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
.book {
  width: 450px;
  height: 300px;
  background: transparent;
  position: static;
  left: 0;
  right: 0;
  margin: auto;
  top: 0;
  bottom: 0;
  border-radius: 10px;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  box-shadow: 0 2px 1px 0 #777;
}
.book_left {
  width: 35%;
  height: 300px;
  float: left;
  overflow-x: visible;
  background: transparent;
}
.book_left img {
  width: auto;
  height: 100%;
  border-radius: 10px 0 0 10px;
  -webkit-border-radius: 10px 0 0 10px;
  -moz-border-radius: 10px 0 0 10px;
  position: relative;
}
.book_right {
  width: 65%;
  height: 300px;
  float: left;
  background: rgba(0,0,0, 0.5);
  border-radius: 0 10px 10px 0;
  -webkit-border-radius: 0 10px 10px 0;
  -moz-border-radius: 0 10px 10px 0;
  position: relative;
}
.book_right h1 {
  color: white;
  font-family: 'Montserrat', sans-serif;
  font-weight: 400;
  text-align: left;
  font-size: 20px;
  margin: 30px 0 0 0;
  padding: 0 0 0 40px;
  letter-spacing: 1px;
}
.book_right_details ul {
  list-style-type: none;
  padding: 0 0 0 40px;
  margin: 10px 0 0 0;
}
.book_right_details ul li {
  display: inline;
  color: #e3e3e3;
  font-family: 'Montserrat', sans-serif;
  font-weight: 400;
  font-size: 14px;
  padding: 0 40px 0 0;
}
.book_right_blurb p {
  color: white;
  font-family: 'Montserrat', sans-serif;
  font-size: 12px;
  padding: 0 40px 0 40px;
  letter-spacing: 1px;
  margin: 10px 0 10px 0;
  line-height: 20px;
}
.book_right_blurb a {
  text-decoration: none;
  font-family: 'Montserrat', sans-serif;
  font-size: 14px;
  padding: 0 0 0 40px;
  color: #2ecc71;
  margin: 0;
}
.book_right_button {
  padding: 0 0 0 40px;
  margin: 15px 0 0 0;
}
.book_right_button a {
  color: #2ecc71;
  text-decoration: none;
  font-family: 'Montserrat', sans-serif;
  border: 2px solid #2ecc71;
  padding: 5px 5px 5px 5px;
  font-size: 12px;
  border-radius: 5px;
  -webkit-transition-property: all;
  transition-property: all;
  -webkit-transition-duration: .5s;
  transition-duration: .5s;
}
.book_right_button a:hover {
  color: #000000;
  background-color: #2ecc71;
  cursor: pointer;
  -webkit-transition-property: all;
  transition-property: all;
  -webkit-transition-duration: .5s;
  transition-duration: .5s;
}
  <div class='book'>
        <div class='book_left'>
          <img src='http://images.gr-assets.com/books/1474171184l/136251.jpg'>
        </div>
        <div class='book_right'>
          <h1>Harry Potter and the Deathly Hallows</h1>
          <div class='book_right_details'>
            <ul>
              <li>JK Rowling</li>
              <li>Fiction</li>
            </ul>
            <div class='book_right_blurb'>
              <p>Harry meets his destiny in the final book of Rowling's acclaimed series.</p>
            </div>
            <div class='book_right_button'>
            <a href='https://www.youtube.com/watch?v=ot6C1ZKyiME' target='_blank'>READ BOOK</a>
            </div>
          </div>
        </div>
      </div>

关于html - 淡化一个 div 溢出到相邻的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44490475/

相关文章:

javascript - Paperjs 中的路径 VS 形状?

javascript - 使 div 仅与父级一样长

.net - 如何在 WPF 应用程序中实现气球消息

jquery - 如何找到具有特定值的子元素并删除其直接父节点?

c# - 如何在 razor foreach 中使用 html 和 escape razor?

image - 如果浏览器不支持 HTML5 的 <video> 标签,如何显示图像

java - 非顶级窗口中的非不透明 JButton 背景变得不透明?

javascript - iOS 自动播放视频的取消静音按钮

css - 超出容器的流体文本框

JAVA GUI - 面板上出现 "cannot find symbol"错误。 "class, interface or enum expected"上