html - HTML 元素在打开后移动
问题描述
奇怪的事情正在发生。
页面加载完成后,将显示此选项菜单
但是,如果您关闭菜单然后打开它,菜单将如下所示:
这很奇怪。这里的代码:
<div id="elegir-personaje" class="popUp">
<button onClick="cerrarElemento(this.parentElement);">x</button>
<fieldset>
<legend>sombrero</legend>
<label><img src="Images/sombrero.png" class="player" /><input type="checkbox" /></label>
<label><input type="text" /></label>
</fieldset>
<!-- More fieldset -->
</div>
.popUp {
box-sizing: border-box;
max-height: 500px;
padding: 10px;
overflow-y: auto;
background-color: #d6ebd5;
box-shadow: 0px 1px 10px 1px #8faa8e;
position: absolute;
top: 50%;
left: 50%;
z-index: 99;
transform: translate(-50%, -50%);
}
/**
*
* @param {HTMLElement} elemento
*/
function cerrarElemento(elemento) {
elemento.style.display = "none";
}
/**
*
* @param {HTMLElement} elemento
*/
function abrirElemento(elemento) {
elemento.style.display = "block";
}
解决方案
推荐阅读
- c - 有人可以解释这个 C 程序的输出吗?
- python - 使用 Python(最好是请求)从 Binance API 获取烛台/Kline 数据以获取 JSON 数据
- c - 使用 void* 更改字符
- go - 自定义处理程序(仅在特定 url 上使用)在 go 中是惯用的吗
- python - Pandas 在应用中就地操作
- elasticsearch - Kibana 在 path.data 中存储了哪些持久化数据?
- javascript - 在新选项卡屏幕中使用 AsyncStorage 加载数据
- javascript - 从 iframe 切换回 Angular App 对我不起作用
- javascript - 我的菜单仍然打开
- shell - 使用 n 次出现时 sed 怀疑