我檢查了很多關于 SO 的問題,其中很多問題都解決了我想要的問題,其他人建議使用absolute和relative我嘗試過的方法,但無濟于事。
我有一個受此啟發的自定義下拉選單:https : //www.w3schools.com/howto/howto_js_autocomplete.asp
我在疊加層中使用此下拉串列,但實際上如果我有很多元素,我的串列不會超出 div:
.content {
flex-grow: 1;
display: flex;
height: 85%;
}
.tool {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
}
.overlay {
z-index: 200;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.fondOverlay {
background-color: rgba(10, 10, 10, 0.8);
height: 100%;
width: 100%;
position: absolute;
z-index: 199;
}
.contenuFormulaireOverlay {
width: 40%;
overflow: hidden;
min-height: 30%;
max-height: 60%;
padding: 20px;
margin: 20px;
border: 2px solid white;
font-variant: small-caps;
border-radius: 30px;
background-color: rgba(255, 255, 255, 0.8);
z-index: 201;
display: flex;
font-size: 1.2em;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.contenuFormulaireOverlay > div {
height: 100%;
width: 100%;
overflow-y: auto;
overflow-x: hidden;
}
.contenuFormulaireOverlay > div > div {
width: 100%;
text-align: left;
margin: 5px;
}
.autocomplete * {
box-sizing: border-box;
}
* {
box-sizing: border-box;
}
.autocomplete {
position: relative;
/* display: inline-block; */
overflow: visible;
width: 90%;
}
input {
border: 1px solid transparent;
background-color: #f1f1f1;
padding: 10px;
font-size: 1em;
}
input[type=text] {
background-color: #f1f1f1;
width: 100%;
}
.autocomplete-items {
position: absolute;
border: 1px solid #d4d4d4;
border-bottom: none;
border-top: none;
z-index: 99;
/*position the autocomplete items to be the same width as the container:*/
top: 100%;
left: 0;
right: 0;
text-align: left;
}
.autocomplete-items div {
padding: 10px;
cursor: pointer;
background-color: #fff;
border-bottom: 1px solid #d4d4d4;
}
.autocomplete-items div:hover {
/*when hovering an item:*/
background-color: #e9e9e9;
}
.autocomplete-active {
/*when navigating through the items using the arrow keys:*/
background-color: DodgerBlue !important;
color: #ffffff;
}
<div class="content">
<div class="tool">
<header>
<h1>TITLE</h1>
</header>
<div class="realContent">
THE CONTENT
</div>
</div>
<!--v-if-->
<div class="overlay">
<div class="fondOverlay"></div>
<div class="contenuFormulaireOverlay">
<div>
<div>
<label>POC:</label>
<div class="autocomplete">
<input type="text" placeholder="Write something...">
<div class="autocomplete-items">
<div>
<span> ?? 123456 - AAA </span>
</div>
<div>
<span > ?? 100000 - BBB </span>
</div>
<div>
<span> ?? CCC</span>
</div>
<div>
<span> ?? DDD</span>
</div>
<div>
<span> ?? EEE</span>
</div>
</div>
</div>
</div>
<span class="button"> Add </span>
</div>
</div>
</div>
</div>
我想要的是下拉選單在 div 之外,在所有東西的前面。我試過了,z-index但它也不起作用......
uj5u.com熱心網友回復:
目前我設法做到了這一點,但我仍然不完全滿意。我不知道為什么,但感覺這不是一個好的答案:
.content {
flex-grow: 1;
display: flex;
height: 85%;
}
.tool {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
}
.overlay {
z-index: 200;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.fondOverlay {
background-color: rgba(10, 10, 10, 0.8);
height: 100%;
width: 100%;
position: absolute;
z-index: 199;
}
.contenuFormulaireOverlay {
width: 40%;
overflow: hidden;
min-height: 30%;
max-height: 60%;
padding: 20px;
margin: 20px;
border: 2px solid white;
font-variant: small-caps;
border-radius: 30px;
background-color: rgba(255, 255, 255, 0.8);
z-index: 201;
display: flex;
font-size: 1.2em;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.contenuFormulaireOverlay > div {
height: 100%;
width: 100%;
overflow-y: auto;
overflow-x: hidden;
}
.contenuFormulaireOverlay > div > div {
width: 100%;
text-align: left;
margin: 5px;
}
.autocomplete * {
box-sizing: border-box;
}
.autocomplete {
overflow: visible;
width: 90%;
}
input {
border: 1px solid transparent;
background-color: #f1f1f1;
padding: 10px;
font-size: 1em;
}
input[type=text] {
background-color: #f1f1f1;
width: 100%;
}
.autocomplete-items {
position: absolute;
border: 1px solid #d4d4d4;
border-bottom: none;
border-top: none;
z-index: 99;
text-align: left;
}
.autocomplete-items div {
padding: 10px;
cursor: pointer;
background-color: #fff;
border-bottom: 1px solid #d4d4d4;
}
.autocomplete-items div:hover {
/*when hovering an item:*/
background-color: #e9e9e9;
}
.autocomplete-active {
/*when navigating through the items using the arrow keys:*/
background-color: DodgerBlue !important;
color: #ffffff;
}
<div class="content">
<div class="tool">
<header>
<h1>TITLE</h1>
</header>
<div class="realContent">
THE CONTENT
</div>
</div>
<!--v-if-->
<div class="overlay">
<div class="fondOverlay"></div>
<div class="contenuFormulaireOverlay">
<div>
<div>
<label>POC:</label>
<div class="autocomplete">
<input type="text" placeholder="Write something...">
<div class="autocomplete-items">
<div>
<span> ?? 123456 - AAA </span>
</div>
<div>
<span > ?? 100000 - BBB </span>
</div>
<div>
<span> ?? CCC</span>
</div>
<div>
<span> ?? DDD</span>
</div>
<div>
<span> ?? EEE</span>
</div>
</div>
</div>
</div>
<span class="button"> Add </span>
</div>
</div>
</div>
</div>
uj5u.com熱心網友回復:
希望我明白你的要求......我添加
.autocomplete-items { width: 100%; position: relative; }
到你的最后一個片段......
.content {
flex-grow: 1;
display: flex;
height: 85%;
}
.tool {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
}
.overlay {
z-index: 200;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.fondOverlay {
background-color: rgba(10, 10, 10, 0.8);
height: 100%;
width: 100%;
position: absolute;
z-index: 199;
}
.contenuFormulaireOverlay {
width: 40%;
overflow: hidden;
min-height: 30%;
max-height: 60%;
padding: 20px;
margin: 20px;
border: 2px solid white;
font-variant: small-caps;
border-radius: 30px;
background-color: rgba(255, 255, 255, 0.8);
z-index: 201;
display: flex;
font-size: 1.2em;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.contenuFormulaireOverlay > div {
height: 100%;
width: 100%;
overflow-y: auto;
overflow-x: hidden;
}
.contenuFormulaireOverlay > div > div {
width: 100%;
text-align: left;
margin: 5px;
}
.autocomplete * {
box-sizing: border-box;
}
.autocomplete {
overflow: visible;
width: 90%;
}
input {
border: 1px solid transparent;
background-color: #f1f1f1;
padding: 10px;
font-size: 1em;
}
input[type=text] {
background-color: #f1f1f1;
width: 100%;
}
.autocomplete-items {
width: 100%;
position: relative;
border: 1px solid #d4d4d4;
border-bottom: none;
border-top: none;
z-index: 99;
text-align: left;
}
.autocomplete-items div {
padding: 10px;
cursor: pointer;
background-color: #fff;
border-bottom: 1px solid #d4d4d4;
}
.autocomplete-items div:hover {
/*when hovering an item:*/
background-color: #e9e9e9;
}
.autocomplete-active {
/*when navigating through the items using the arrow keys:*/
background-color: DodgerBlue !important;
color: #ffffff;
}
<div class="content">
<div class="tool">
<header>
<h1>TITLE</h1>
</header>
<div class="realContent">
THE CONTENT
</div>
</div>
<!--v-if-->
<div class="overlay">
<div class="fondOverlay"></div>
<div class="contenuFormulaireOverlay">
<div>
<div>
<label>POC:</label>
<div class="autocomplete">
<input type="text" placeholder="Write something...">
<div class="autocomplete-items">
<div>
<span> ?? 123456 - AAA </span>
</div>
<div>
<span > ?? 100000 - BBB </span>
</div>
<div>
<span> ?? CCC</span>
</div>
<div>
<span> ?? DDD</span>
</div>
<div>
<span> ?? EEE</span>
</div>
</div>
</div>
</div>
<span class="button"> Add </span>
</div>
</div>
</div>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/346580.html
上一篇:居中:從邊界到容器末端?[復制]
