我对css float有疑问:right;当我卸下浮子时:right;在.container中,然后将显示.app-chat-image-more,但我需要float:right;
这是DEMO您看不到图像.当您删除.container中的float:right时,您可以看到图像.如何使用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.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一个宽度:100%.
原文链接:https://www.f2er.com/html/530464.html由于您已设置了最大宽度: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.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>