html-css float不会在右边显示div

前端之家收集整理的这篇文章主要介绍了html-css float不会在右边显示div 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我对css float有疑问:right;当我卸下浮子时:right;在.container中,然后将显示.app-chat-image-more,但我需要float:right;

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

  1. .container {
  2. max-width: 60%;
  3. -webkit-border-radius: 10px;
  4. -webkit-border-top-right-radius: 3px;
  5. -webkit-border-bottom-right-radius: 3px;
  6. -moz-border-radius: 10px;
  7. -moz-border-radius-topright: 3px;
  8. -moz-border-radius-bottomright: 3px;
  9. border-radius: 10px;
  10. border-top-right-radius: 10px;
  11. border-bottom-right-radius: 10px;
  12. border-top-right-radius: 3px;
  13. border-bottom-right-radius: 3px;
  14. background-color: #dcf8c6;
  15. Box-shadow: 0 1px 0.5px rgba(0,0.13);
  16. float: right;
  17. }
  18. .app-chat-image-more {
  19. width: 100%;
  20. -webkit-border-radius: 10px;
  21. -webkit-border-top-right-radius: 3px;
  22. -webkit-border-bottom-right-radius: 3px;
  23. -moz-border-radius: 10px;
  24. -moz-border-radius-topright: 3px;
  25. -moz-border-radius-bottomright: 3px;
  26. border-radius: 10px;
  27. border-top-right-radius: 3px;
  28. border-bottom-right-radius: 3px;
  29. overflow: hidden;
  30. display: inline-block;
  31. float: right;
  32. }
  33. .chat-image-more-item {
  34. position: relative;
  35. float: left;
  36. width: calc(100% / 2 - 2px);
  37. width: -webkit-calc(100% / 2 - 2px);
  38. width: -moz-calc(100% / 2 - 2px);
  39. padding: 1px;
  40. }
  41. .app-chat-image-item {
  42. position: relative;
  43. padding-top: 100%;
  44. position: relative;
  45. overflow: hidden;
  46. -webkit-background-size: cover;
  47. -moz-background-size: cover;
  48. -o-background-size: cover;
  49. background-size: cover;
  50. background-position: center;
  51. }
  52. .chat-hidden-image-item {
  53. position: absolute;
  54. display: block;
  55. left: 0;
  56. right: 0;
  57. top: 0;
  58. bottom: 0;
  59. width: 100%;
  60. height: 100%;
  61. opacity: 0;
  62. }
  1. <div class="container">
  2. <div class="app-chat-image-more">
  3. <div class="chat-image-more-item">
  4. <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');">
  5. <img src="http://www.cartoondistrict.com/wp-content/uploads/2015/02/avatar-wallpaper-for-Pc-11.jpg">
  6. </div>
  7. </div>
  8. </div>
  9. </div>
最佳答案
给.container一个宽度:100%.

由于您已设置了最大宽度:60%,因此宽度实际上是60%.但是,您需要设置宽度才能使用float:right.

  1. .container {
  2. width: 100%;
  3. max-width: 60%;
  4. -webkit-border-radius: 10px;
  5. -webkit-border-top-right-radius: 3px;
  6. -webkit-border-bottom-right-radius: 3px;
  7. -moz-border-radius: 10px;
  8. -moz-border-radius-topright: 3px;
  9. -moz-border-radius-bottomright: 3px;
  10. border-radius: 10px;
  11. border-top-right-radius: 10px;
  12. border-bottom-right-radius: 10px;
  13. border-top-right-radius: 3px;
  14. border-bottom-right-radius: 3px;
  15. background-color: #dcf8c6;
  16. Box-shadow: 0 1px 0.5px rgba(0,0.13);
  17. float: right;
  18. }
  19. .app-chat-image-more {
  20. width: 100%;
  21. -webkit-border-radius: 10px;
  22. -webkit-border-top-right-radius: 3px;
  23. -webkit-border-bottom-right-radius: 3px;
  24. -moz-border-radius: 10px;
  25. -moz-border-radius-topright: 3px;
  26. -moz-border-radius-bottomright: 3px;
  27. border-radius: 10px;
  28. border-top-right-radius: 3px;
  29. border-bottom-right-radius: 3px;
  30. overflow: hidden;
  31. display: inline-block;
  32. float: right;
  33. }
  34. .chat-image-more-item {
  35. position: relative;
  36. float: left;
  37. width: calc(100%/2 - 2px);
  38. width: -webkit-calc(100%/2 -2px);
  39. width: -moz-calc(100%/2 -2px);
  40. padding: 1px;
  41. }
  42. .app-chat-image-item {
  43. position: relative;
  44. padding-top: 100%;
  45. position: relative;
  46. overflow: hidden;
  47. -webkit-background-size: cover;
  48. -moz-background-size: cover;
  49. -o-background-size: cover;
  50. background-size: cover;
  51. background-position: center;
  52. }
  53. .chat-hidden-image-item {
  54. position: absolute;
  55. display: block;
  56. left: 0;
  57. right: 0;
  58. top: 0;
  59. bottom: 0;
  60. width: 100%;
  61. height: 100%;
  62. opacity: 0;
  63. }
  1. <div class="container">
  2. <div class="app-chat-image-more">
  3. <div class="chat-image-more-item">
  4. <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');">
  5. <img src="http://www.cartoondistrict.com/wp-content/uploads/2015/02/avatar-wallpaper-for-Pc-11.jpg">
  6. </div>
  7. </div>
  8. </div>
  9. </div>

猜你在找的HTML相关文章