gpt4 book ai didi

css - 使用 AngularJS 路由时的最小高度 css 问题

转载 作者:行者123 更新时间:2023-11-28 17:00:53 25 4
gpt4 key购买 nike

我在一个简单的 html 文件中有以下配置:

* {
box-sizing: border-box;
}

html, body {

height: 100%;
min-height: 100%;
margin: 0;
}

section {
display: block;
width: 100%;
min-height: 100%;
padding: 1em
}

.b1 {
background: #2AC56D
}
.b2 {
background: #fae10c
}
.b3 {
background: #03a9f4
}
<section class="b1">1
</section>
<section class="b2">2
</section>
<section class="b3">3
</section>

然后我尝试按以下方式使用 AngularJS 路由:部分元素进入名为 template.html 的模板,如下所示:

<section class="b1">1
</section>
<section class="b2">2
</section>
<section class="b3">3
</section>

然后我将 AngularJS、ng-route 依赖项和以下脚本添加到主文件中,如下所示:

<script src="js/angular.min.js"></script>
<script src="js/angular-route.min.js"></script>
<script>
var app = angular.module('app', ['ngRoute']);
app.config(function($routeProvider, $locationProvider) {
$routeProvider.when('/', {
templateUrl: 'template.html'
}).otherwise({
redirectTo: '/'
});
});
</script>
</head>
<body data-ng-app="app">
<div data-ng-view>
</div>
</body>

它正在处理脚本部分,但 section 元素不再是全高,看起来像这样。

enter image description here

真正的问题是什么,更重要的是,我该如何纠正它?我真正需要的是至少有一些 divsection 的全屏高度。

谢谢。

最佳答案

嗯,要使 height: 100%; 正常工作,您还需要在其父 div 中进行设置。

假设这个 html:

<div id="main">
<section>1</section>
</div>

然后仅在部分中应用 100% 高度是行不通的。您需要为父元素设置固定高度。所以,使用:

#main{
height: 100%;
}

你已经在 html 中设置了 100% 高度,body 标签很好。


所以,在你的情况下,像这样申请:

div[data-ng-view]{
height: 100%;
}

关于css - 使用 AngularJS 路由时的最小高度 css 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31309416/

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