如何通过移至新行来防止图像溢出div块?

时间:2019-05-19 15:35:46

标签: php html css

我正在编写代码,以使用按钮设置表情符号列表。我对表情符号图像有问题,因为当我控制div块的宽度大小以防止图像溢出时,它们会溢出div块。

这是图片:

enter image description here

Here是JSFiddle链接。

我已经尝试过:

overflow:hidden;

我也尝试过这个:

width: 100%;
height: 100%; 
overflow-y: scroll;

这是完整的代码:

.font-border {
  -webkit-align-items: center;
  align-items: center;
  background-color: #ffff;
  border: none;
  -webkit-border-radius: 2px;
  border-radius: 2px;
  -webkit-box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  /*display: -webkit-inline-box;
        display: -webkit-inline-flex;
        display: -ms-inline-flexbox;*/
  display: none;
  margin-left: 16px;
  margin-bottom: 12px;
  position: relative;
  padding: 8px 2px;
  white-space: nowrap;
  height: 21px;
}

.search_emoticons {
  background: no-repeat url(https://ssl.gstatic.com/mail/sprites/compose-28e1860af47052bc9ce7a152b803c105.png) 0 -799px;
  width: 28px;
  height: 30px;
  margin: 2px 3px;
  border: 0;
  background-color: rgba(0, 0, 0, .3);
  opacity: 1;
}

.show_face_emoticons {
  background: no-repeat url(https://ssl.gstatic.com/mail/sprites/compose-28e1860af47052bc9ce7a152b803c105.png) 0 -270px;
  width: 28px;
  height: 30px;
  margin: 2px 3px;
  border: 0;
  opacity: .225;
}

.show_object_emoticons {
  background: no-repeat url(https://ssl.gstatic.com/mail/sprites/compose-28e1860af47052bc9ce7a152b803c105.png) 0 -689px;
  width: 28px;
  height: 30px;
  margin: 2px 3px;
  border: 0;
  opacity: .225;
}

.show_nature_emoticons {
  background: no-repeat url(https://ssl.gstatic.com/mail/sprites/compose-28e1860af47052bc9ce7a152b803c105.png) 0 -547px;
  width: 28px;
  height: 30px;
  margin: 2px 3px;
  border: 0;
  opacity: .225;
}

.show_transportation {
  background: no-repeat url(https://ssl.gstatic.com/mail/sprites/compose-28e1860af47052bc9ce7a152b803c105.png) 0 -657px;
  width: 28px;
  height: 30px;
  margin: 2px 3px;
  border: 0;
  opacity: .225;
}

.show_symbol_emoticons {
  background: no-repeat url(https://ssl.gstatic.com/mail/sprites/compose-28e1860af47052bc9ce7a152b803c105.png) 0 -854px;
  width: 28px;
  height: 30px;
  margin: 2px 3px;
  border: 0;
  opacity: .225;
}

.close_border {
  border: none;
  background: no-repeat url(https://ssl.gstatic.com/mail/sprites/compose-28e1860af47052bc9ce7a152b803c105.png) 0 -767px;
  height: 30px;
  width: 30px;
  float: right;
}

.emoticons_input_search {
  border-style: none none solid;
  border-bottom: 2px solid #c3c3c3;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  font-size: .875rem;
  width: 100%;
  padding: 8px;
  outline: none;
}

.a8I {
  position: relative;
  overflow-y: scroll;
  display: inline-block;
  display: table-cell;
  width: 100%;
  height: 84%;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
}

.a8m {
  padding: 2px;
  text-align: center;
  vertical-align: middle;
  margin: 4px;
  cursor: pointer;
  background: transparent;
  border: none;
  font-size: 1px;
}

.e1f600 {
  background: no-repeat url(https://ssl.gstatic.com/chat/emoji/png28-7f9d3a5045813584f828fe69a1fecb77.png) 0 -11223px;
}

.e1f601 {
  background: no-repeat url(https://ssl.gstatic.com/chat/emoji/png28-7f9d3a5045813584f828fe69a1fecb77.png) 0 -14152px;
}

.e1f602 {
  background: no-repeat url(https://ssl.gstatic.com/chat/emoji/png28-7f9d3a5045813584f828fe69a1fecb77.png) 0 -14152px;
}

.e1f603 {
  background: no-repeat url(https://ssl.gstatic.com/chat/emoji/png28-7f9d3a5045813584f828fe69a1fecb77.png) 0 -14152px;
}

.e1f604 {
  background: no-repeat url(https://ssl.gstatic.com/chat/emoji/png28-7f9d3a5045813584f828fe69a1fecb77.png) 0 -14152px;
}

.e1f605 {
  background: no-repeat url(https://ssl.gstatic.com/chat/emoji/png28-7f9d3a5045813584f828fe69a1fecb77.png) 0 -14152px;
}

.e1f606 {
  background: no-repeat url(https://ssl.gstatic.com/chat/emoji/png28-7f9d3a5045813584f828fe69a1fecb77.png) 0 -14152px;
}

.e1f607 {
  background: no-repeat url(https://ssl.gstatic.com/chat/emoji/png28-7f9d3a5045813584f828fe69a1fecb77.png) 0 -14152px;
}

.e1f608 {
  background: no-repeat url(https://ssl.gstatic.com/chat/emoji/png28-7f9d3a5045813584f828fe69a1fecb77.png) 0 -14152px;
}

.e1f609 {
  background: no-repeat url(https://ssl.gstatic.com/chat/emoji/png28-7f9d3a5045813584f828fe69a1fecb77.png) 0 -14152px;
}

.e1f610 {
  background: no-repeat url(https://ssl.gstatic.com/chat/emoji/png28-7f9d3a5045813584f828fe69a1fecb77.png) 0 -14152px;
}

.a8r {
  margin: 0 .2ex;
  vertical-align: middle;
  height: 28px;
  width: 28px;
  display: inline-block;
}
<div id="emoticons-menu" class="font-border" style="visibility: visible; left: 212px; top: 219px; box-sizing: border-box; position: absolute; width: 262px; height: 212px; z-index: 2; display: block;">


  <div id="show_emoticons" class="a8I a8m" style="position: relative; width: 100%; height: 100%; overflow-y: scroll;">

    <button aria-label="grinning face" string="1f601" class="e1f601 a8r"></button>

    <button aria-label="grinning face" string="1f602" class="e1f602 a8r"></button>

    <button aria-label="grinning face" string="1f603" class="e1f603 a8r"></button>

    <button aria-label="grinning face" string="1f604" class="e1f604 a8r"></button>

    <button aria-label="grinning face" string="1f605" class="e1f605 a8r"></button>

    <button aria-label="grinning face" string="1f606" class="e1f606 a8r"></button>

    <button aria-label="grinning face" string="1f607" class="e1f607 a8r"></button>

    <button aria-label="grinning face" string="1f608" class="e1f608 a8r"></button>

    <button aria-label="grinning face" string="1f609" class="e1f609 a8r"></button>

    <button aria-label="grinning face" string="1f610" class="e1f610 a8r"></button>

    <button aria-label="grinning face" string="1f600" class="e1f600 a8r"></button>
  </div>
</div>

我希望实现的是每次将图像移动到div块上方的位置,以便图像显示在新行中以防止溢出。我不知道该怎么做,因为我尝试了几种不同的方法,所以请您举个例子,说明如何将图像移到新行以防止div块溢出?

谢谢。

2 个答案:

答案 0 :(得分:1)

您需要为此应用word-wrapwhite-space

.a8m {

    padding: 2px;
    text-align: center;
    vertical-align: middle;
    margin: 4px;
    cursor: pointer;
    background: transparent;
    border: none;
    font-size: 1px;
    word-wrap: break-word;
    white-space: initial;

}

希望它对您有帮助:)

答案 1 :(得分:1)

只需尝试一下:

图释的父div应该显示为FLEX 例如:

display:flex;(这将横向排列图释) flex-wrap:wrap;(这会使表情符号到达边缘时进入新的一行)