【发布时间】:2020-08-21 15:44:35
【问题描述】:
我正在做一个项目,我必须只使用 HTML 和 CSS 创建一个在线书店网页。我想使用如下图所示的样式显示商店的“关于我们”信息:
基本上我想以上面显示的方式放置图像和文本。但是,使用 flexbox 时,我无法同步图像和文本,因为我很难将图像宽度设置为覆盖 flex 容器的一半,而将文本的一部分设置为另一半。 这是我的代码:
.flex-container {
display: flex;
justify-content: flex-start;
flex-direction: row;
background-color: orange;
opacity: 0.7;
}
.flex-container>div {
margin: 0;
width: 100%;
height: auto;
}
#fleximg>img {
width: 60%;
height: auto;
}
#about {
width: 50%;
margin-right: 300px;
height: auto;
}
<div class="flex-container">
<div id="fleximg"><img src="https://placehold.it/400x400" alt=d esk/></div>
<div id="about">
<!-- text i want to place next to image -->
<h1> ABOUT US </h1>
<p>
In these rough times we experience right now being forced to stay at home staring at nothing does actually nothing.This is why we have created this online book delivery website to provide the company of a book to those who can't go outside to buy or read
a book at a local bookshop .
</p>
</div>
</div>
当我运行我的页面时,我得到下面的图片,其中图像和文本不相邻,我无法重新调整它们的大小
感谢您帮助指导我解决问题
【问题讨论】:
-
文本和图像之间有一个空格,因为您已将 img 设为其父级的 60% 宽度。
标签: html css image flexbox width