我使用overflow: hidden
让我的布局流畅。请参阅(以下代码)名为Dropdown Menu
的右上角按钮。这是需要修复的问题。
请参阅以下代码以供参考。
* {
padding: 0;
margin: 0;
}
*:focus {
outline: 0;
}
*,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
a {
text-decoration: none;
color: inherit;
}
body {
font: 14px/18px Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.float-left {
float: left;
}
.float-right {
float: right;
}
.dropdown-box {
position: relative;
}
.dropdown-box:hover .dropdown-menu {
display: block;
}
.dropdown-menu {
display: none;
position: absolute;
top: 100%;
left: 0;
}
.overlay-block {
display: none;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
position: absolute;
top: 0;
left: 0;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
transition: all 0.2s;
}
.position-center {
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
position: absolute;
top: 50%;
left: 50%;
}
.profile-header {
display: block;
}
.profile-cover {
height: 100px;
background-color: rgba(0, 0, 0, 0.5);
}
.profile-header-content {
padding-bottom: 15px;
margin-top: -72px;
position: relative;
}
.profile-header-content:after {
content: '';
clear: both;
display: block;
}
.profile-user-image,
.profile-user-video {
width: 140px;
height: 140px;
background-color: rgba(234, 234, 234, 0.5);
color: #fff;
padding: 5px;
margin: 0 15px;
overflow: hidden;
position: relative;
}
.profile-user-image:hover .overlay-block,
.profile-user-video:hover .overlay-block {
display: block;
}
.profile-user-image:active .overlay-block,
.profile-user-video:active .overlay-block {
background: rgba(0, 0, 0, 0.95);
}
.profile-user-image img,
.profile-user-video img {
display: block;
width: 100%;
}
.profile-center-content {
overflow-x: hidden;
overflow-y: visible !important;
}

<div class="profile-header">
<div class="profile-cover"> </div>
<div class="profile-header-content">
<a class="profile-user-image float-left" href="javascript:;">
<div class="overlay-block">
<div class="position-center">Overlay</div>
</div>
</a>
<a class="profile-user-video float-right" href="javascript:;">
<div class="overlay-block">
<div class="position-center">Overlay</div>
</div>
</a>
<div class="profile-center-content">
<div class="float-left">
Lorem Ipsum
</div>
<div class="float-right">
<div class="dropdown-box">
<a href="javascript:;" class="toggle-dropdown">Dropdown Menu</a>
<ul class="dropdown-menu">
<li><a href="#Home">Home</a>
</li>
<li><a href="#About">About</a>
</li>
<li><a href="#Services">Services</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
&#13;
答案 0 :(得分:0)
当您使用position: absolute;
时,该元素超出了范围。所以请将其从.dropdown-menu
中移除,以使其保持在profile-center-content
的范围内,并且不会被考虑在内,以便滚动。
* {
padding: 0;
margin: 0;
}
*:focus {
outline: 0;
}
*,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
a {
text-decoration: none;
color: inherit;
}
body {
font: 14px/18px Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.float-left {
float: left;
}
.float-right {
float: right;
}
.dropdown-box {
position: relative;
}
.dropdown-box:hover .dropdown-menu {
display: block;
}
.dropdown-menu {
display: none;
}
.overlay-block {
display: none;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
position: absolute;
top: 0;
left: 0;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
transition: all 0.2s;
}
.position-center {
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
position: absolute;
top: 50%;
left: 50%;
}
.profile-header {
display: block;
}
.profile-cover {
height: 100px;
background-color: rgba(0, 0, 0, 0.5);
}
.profile-header-content {
padding-bottom: 15px;
margin-top: -72px;
position: relative;
}
.profile-header-content:after {
content: '';
clear: both;
display: block;
}
.profile-user-image,
.profile-user-video {
width: 140px;
height: 140px;
background-color: rgba(234, 234, 234, 0.5);
color: #fff;
padding: 5px;
margin: 0 15px;
overflow: hidden;
position: relative;
}
.profile-user-image:hover .overlay-block,
.profile-user-video:hover .overlay-block {
display: block;
}
.profile-user-image:active .overlay-block,
.profile-user-video:active .overlay-block {
background: rgba(0, 0, 0, 0.95);
}
.profile-user-image img,
.profile-user-video img {
display: block;
width: 100%;
}
.profile-center-content {
overflow-x: hidden;
overflow-y: visible !important;
}
<div class="profile-header">
<div class="profile-cover"> </div>
<div class="profile-header-content">
<a class="profile-user-image float-left" href="javascript:;">
<div class="overlay-block">
<div class="position-center">Overlay</div>
</div>
</a>
<a class="profile-user-video float-right" href="javascript:;">
<div class="overlay-block">
<div class="position-center">Overlay</div>
</div>
</a>
<div class="profile-center-content">
<div class="float-left">
Lorem Ipsum
</div>
<div class="float-right">
<div class="dropdown-box">
<a href="javascript:;" class="toggle-dropdown">Dropdown Menu</a>
<ul class="dropdown-menu">
<li><a href="#Home">Home</a>
</li>
<li><a href="#About">About</a>
</li>
<li><a href="#Services">Services</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>