【问题标题】:CSS interrupt when use bootstrap使用引导程序时的 CSS 中断
【发布时间】:2014-10-21 13:20:49
【问题描述】:

我正在制作一个从 3 行转换为 x 的导航按钮

    var anchor = document.querySelectorAll('button');
    [].forEach.call(anchor, function(anchor) {
      var open = false;
      anchor.onclick = function(event) {
        event.preventDefault();
        if (!open) {
          this.classList.add('close');
          open = true;
        } else {
          this.classList.remove('close');
          open = false;
        }
      }
    });
html,
body {
  height: 100%;
}
body {
  background-color: white;
  font-family: "Source Sans pro", sans-serif;
}
#mbtn {
  display: inline-block;
  margin: 0 1em;
  border: none;
  background: none;
}
#mbtn span {
  display: block;
}
.lines-button {
  padding: 2rem 1rem;
  transition: .3s;
  cursor: pointer;
  /* */
}
.lines {
  display: inline-block;
  width: 4rem;
  height: 0.57143rem;
  background: #211f20;
  border-radius: 0.28571rem;
  transition: 0.3s;
  position: relative;
}
.lines:before,
.lines:after {
  display: inline-block;
  width: 4rem;
  height: 0.57143rem;
  background: #211f20;
  border-radius: 0.28571rem;
  transition: 0.3s;
  position: absolute;
  left: 0;
  content: '';
  -webkit-transform-origin: 0.28571rem center;
  transform-origin: 0.28571rem center;
}
.lines:before {
  top: 1rem;
}
.lines:after {
  top: -1rem;
}
.lines-button:hover .lines:before {
  top: 1.14286rem;
}
.lines-button:hover .lines:after {
  top: -1.14286rem;
}
.lines-button.close {
  -webkit-transform: scale3d(0.8, 0.8, 0.8);
  transform: scale3d(0.8, 0.8, 0.8);
}
.lines-button.x.close .lines {
  background: transparent;
}
.lines-button.x.close .lines:before,
.lines-button.x.close .lines:after {
  -webkit-transform-origin: 50% 50%;
  transform-origin: 50% 50%;
  top: 0;
  width: 4rem;
}
.lines-button.x.close .lines:before {
  -webkit-transform: rotate3d(0, 0, 1, 45deg);
  transform: rotate3d(0, 0, 1, 45deg);
}
.lines-button.x.close .lines:after {
  -webkit-transform: rotate3d(0, 0, 1, -45deg);
  transform: rotate3d(0, 0, 1, -45deg);
}
<button type="button" role="button" aria-label="Toggle Navigation" id="mbtn" class="lines-button x">
  <span class="lines"></span>
</button>

当我从 html 中删除 bootstrap.min.css 时它工作得很好,但是当我有我的 bootstrap css 时它会干扰实际的导航 css 并且不能正常工作

【问题讨论】:

    标签: html css twitter-bootstrap transition


    【解决方案1】:

    问题是因为 bootstrap 已经有 .close 类的样式,用任何其他名称替换 .close 类样式

    演示 - http://jsfiddle.net/Ah6XA/33/

    在这个小提琴中包含bootstrap.min.css

    .close 替换为.change

    var anchor = document.querySelectorAll('button');
    
    [].forEach.call(anchor, function (anchor) {
        var open = false;
        anchor.onclick = function (event) {
            event.preventDefault();
            if (!open) {
                this.classList.add('change');
                open = true;
            } else {
                this.classList.remove('change');
                open = false;
            }
        }
    });
    

    css 样式

    .lines-button.change {
        -webkit-transform: scale3d(0.8, 0.8, 0.8);
        transform: scale3d(0.8, 0.8, 0.8);
    }
    .lines-button.x.change .lines {
        background: transparent;
    }
    .lines-button.x.change .lines:before, .lines-button.x.change .lines:after {
        -webkit-transform-origin: 50% 50%;
        transform-origin: 50% 50%;
        top: 0;
        width: 4rem;
    }
    .lines-button.x.change .lines:before {
        -webkit-transform: rotate3d(0, 0, 1, 45deg);
        transform: rotate3d(0, 0, 1, 45deg);
    }
    .lines-button.x.change .lines:after {
        -webkit-transform: rotate3d(0, 0, 1, -45deg);
        transform: rotate3d(0, 0, 1, -45deg);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-21
      • 2023-03-30
      • 2014-12-14
      • 2016-04-21
      • 2012-01-30
      • 2014-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多