gpt4 book ai didi

html - 按钮上的 Angular ngHide 在它原来的位置留下空间

转载 作者:太空宇宙 更新时间:2023-11-03 23:04:54 25 4
gpt4 key购买 nike

在这个 html 文件的页脚中,我有 3 个按钮。

第一张图片显示了 3 个按钮的排列方式。
第二张图片显示的是页脚中间按钮被注释掉的情况。
第三张图片是当中间按钮上的 ng-hide="true"时。

当中间是 ngHide(n) 时,如何让 No 和 YES 按钮之间没有空格?谢谢

enter image description here

* {
margin: 0;
padding: 0;
}

html {
height: 100%;
}

body {
height: 1%;
}

header > button {
height: 1.5em;
width: 1.5em;
font-size: 1.5em;
top: 0;
}

label.pageTitle {
display: inline-block;
width: calc(100% - 5em);
text-align: center;
}

header {
border-bottom: 1px solid black;
width: 100%;
position: fixed;
top: 0;
}

main, .mainMenu {
position: absolute;
top: 2.5em;
}

main {
z-index: -2;
width: 100%;
}

footer {
position: fixed;
bottom: 0;
width: 100%;
}

footer > button {
font-size: 1em;
padding: 0.5em 1em;

}
section {
text-align: center;
}
input {
font-size: 1em;
padding: 0.25em;
margin: 0.5em;
width: 90%;
}

header, footer {
background-color: white;
}

.horizontal-style {
display: table;
width: 100%
}
.horizontal-style li {
display: table-cell;
padding: 2px;
}
.horizontal-style button {
display: block;
border: 1px solid black;
text-align: center;
background: #dfdfdf;
}

footer button {
width: 100%;
border-radius: 6px;
font-size: 1.5em;
}

.mainMenu {
padding-left: 1em;
background-color: #dfdfdf;
width: 70%;
border-radius: 0 6px 10px 0;
z-index: -1;
}

ul {
list-style-type: none;
}

ul li img {
vertical-align: middle;
padding-right: 0.25em;
}

a {
display: block;
padding: 1em 0em;
}
<!doctype html>
<html lang="en" ng-app="appModule">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="index.css">
<meta name="viewport" content="width=device-width" />

<base href="http://localhost:63342/students/">

<!--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js"></script>-->
<!--<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-route.js"></script>-->
<script src="angular.js"></script>
<script src="angular-route.js"></script>

<script src="app.js"></script>

<script src="services/routing.js"></script>
<script src="services/menuToggle.js"></script>

<script src="controllers/menuToggleCtrl.js"></script>
<script src="controllers/mainMenuCtrl.js"></script>
<script src="controllers/page1Ctrl.js"></script>
<script src="controllers/page2Ctrl.js"></script>
</head>

<body>
<header ng-controller="MenuToggleCtrl">
<button class="menuLeft" type="button" ng-model="clicked" ng-click="menuToggle()">&#9776;</button>
<label id="pageTitle" class="pageTitle">Select item from list</label>
<button class="menuRight" type="button">&#8942;</button>
</header>

<section class="mainMenu" ng-controller="MainMenuCtrl" ng-if="!clicked">
<ul>
<li ng-repeat="item in menuItems">
<a href="#/{{item.name}}">
<image ng-src="images/{{item.image}}.png"></image>
{{item.name}}
</a>
</li>
</ul>
</section>

<main ng-view></main>

<footer ng-controller="MenuToggleCtrl" ng-if="clicked">
<ul class="horizontal-style">
<li><button type="button">NO</button></li>
<li><button type="button">EXTRA</button></li>
<!--<li><button type="button">EXTRA</button></li>-->
<!--<li><button type="button" ng-hide="true">EXTRA</button></li>-->
<li><button type="button">YES</button></li>
</ul>
</footer>

</body>
</html>

最佳答案

通过对 li 元素应用 ng-hide 隐藏整个 li。

<li ng-hide={{expression}}><button type="button">EXTRA</button></li>

注意:您也可以使用 ng-if而不是 ng-hide这将完全删除 <li>来自 DOM,并且可以证明容器内有大量内容的性能。

关于html - 按钮上的 Angular ngHide 在它原来的位置留下空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35061437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com