为什么我可以用Flex移动图像?
.nav {
height: 500px;
}
.navphoto {
height: 500px;
display: flex;
justify-content: flex-end;
}
<div class="nav">
<img class="navphoto" src="images/navphoto.jpg">
</div>
正如标题所说:为什么我不能移动图像,但是当我将Flex代码放入.NAV中时,它正在工作。
.nav {
height: 500px;
}
.navphoto {
height: 500px;
display: flex;
justify-content: flex-end;
}
<div class="nav">
<img class="navphoto" src="images/navphoto.jpg">
</div>
As the title says: why can't I move an image but when I put flex code into a .nav it's working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有两个问题:
正当 - contify-content
是Flex容器的属性基本上,试图将图像本身设置为flex-container并不能做您想要的事情,因为图像不是自身的孩子。这是整个元素。您需要某种弹性容器才能在其中布局。
There's two problems:
justify-content
is a property for a flex containerBasically, trying to set the image itself as a flex-container doesn't do what you want because the image is not a child of itself. It's the entire element. You need some kind of flex container to layout within.
来自 css技巧 - flexbox的完整指南
关键字 - 容器
它对
flex
img
元素没有太大的逻辑意义,因为它不是容器,它是flex -item 。如果您的子集包含img
和text
,那么对于flex
it是有意义的。请在下面的CSS中查看注释:
From CSS Tricks - A Complete Guide to Flexbox
Key word - container
It doesn't make much logical sense to
flex
theimg
element because it is not a container, it's a flex-item. If you had a different subset that contained theimg
and thetext
then it would make sense toflex
it.Please see the notes in the CSS below:
您正在应用
显示:flex;
on.navphoto
,将其应用于.nav
。查看以下代码You are applying
display: flex;
on.navphoto
, apply it on.nav
. Look at the following code