html - 如何将图像从容器“拉伸”到屏幕右侧?
问题描述
我尝试将图像标签放置在绝对顶部 0 右 0 的包装器中。但在这种情况下,图像包装器从父框出来。那么你有什么想法吗?还有什么更好的选择:img-tag 或带有背景图像的 div? 最终结果如图
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.container {
width: 100%;
max-width: 1400px;
margin: 0 auto;
}
.about__left, .about__right {
width: 50%;
}
.about-wrapper {
display: flex;
align-items: center;
position: relative;
}
.about__left-text {
width: 85%;
line-height: 35px;
}
.about__left-title {
margin-bottom: 40px;
}
.about__right {
position: absolute;
top: 0;
right: 0;
/* width: 950px;
height: 600px;
background-image: url('../images/about__pic.png');
background-size: cover;
background-repeat: no-repeat; */
}
.about__right-pic {
/* position: absolute;
top: 0;
right: 0; */
}
<div class="about mb180">
<div class="container about-wrapper">
<div class="about__left">
<h2 class="about__left-title title">О нас</h2>
<p class="about__left-text text">Командор - официальный дистрибьютор и эксклюзивный представитель международной марки Komandor в России. 25 лет на рынке, представительства в более, чем 11 странах мира, в России работает более 400 торговых точек и 40 сертифицированных производств</p>
</div>
<div class="about__right">
<img class="about__right-pic" src="images/about__pic.png" alt="pic">
</div>
</div>
</div>
解决方案
添加overflow:hidden;
到 .container 并查看。
.container {
width: 100%;
max-width: 1400px;
margin: 0 auto;
overflow:hidden;
}
或者添加这个新的 css 规则;
.about__right-pic,
.about__right img{
width:100%;
height:auto;
}
推荐阅读
- android - Bufferedreader.readline() 导致无限循环
- python - 如何遍历此列表以获得正确答案?
- instagram-api - 通过 instagram-api 登录后如何获取 session-id?我正在获取用户名但进一步的 api 调用我想要 session-id 我将如何得到它?
- javascript - 如果阅读,jQuery 显示/隐藏通知
- apache - 如何通过具有虚拟主机的服务器上的 IP 地址访问没有域名的 vps 文件?
- html - 反应原生图标未在视图中心对齐
- javascript - 如何在语义 UI 反应下拉列表中设置默认值
- ssis - 当源和目标都是动态的时,如何在复制活动中动态映射模式?
- javascript - 如何在字符串中显示html标签?
- google-apps-script - Google脚本通过唯一ID查找和更新其他工作表中的行