css - HTML 中的组件对齐方式不符合我对齐的顺序

标签 css angular

元素文件的目的是使用 @keyframe 练习 CSS 动画以及在 Angular2 中显示一些不同的组件;我开始同时学习 CSS 和 Angular2。

问题是我在<app-root>中设置的标签顺序在 Web 浏览器上加载时不应用模板。 <contents>模板必须在中间,但它出现在 <bottomline> 下方.

<body> index.html 的标签有<app-root>只有瀑布背景图像也在这个文件中处理。

这是<app-root>的神殿.

<titlebar></titlebar>
<contents></contents>
<bottomline></bottomline>

所以 <contents>应该在中间但结果如下:

enter image description here

<titlebar><bottomline>具有相同的结构;唯一的两个区别是 <div> 中的文本标签和类选择器的名称。

<div class="titlebar">
    titlebar!
</div>

这是 titlebar.component.css .

div.titlebar{
    width: 100%;
    height: 50px;
    margin: 0 0 0 0;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
}

body.component.html , .ts 中的选择器名称设置为 <contents> :

<div class="outer">
    <div class="middle">
        <div class="inner">

        </div>
    </div>
</div>

这个是body.component.css .我复制了.outer , .middle , 和 .inner本网站问题中的选择器将 <div> 居中标签。我不认为动画会造成问题;当我将动画代码设置为评论时,想法并没有变得更好。

.outer {
    display: table;
    position: absolute;
    height: 100%;
    width: 100%;}

.middle {
    display: table-cell;
    vertical-align: middle;}

.inner {
    animation-duration: 3s;
    animation-name: mainbox;
    animation-iteration-count: 1;

    margin-left: auto;
    margin-right: auto; 
    width: 80%;
    height: 80%;
    background: rgba(0, 0, 0, 0.55);
}

@keyframes mainbox{
    from{
        background: rgba(0, 0, 0, 0);
        height: 0%;
    }

    to{
        background: rgba(0, 0, 0, 0.55);
        height: 80%;
    }
}

以我的常识,没有理由 <contents><bottomline>标签来切换位置。我错过了什么?

最佳答案

可能是因为 position: absolute - 为了测试它,将位置更改为 relativeinherent 或其他东西 - 这就是为什么发生是因为当你把某件事变得绝对时——你基本上是在把它从它的自然流动中拿走。把它想象成不仅把它拿出来,而且把它漂浮在上面 - 允许其他东西填充它后面的空间,这就是为什么你期望在它下面的元素 - 已经向上移动了。

关于css - HTML 中的组件对齐方式不符合我对齐的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42685462/

相关文章:

angular - 如何向输入字段添加验证,以便多个输入字段不应该有相同的值?

javascript - angular 中 .next() 函数的解释

javascript - Onclick - 向下微调 div

css - 是否有 "previous sibling"选择器?

jquery - Codrops - Jmpress.js响应式特性//识别函数和方法

angular - Subject.complete() 是否取消订阅所有听众?

angular - Angular Intercept catcherror还捕获除404之外的其他错误,并阻止了应用程序按原样工作

html - 将标题分为移动应用程序的 3 列(按钮、标题、按钮)

html - 用文本扩展 CSS 形状

选项卡主体内的 Angular Material sidenav