css - 溢出-y滚动导致内容被切断
问题描述
我目前有一个最大高度为 800 像素的容器。它也有溢出-y:滚动。我想要完成的事情很简单(可能不是那么简单,因此我问你们!)。
我想继续拥有这个溢出-y 滚动。但是,我的内容被切断了。我有一个带有 future-dropdown 类的 div,我希望里面的内容有目的地覆盖这个容器。如果你看一下代码片段,我在 div 中的内容会因为溢出-y 滚动而被截断。
我怎样才能解决这个问题并且仍然拥有这个?我仍然需要这个可滚动的容器,但我还需要一种方法来让我的内容仍然显示在那个位置。
请提出建议!
* {
padding: 0;
margin: 0;
}
.scroll-list {
max-height: 800px;
overflow-y: scroll;
border-radius: 5px;
border: 5px solid blue;
width: 400px;
}
li {
height: 200px;
width: 100%;
border-radius: 2px;
background-color: white;
font-size: 15px;
text-align: center;
list-style-type: none;
background: lightgray;
/* margin: 0 auto; */
}
.future-dropdown {
position: relative;
left: 200px;
}
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="index.css">
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div class="scroll-list">
<ul>
<li>Content <div class="future-dropdown">Future dropdown</div></li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
</ul>
</div>
<script src="" async defer></script>
</body>
</html>
解决方案
看看这个代码片段。
我添加了以下css,
.future-dropdown1 {
position: relative;
text-align: right;
}
.future-dropdown2 {
position: relative;
float: right;
margin-top: 20px;
}
由于定位div
withleft
属性会导致它从定义的像素位置开始,因此它被裁剪了。
* {
padding: 0;
margin: 0;
}
.scroll-list {
max-height: 800px;
overflow-y: scroll;
border-radius: 5px;
border: 5px solid blue;
width: 400px;
}
li {
height: 200px;
width: 100%;
border-radius: 2px;
background-color: white;
font-size: 15px;
text-align: center;
list-style-type: none;
background: lightgray;
/* margin: 0 auto; */
}
.future-dropdown1 {
position: relative;
text-align: right;
}
.future-dropdown2 {
position: relative;
float: right;
margin-top: 20px;
}
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="index.css">
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div class="scroll-list">
<ul>
<li>Content <div class="future-dropdown1">Future dropdown</div></li>
<li>Content <div class="future-dropdown2">Future dropdown</div></li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
<li>Content</li>
</ul>
</div>
<script src="" async defer></script>
</body>
</html>
推荐阅读
- android-studio - 如何在 Android Studio 或 Visual Studio Code 中找到未使用的颤振类
- java - Maven 依赖项为每个依赖项提供 ValidatorException 警告
- node.js - 从 postgresql 数据库列中删除空格不起作用
- apache-kafka - kafka 连接转换订购保证
- python - 如何在 AWS Lambda 上执行 Python REST API 测试套件
- neural-network - 在 PyTorch 中提取图像的编码表示?
- web-crawler - 从 Apache Nutch 清除数据
- asp.net - Visual Basic 编译器 (vbc.exe) 用完所有系统内存(RAM 和虚拟)
- excel - 如何将日期时间存储到 VBA 中的变量以保存在 Excel 数据库中
- angular - Summernote 在 Angular 8 中无法正确更改内容