响应式媒体卡图像在左,文本在右
Responsive Media Card Image on left, text on right
这是我当前的代码 in jsfiddle:
<div class="card-container">
<div class="float-layout">
<div class="card-image">
<img src="https://images.pexels.com/photos/534151/pexels-photo-534151.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260">
<div class="card">
<div class="card-title">Title</div>
<div class="card-desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ullamcorper
mollis tempus. Mauris eu maximus lectus, eu auctor justo. Aenean porta purus
vel commodo consequat.
</div>
</div>
</div>
</div>
</div>
.float-layout {
padding: 5px 5px;
float: left;
width: 100%;
height: auto;
box-sizing: border-box;
margin: 0;
}
.card-container {
overflow: hidden;
}
.card {
background-color: dodgerblue;
color: black;
height: 100%;
width: 50%;
float: right;
}
.card-title {
font-size: 30px;
text-align: center;
font-weight: bold;
padding-top: 20px;
}
.card-desc {
padding: 10px;
text-align: left;
font-size: 18px;
}
div.card-image img {
width: 50%;
height: auto;
}
/* Phone Devices Query */
@media only screen and (max-width: 37.5em) {
div.card-image img {
width: 100%;
height: auto;
}
.card {
width: 100%;
margin-top: -4px;
}
}
我不确定我是否需要 clearfix hack 来解决这个问题,但是当我调整浏览器时 window,我的媒体卡右侧(包含标题和描述)没有正确缩放我的图像设置的左侧。我希望它们都能以相同的高度和大小响应地缩放。
为了更好地理解,我当前的代码如下所示:
https://i.stack.imgur.com/xebaE.png
我希望它在相同的高度缩放,当我将浏览器 window 调整为任意大小时,像这样响应:
https://i.stack.imgur.com/IkXok.png
有必要吗?
.float-layout {
padding: 5px 5px;
float: left;
width: 100%;
height: auto;
box-sizing: border-box;
margin: 0;
}
.card-container {
overflow: hidden;
}
.card {
background-color: dodgerblue;
color: black;
min-height: 100%; /*replace this it in width: 100%*/
width: 50%;
float: right;
}
.card-title {
font-size: 30px;
text-align: center;
font-weight: bold;
padding-top: 20px;
}
.card-desc {
padding: 10px;
text-align: left;
font-size: 18px;
}
/*add this it*/
.card-image {
display: flex;
}
/*-------------*/
div.card-image img {
width: 50%;
height: auto;
}
/* Phone Devices Query */
@media only screen and (max-width: 37.5em) {
div.card-image img {
width: 100%;
height: auto;
}
/*add this it*/
.card-image {
flex-direction: column;
}
/*----------------------*/
.card {
width: 100%;
margin-top: -4px;
}
}
<div class="card-container">
<div class="float-layout">
<div class="card-image">
<img src="https://images.pexels.com/photos/534151/pexels-photo-534151.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260">
<div class="card">
<div class="card-title">Title</div>
<div class="card-desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ullamcorper
mollis tempus. Mauris eu maximus lectus, eu auctor justo. Aenean porta purus
vel commodo consequat.
</div>
</div>
</div>
</div>
</div>
这是我当前的代码 in jsfiddle:
<div class="card-container">
<div class="float-layout">
<div class="card-image">
<img src="https://images.pexels.com/photos/534151/pexels-photo-534151.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260">
<div class="card">
<div class="card-title">Title</div>
<div class="card-desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ullamcorper
mollis tempus. Mauris eu maximus lectus, eu auctor justo. Aenean porta purus
vel commodo consequat.
</div>
</div>
</div>
</div>
</div>
.float-layout {
padding: 5px 5px;
float: left;
width: 100%;
height: auto;
box-sizing: border-box;
margin: 0;
}
.card-container {
overflow: hidden;
}
.card {
background-color: dodgerblue;
color: black;
height: 100%;
width: 50%;
float: right;
}
.card-title {
font-size: 30px;
text-align: center;
font-weight: bold;
padding-top: 20px;
}
.card-desc {
padding: 10px;
text-align: left;
font-size: 18px;
}
div.card-image img {
width: 50%;
height: auto;
}
/* Phone Devices Query */
@media only screen and (max-width: 37.5em) {
div.card-image img {
width: 100%;
height: auto;
}
.card {
width: 100%;
margin-top: -4px;
}
}
我不确定我是否需要 clearfix hack 来解决这个问题,但是当我调整浏览器时 window,我的媒体卡右侧(包含标题和描述)没有正确缩放我的图像设置的左侧。我希望它们都能以相同的高度和大小响应地缩放。
为了更好地理解,我当前的代码如下所示: https://i.stack.imgur.com/xebaE.png
我希望它在相同的高度缩放,当我将浏览器 window 调整为任意大小时,像这样响应: https://i.stack.imgur.com/IkXok.png
有必要吗?
.float-layout {
padding: 5px 5px;
float: left;
width: 100%;
height: auto;
box-sizing: border-box;
margin: 0;
}
.card-container {
overflow: hidden;
}
.card {
background-color: dodgerblue;
color: black;
min-height: 100%; /*replace this it in width: 100%*/
width: 50%;
float: right;
}
.card-title {
font-size: 30px;
text-align: center;
font-weight: bold;
padding-top: 20px;
}
.card-desc {
padding: 10px;
text-align: left;
font-size: 18px;
}
/*add this it*/
.card-image {
display: flex;
}
/*-------------*/
div.card-image img {
width: 50%;
height: auto;
}
/* Phone Devices Query */
@media only screen and (max-width: 37.5em) {
div.card-image img {
width: 100%;
height: auto;
}
/*add this it*/
.card-image {
flex-direction: column;
}
/*----------------------*/
.card {
width: 100%;
margin-top: -4px;
}
}
<div class="card-container">
<div class="float-layout">
<div class="card-image">
<img src="https://images.pexels.com/photos/534151/pexels-photo-534151.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260">
<div class="card">
<div class="card-title">Title</div>
<div class="card-desc">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ullamcorper
mollis tempus. Mauris eu maximus lectus, eu auctor justo. Aenean porta purus
vel commodo consequat.
</div>
</div>
</div>
</div>
</div>