Javascript Div height始终为零-如何使其自动假定高度

Javascript Div height始终为零-如何使其自动假定高度,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想在我的网站上显示通知,这个插件似乎是一个合适的解决方案。然而,问题是节的高度始终为零,因为它不会向下推它后面的任何内容,而是出现在同一个节上 HTML: 我如何确保该部分自动假定其高度,并按应有的方式向下推送所有内容 我刚检查了一下你的小提琴,发现你的。a有位置:绝对

我想在我的网站上显示通知,这个插件似乎是一个合适的解决方案。然而,问题是节的高度始终为零,因为它不会向下推它后面的任何内容,而是出现在同一个节上

HTML:



我如何确保该部分自动假定其高度,并按应有的方式向下推送所有内容

我刚检查了一下你的小提琴,发现你的
。a
位置:绝对

如果我从中删除position,它会工作,但看起来很难看,因为您使用了
可见性:hidden
。我删除了可见性,并将“显示无/块”改为与活动类一起使用

现在它看起来像它应该是好的。 这是我用两个类修改的代码

.awNotices a {
  /* position: absolute; */
  /* visibility: hidden; */
  display: none;
}
.awNotices a.active {
  /* visibility: visible; */
  display: block;
}

上面的代码只显示了更改后的特定CSS属性,您必须包含其他类属性才能获得预期的结果。请看一下我更新的

欢迎建议任何其他插件/解决方案在站点上显示(响应)通知。
$('.awNotices').append('<span class="controller fa fa-pause"></span>');
$('.awNotices a:nth-of-type(1)').addClass('active');

function awNotice() {
  if (!$('.awNotices').hasClass('stopped')) {
    var $active = $('.awNotices a.active');
    var $next = $active.next('a');

    if ($next.length) {
      $next.addClass('active');
      $active.removeClass('active');
    } else {
      $active.removeClass('active');
      $('.awNotices a:first-of-type').addClass('active');
    }
  }
}

$('.awNotices .controller').click(function () {
  $(this).toggleClass('fa-pause fa-play');
  $('.awNotices').toggleClass('stopped');
})

function awNotices(timer) {
  setInterval("awNotice()", timer);
}

awNotices(2000);
.awNotices a {
  /* position: absolute; */
  /* visibility: hidden; */
  display: none;
}
.awNotices a.active {
  /* visibility: visible; */
  display: block;
}