html - CSS 在图像旁边放置文本并使其具有移动响应性
问题描述
我使用此代码:我的代码
<div style="display:inline-block;vertical-align:top;"><a href="domain.tld"><img src="https://i.imgur.com/J5azqpQ.jpg" alt="This is a cool picture" width="300px" /> </a></div><div style="display:inline-block;"><div>13/11/2019</div><div><strong>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</strong></div><div><a href="*|FEEDITEM:URL|*"> Learn More</a><br></div></div><hr><div style="display:inline-block;vertical-align:top;"><a href="domain.tld"><img src="https://i.imgur.com/HkwIsNL.jpg" alt="This is a cool picture" width="300px" /> </a></div><div style="display:inline-block;"><div>13/11/2019</div><div><strong>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</strong></div><div><a href="*|FEEDITEM:URL|*"> Learn More</a><br></div>
我想要实现的只是当您从 PC/笔记本电脑/平板电脑查看代码时,能够在图像旁边显示文本,如图 1 所示。我需要所有移动设备上的文本都位于图像下方(图 2)。
有没有可能在没有媒体查询的情况下实现这一目标的方法?因为有些手机的宽度大于 1080 像素,这与一些旧 PC 的宽度相同。
我想以某种方式确定用户使用手机,以便如果用户使用 PC 或移动设备,我可以实现不同的 css。
我分享两张照片,以便您理解我的意思。
PC端(图1)
手机端(图2)
任何帮助将不胜感激!
解决方案
如果屏幕大小发生变化,您可以使用 css 媒体查询进行调整。
* {
box-sizing: border-box;
}
.item {
display: inline-block;
}
/* on PC */
@media screen and (min-width: 550px) {
.featured-image {
float: left;
width: 40%;
padding-right: 15px;
}
.featured-image img {
width: 100%;
}
.description {
float: left;
width: 60%;
}
}
/* on Mobile */
@media screen and (max-width: 550px) {
.featured-image {
width: 100%;
}
.featured-image img {
width: 100%;
}
.description {
width: 100%;
}
}
<div class="item">
<div class="featured-image">
<a href="domain.tld"><img src="https://i.imgur.com/J5azqpQ.jpg" alt="This is a cool picture" /> </a>
</div>
<div class="description">
<div>13/11/2019</div>
<div><strong>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</strong></div>
<div><a href="*|FEEDITEM:URL|*"> Learn More</a><br></div>
</div>
</div>
<hr>
<div class="item">
<div class="featured-image">
<a href="domain.tld"><img src="https://i.imgur.com/HkwIsNL.jpg" alt="This is a cool picture" /> </a>
</div>
<div class="description">
<div>13/11/2019</div>
<div><strong>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</strong></div>
<div><a href="*|FEEDITEM:URL|*"> Learn More</a><br></div>
</div>
</div>
<hr>
推荐阅读
- python - Convert list of dicts into a unique dict
- c# - 在 MVC 应用程序中存储下载链接
- python - Keras 的正确形状 - 非图像 1D CNN
- java - 切换为 goto 语句或个别案例检查器?
- amazon-web-services - 有没有办法在没有 NAT 的情况下从 VPC 外部的 Lambda 查询 VPC 中的 RDS DB
- c# - CodeDomProvider 在使用 GenerateInMemory 时仍然使用 TempFiles
- javascript - 无法从 Firebase 读取 JSON 值
- c# - 如何打印带有前导零的两位数?
- javascript - P5.js:如何知道某个键是否不再被按下?
- mysql - MySQL Workbench 中的正向工程输出错误 1064