我正在尝试在 div 中使文本左侧和图像右侧。我在 Stackoverflow 中发现了很多示例,其中图像在左,文本在右,然后我尝试切换它们但无法使其工作。我 在 stackoverflow 上 发现了这一点,但对我来说没有意义。
我试过这个 JSFIDDLE ,但你会发现它不起作用。
.main-topic {
border: 2px solid green;
width: 1541px;
margin: 0 auto;
clear: both;
}
.left-text{
vertical-align:middle;
}
.right-picture{
float: right;
}
.right-picture > img{
display: block;
}
.clear{
clear: both;
}
我的目标是 这个(抱歉不能张贴图片我没有足够的声誉)。我希望文本位于带边框的 div 的左侧,图片位于右侧
原文由 Levan Tsivadze 发布,翻译遵循 CC BY-SA 4.0 许可协议
只需将
display: flex;
添加到.main-topic
即可。并删除以下 css。现在不需要了。
工作小提琴
编辑:
If don’t required static width and height then, remove static
height
fromsection
and staticwidth
from.main-topic
will make result better.这是
width: 1541px;
来自.main-topic
和height: 500px;
来自section
更新小提琴