gpt4 book ai didi

html - css float 不在右侧显示 div

转载 作者:可可西里 更新时间:2023-11-01 13:19:14 26 4
gpt4 key购买 nike

我在使用 css float:right; 时遇到问题当我删除 .container 中的 float:right; 时,.app-chat-image-more 将显示,但我需要 float :右;

这是 DEMO 您看不到图像。当你删除 float:right in .container 然后你可以看到图像。使用 float:right; 如何处理图片的显示? .有人可以帮我吗?

.container {
max-width: 60%;
-webkit-border-radius: 10px;
-webkit-border-top-right-radius: 3px;
-webkit-border-bottom-right-radius: 3px;
-moz-border-radius: 10px;
-moz-border-radius-topright: 3px;
-moz-border-radius-bottomright: 3px;
border-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
background-color: #dcf8c6;
box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
float: right;
}

.app-chat-image-more {
width: 100%;
-webkit-border-radius: 10px;
-webkit-border-top-right-radius: 3px;
-webkit-border-bottom-right-radius: 3px;
-moz-border-radius: 10px;
-moz-border-radius-topright: 3px;
-moz-border-radius-bottomright: 3px;
border-radius: 10px;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
overflow: hidden;
display: inline-block;
float: right;
}

.chat-image-more-item {
position: relative;
float: left;
width: calc(100% / 2 - 2px);
width: -webkit-calc(100% / 2 - 2px);
width: -moz-calc(100% / 2 - 2px);
padding: 1px;
}

.app-chat-image-item {
position: relative;
padding-top: 100%;
position: relative;
overflow: hidden;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-position: center;
}

.chat-hidden-image-item {
position: absolute;
display: block;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
opacity: 0;
}
<div class="container">
<div class="app-chat-image-more">
<div class="chat-image-more-item">
<div class="app-chat-image-item" style="background-image: url('http://www.cartoondistrict.com/wp-content/uploads/2015/02/avatar-wallpaper-for-Pc-11.jpg');">
<img src="http://www.cartoondistrict.com/wp-content/uploads/2015/02/avatar-wallpaper-for-Pc-11.jpg">
</div>
</div>
</div>
</div>

最佳答案

.container一个width: 100%

因为您设置了 max-width: 60%,所以宽度实际上是 60%。但是,您需要设置宽度才能使用 float: right

.container {
width: 100%;
max-width: 60%;
-webkit-border-radius: 10px;
-webkit-border-top-right-radius: 3px;
-webkit-border-bottom-right-radius: 3px;
-moz-border-radius: 10px;
-moz-border-radius-topright: 3px;
-moz-border-radius-bottomright: 3px;
border-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
background-color: #dcf8c6;
box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
float: right;
}

.app-chat-image-more {
width: 100%;
-webkit-border-radius: 10px;
-webkit-border-top-right-radius: 3px;
-webkit-border-bottom-right-radius: 3px;
-moz-border-radius: 10px;
-moz-border-radius-topright: 3px;
-moz-border-radius-bottomright: 3px;
border-radius: 10px;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
overflow: hidden;
display: inline-block;
float: right;
}

.chat-image-more-item {
position: relative;
float: left;
width: calc(100%/2 - 2px);
width: -webkit-calc(100%/2 -2px);
width: -moz-calc(100%/2 -2px);
padding: 1px;
}

.app-chat-image-item {
position: relative;
padding-top: 100%;
position: relative;
overflow: hidden;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-position: center;
}

.chat-hidden-image-item {
position: absolute;
display: block;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
opacity: 0;
}
<div class="container">
<div class="app-chat-image-more">
<div class="chat-image-more-item">
<div class="app-chat-image-item" style="background-image: url('http://www.cartoondistrict.com/wp-content/uploads/2015/02/avatar-wallpaper-for-Pc-11.jpg');">
<img src="http://www.cartoondistrict.com/wp-content/uploads/2015/02/avatar-wallpaper-for-Pc-11.jpg">
</div>
</div>
</div>
</div>

关于html - css float 不在右侧显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55269111/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com