菜单内容不会在Safari for iOS中溢出它的父级

时间:2016-09-11 12:40:05

标签: ios css twitter-bootstrap-3 overflow mobile-safari

我在网站上使用Bootstrap 3创建了一个菜单。 此菜单适用于我测试的每个浏览器,以及任何屏幕尺寸。

除iOS上的Safari外,菜单根本没有显示。

使用CSS,我强制菜单的容器填充宽度,并且高640像素。然后我可以看到菜单。所以问题似乎是溢出。

然而,容器父和祖父母有一个累积的填充,这在任何浏览器(我测试过)中都没有区别,除了iOS上的Safari。 这可以在screetshot number 2中看到。

清除某些字词

菜单正在引用ID为<ul>的{​​{1}}元素。这在下面的屏幕截图中标记为RED。

引用了类header-menu的immidiate parent。这在下面的屏幕截图中标记为蓝色。

重新创建问题

我终于可以通过向父级添加navbar-ex1-collapse来重新创建Chrome中的相同问题。

屏幕截图

Screenshot of menu in Chrome

Screenshot of menu in Safari on iOS

Screenshot of the menu and container code

查看代码段:

&#13;
&#13;
position: absolute;
&#13;
	(function($){
		$("#header-menu .menu-item-has-children > a, #header-menu .menu-item-has-children > span.after").on('click', function(e) {
			e.preventDefault();
			if( $(this).parent().hasClass('hide-sub') ){
				$(this).parent().addClass("show-sub").removeClass("hide-sub");
			}else{
				$(this).parent().addClass("hide-sub").removeClass("show-sub");
			}
		});
		
		$("#header-menu .close-menu-button > span.before").on('click', function(e) {
			e.preventDefault();
			if( $(this).parent().parent().parent().hasClass('hide-sub') ){
				$(this).parent().parent().parent().addClass("show-sub").removeClass("hide-sub");
			}else{
				$(this).parent().parent().parent().addClass("hide-sub").removeClass("show-sub");
			}
		});
	})(jQuery);
	
	
	
&#13;
@charset "utf-8";

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');


#header-menu {
  float: right
}




@media (max-width: 991px) {
  .navbar-default .navbar-toggle {
    background: rgba(255, 255, 255, 0.05);
    border: 0 none;
    border-radius: 0
  }
  .navbar-default .navbar-toggle .icon-bar {
    background-color: #d23479
  }
  .navbar-default .navbar-toggle:hover .icon-bar,
  .navbar-default .navbar-toggle:focus .icon-bar {
    background-color: #fff
  }
  .navbar-default .navbar-toggle:hover,
  .navbar-default .navbar-toggle:focus {
    background-color: #d23479
  }
  .navbar-default .navbar-collapse,
  .navbar-default .navbar-form {
    background: rgba(255, 255, 255, 0.25);
    border: 0;
    box-shadow: none
  }
  .navbar-collapse {
    margin-top: 10px
  }
}
@media(max-width:991px) {
  .navbar-nav>li>a {
    line-height: 70px;
  }
  .nav>li {
    font-size: 35px;
  }
  .navbar-nav {
    width: 100%;
    text-align: center;
    margin: 0px;
  }
}





/*meny*/

@media (min-width: 992px) {
  #header-menu .only-mobile,
  #header-menu a span {
    display: none !important;
  }
  #header-menu > li {
    position: static;
  }
  #header-menu > li > a {
    display: inline-block;
  }
  #header-menu > li > a:active {
    color: #d23479;
  }
  #header-menu > li > a:focus {
    color: white;
  }
  #header-menu > li > ul.sub-menu {
    display: block;
    background-color: white;
    padding: 30px;
    width: 100%;
    height: 100vh;
    min-height: 640px;
    max-height: 768px;
    position: absolute;
    z-index: 100;
    left: 0;
  }
  #header-menu > li > ul.sub-menu > li {
    display: table;
    width: 100%;
  }
  #header-menu > li > ul.sub-menu > li > ul.sub-menu {
    display: table-row;
  }
  #header-menu > li > ul.sub-menu > li > ul.sub-menu > li {
    display: table-cell;
    width: 25%;
    padding: 15px;
  }
  #header-menu > li > ul.sub-menu > li > ul.sub-menu > li:first-of-type {
    padding: 15px 15px 15px 0;
  }
  #header-menu > li > ul.sub-menu > li > ul.sub-menu > li:last-of-type {
    padding: 15px 0 15px 15px;
  }
  #header-menu > li > ul.sub-menu > li.sub-menu-row:first-of-type > ul.sub-menu > li a {
    display: block;
    padding: 5px;
  }
  #header-menu > li > ul.sub-menu > li > ul.sub-menu > li > a {
    font-size: 14px;
    color: black;
    border-width: 0 0 1px 0;
    border-style: solid;
    margin: 0 0 10px 0;
    font-weight: 600;
    border-color: #d23479;
    text-transform: uppercase;
  }
  #header-menu > li > ul.sub-menu > li > ul.sub-menu > li > ul.sub-menu > li {
    width: 100%;
  }
  #header-menu > li > ul.sub-menu > li > ul.sub-menu > li > ul.sub-menu > li > a {
    color: gray;
    font-size: 12px;
  }
  #header-menu .sub-menu-row {
    display: block;
    width: 100%;
  }
  #header-menu .sub-menu-row:nth-of-type(2) {
    margin-top: 50px;
    border-width: 1px 0 0 0;
    border-color: lightgray;
    border-style: solid;
  }
  #header-menu .sub-menu-row:nth-of-type(2) > ul.sub-menu > li > a {
    text-transform: none;
    font-weight: 300 !important;
    border: none;
  }
  #header-menu .contact a {
    color: #d23479 !important;
  }
  #header-menu [class*="icon-"]:before {
    font-size: 26px;
    color: #d23479;
    float: left;
    margin: 0 10px;
    position: relative;
  }
  #header-menu > .menu-item-has-children > span {
    cursor: pointer;
  }
  #header-menu > .menu-item-has-children > span:after {
    margin: 0 0 0 5px;
    display: inline-block;
  }
  #header-menu > .menu-item-has-children.hide-sub > span.after:before {
    content: '';
    background-image: url('https://boxdev.no/box/wp-content/themes/box/icons/DropDown-Arrow.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center center;
    display: inline-block;
    width: 15px;
    height: 15px;
  }
  #header-menu > .menu-item-has-children.show-sub > span.after:before {
    background: none;
    content: '×';
    font-size: 27px;
    font-weight: 300;
    line-height: 1.2em;
    font-family: serif;
    vertical-align: middle;
    color: #d23479;
  }
  #header-menu > .menu-item-has-children.hide-sub > .sub-menu {
    display: none;
  }
  #header-menu > .menu-item-has-children.show-sub > .sub-menu {
    display: block;
  }
  #header-menu .sub-menu .close-menu-button {
    display: block;
    position: absolute;
    bottom: 130px;
  }
  #header-menu .sub-menu .close-menu-button span.before {
    display: block;
    width: 100px;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
    cursor: pointer;
  }
  #header-menu .sub-menu .close-menu-button span.before:before {
    content: '×';
    color: #d23479;
    font-size: 42px;
    font-family: serif;
    font-weight: bold;
    line-height: 32px;
    display: block;
    width: 100px;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
  }
  #header-menu .sub-menu .close-menu-button span.before:after {
    content: 'Lukk meny';
    text-transform: uppercase;
    color: #ccc;
    font-size: 12px;
    display: block;
    width: 100px;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
  }
}
@media (max-width: 991px) {
  #header-menu button.navbar-toggle {
    display: inline-block;
    width: 42px;
    height: 32px;
    background-color: #d23479;
    position: absolute;
    top: 15px;
    right: 30px;
  }
  #header-menu button.navbar-toggle:before {
    content: '×';
    color: white;
    font-family: serif;
    font-size: 32px;
    vertical-align: top;
    line-height: 16px;
  }
  #header-menu {
    background-color: white;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100%;
    height: 100%;
    z-index: 10;
    overflow: scroll;
    margin-top: 0;
    padding: 102px 20px 20px 20px;
  }
  #header-menu .only-computer {
    display: none !important;
  }
  #header-menu > li,
  #header-menu .sub-menu li {
    text-align: left;
    border-top: 1px solid #ccc;
  }
  #header-menu .show-sub > ul.sub-menu {
    border-top: 1px solid #ccc;
  }
  #header-menu a {
    display: inline-block;
    line-height: 1.4em;
    text-transform: uppercase;
    font-weight: 400;
    padding: 0;
    color: #222;
    font-size: 18px;
  }
  #header-menu ul.sub-menu > li > ul.sub-menu > li > a {
    color: #444;
    font-size: 15px;
  }
  #header-menu ul.sub-menu > li > ul.sub-menu > li > ul.sub-menu > li > a {
    color: #666;
    font-size: 13px;
    font-weight: 300;
  }
  #header-menu > li > a:active,
  #header-menu > li.show-sub > a {
    color: #d23479;
  }
  #header-menu ul.sub-menu {
    padding-left: 15px;
  }
  #header-menu .menu-item-1350 > .sub-menu {
    padding: 0;
  }
  #header-menu .sub-menu-row {
    display: block;
    width: 100%;
  }
  #header-menu .sub-menu > li:first-of-type,
  #header-menu .sub-menu-row,
  #header-menu .bottom-contact-info,
  #header-menu .bottom-contact-info li {
    border: none !important;
  }
  #header-menu .menu-item-has-children.hide-sub span {
    display: none;
  }
  #header-menu .menu-item-has-children.hide-sub > a {} #header-menu .menu-item-has-children > a {
    width: 100%;
    display: inline-block;
    background-repeat: no-repeat;
    background-size: 22px 22px;
    background-position: 98% 50%;
  }
  #header-menu .menu-item-has-children.hide-sub > a {
    background-image: url('https://boxdev.no/box/wp-content/themes/box/icons/down-arrow-menu.png');
  }
  #header-menu .menu-item-has-children.show-sub > a {
    background-image: url('https://boxdev.no/box/wp-content/themes/box/icons/right-arrow-menu.png');
  }
  #header-menu .menu-item-has-children.hide-sub > .sub-menu {
    display: none;
  }
  #header-menu .menu-item-has-children.show-sub > .sub-menu {
    display: block;
  }
  #header-menu > li:first-of-type,
  #header-menu .bottom-contact-info > .sub-menu {
    border-top: 1px solid #d23479;
    padding: 0;
  }
  #header-menu .bottom-contact-info a {
    color: #333;
  }
  #header-menu [class*="icon-"]:before {
    font-size: 20px;
    color: #d23479;
    margin: 0 10px;
    position: relative;
    text-transform: none;
  }
  #header-menu > .menu-item-has-children > span {
    cursor: pointer;
  }
  #header-menu > .menu-item-has-children > span:after {
    margin: 0 0 0 5px;
    display: inline-block;
  }
  #header-menu .inactive > a,
  #header-menu .inactive > span,
  #header-menu a span {
    display: none;
  }
  #header-menu .logo {
    position: absolute;
    top: 10px;
    left: 30px;
    border: 0;
  }
  #header-menu .logo > a {
    background-image: url('https://boxdev.no/box/wp-content/themes/box/images/logo.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    height: 34px;
    width: 167px;
  }
}
/* Fixing the menu for Safari on iOS */

.dropdown-backdrop {
  position: static !important;
}
.navbar-ex1-collapse {
  z-index: 99999;
}
.collapse.in {
  background-color: white;
  width: 100%;
  height: 640px;
  position: fixed;
  display: block;
  overflow: scroll;
  position: static !important;
}
#header-menu {
  z-index: 99999 !important;
  display: block;
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

尝试将导航栏定位明确设置为相对。在iOS上,似乎存在针对Safari的定位元素的反复出现的错误。