多个mdl表重叠问题

时间:2017-08-10 04:35:51

标签: jquery html css css3 material-design-lite

嗨,快问我想知道你是否可以在一个页面上有多个mdl表?然而,他们都需要得到相同的形式。

我的尝试让它相互拍打而不是从左到右相邻。

https://codepen.io/russellharrower/pen/RZVmwo 错误在我知道的CSS中

CSS

/* Downloaded from https://www.codeseek.co/ */
body {
  background: #ECEFF1;
}

.mdl-layout__content {
  padding: 24px 12px;
}
.mdl-layout__content h1 {
  font-size: 30px;
  margin: 0 0 .3em;
}

.mdl-sheet__container {
  right: 32px;
  bottom: 32px;
  -webkit-transform: rotate(0deg);
          transform: rotate(0deg);
}

.mdl-sheet {
  position: relative;
  background: #FF5722;
  float:left;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  cursor: pointer;
  -webkit-transition: all 180ms;
  transition: all 180ms;
}
.mdl-sheet .mdl-sheet__content {
  display: none;
}

.mdl-sheet__icon {
  color: #fff;
  position: static;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-12px, -12px);
          transform: translate(-12px, -12px);
  font-size: 24px;
  width: 24px;
  height: 24px;
  line-height: 24px;
}

.mdl-sheet--opened {
  background: #fff;
  color: #263238;
  border-radius: 2px;
  width: 240px;
  height: auto;
  min-height: 150px;
  max-height: 80vh;
  overflow-y: auto;
}
.mdl-sheet--opened .mdl-sheet__icon {
  display: none;
}
.mdl-sheet--opened .mdl-sheet__content {
  display: block;
}

1 个答案:

答案 0 :(得分:0)

由于您已将另一个mdl-sheet插入到上一个mdl-sheet中,因此表格重叠。在css中,我添加了display:inline-block,以便从左到右显示它们。



var $sheet = $('.mdl-sheet');

if ($sheet.length > 0) {
  $('html').on('click', function() {
    $sheet.removeClass('mdl-sheet--opened')
  });

  $sheet.on('click', function(event) {
    event.stopPropagation();

    $sheet.addClass('mdl-sheet--opened');
  });
}

/* Downloaded from https://www.codeseek.co/ */

body {
  background: #ECEFF1;
}

.mdl-layout__content {
  padding: 24px 12px;
}

.mdl-layout__content h1 {
  font-size: 30px;
  margin: 0 0 .3em;
}

.mdl-sheet__container {
  right: 32px;
  bottom: 32px;
  -webkit-transform: rotate(0deg);
  transform: rotate(0deg);
}

.mdl-sheet {
  display: inline-block;
  position: relative;
  background: #FF5722;
  float: none;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  cursor: pointer;
  -webkit-transition: all 180ms;
  transition: all 180ms;
}

.mdl-sheet .mdl-sheet__content {
  display: none;
}

.mdl-sheet__icon {
  color: #fff;
  position: static;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-12px, -12px);
  transform: translate(-12px, -12px);
  font-size: 24px;
  width: 24px;
  height: 24px;
  line-height: 24px;
}

.mdl-sheet--opened {
  background: #fff;
  color: #263238;
  border-radius: 2px;
  width: 240px;
  height: auto;
  min-height: 150px;
  max-height: 80vh;
  overflow-y: auto;
}

.mdl-sheet--opened .mdl-sheet__icon {
  display: none;
}

.mdl-sheet--opened .mdl-sheet__content {
  display: block;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<div class="mdl-sheet__container">
  <div class="mdl-sheet mdl-shadow--2dp">
    <i class="material-icons mdl-sheet__icon">add</i>
    <div class="mdl-sheet__content">
      <div class="mdl-list">
        <div class="mdl-list__item">
          <span class="mdl-list__item-primary-content">
              <i class="material-icons mdl-list__item-avatar">person</i>
              <span>Bryan Cranston</span>
          </span>
          <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">add</i></a>
        </div>
        <div class="mdl-list__item">
          <span class="mdl-list__item-primary-content">
              <i class="material-icons mdl-list__item-avatar">person</i>
              <span>Aaron Paul</span>
          </span>
          <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">add</i></a>
        </div>
        <div class="mdl-list__item">
          <span class="mdl-list__item-primary-content">
              <i class="material-icons mdl-list__item-avatar">person</i>
              <span>Bob Odenkirk</span>
          </span>
          <span class="mdl-list__item-secondary-content">
              <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a>
            </span>
        </div>
      </div>
    </div>
  </div>
  <div class="mdl-sheet mdl-shadow--2dp">
    <i class="material-icons mdl-sheet__icon">add</i>
    <div class="mdl-sheet__content">
      <div class="mdl-list">
        <div class="mdl-list__item">
          <span class="mdl-list__item-primary-content">
              <i class="material-icons mdl-list__item-avatar">person</i>
              <span>Bryan Cranston</span>
          </span>
          <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">add</i></a>
        </div>
        <div class="mdl-list__item">
          <span class="mdl-list__item-primary-content">
              <i class="material-icons mdl-list__item-avatar">person</i>
              <span>Aaron Paul</span>
          </span>
          <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">add</i></a>
        </div>
        <div class="mdl-list__item">
          <span class="mdl-list__item-primary-content">
              <i class="material-icons mdl-list__item-avatar">person</i>
              <span>Bob Odenkirk</span>
          </span>
          <span class="mdl-list__item-secondary-content">
              <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons">star</i></a>
            </span>
        </div>
      </div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;