使用 Css 的响应式设计
Responsive design using Css
我想在我的 application.I 中使用 Angular Toaster 进行通知的弹出式通知的响应式设计。
例如,我将 toaster-container 元素定位在屏幕中央,但使用的是绝对位置,因此对于较小的屏幕,通知会保持在相同位置,因此不会显示。我想使通知相对于包含它们的父元素(在本例中为容器网格)。如何使用 CSS 实现该目标?这是我的 html 代码:
<body data-ng-controller="AppController">
<div id="container" class="container">
<toaster-container toaster-options="{'position-class': 'toast-container-custo','time-out': 3000, 'close-button':true}"></toaster-container>
<div id="header" data-ng-include="'partials/header/header.html'" ></div>
<div data-ng-view></div>
<div id="footer" data-ng-include="'partials/footer/footer.html'"></div>
<!-- This is the div with the overlay css class, so no matter where it is located this div inside the screen, it will cover the whole screen-->
<div id="loader" class="loading overlay" data-ng-if="loader.loading">
<p>We are loading the products. Please wait...</p>
<img alt="" src="images/ajax-loader.gif">
</div>
</div>
<div id="loginPanel" data-ng-include="'partials/content/panels/login.html'"></div>
</body>
以及我用于 toaster-container 元素的自定义 css 规则:
.toast-container-custo
{
position: absolute;
top:100px;
left: 780px;
}
- 使用百分比而不是像素
对于 width/height 和 top/left 值,您可以使用 百分比 使您的 div 与其容器相关。您在此处使用的百分比将与 父容器大小 相关。因此,如果您的父容器设置为 width:300px
,而您的子容器设置为 width:50%
,则子容器将呈现在 width:150px;
- 对元素使用相对定位。
相对定位,就是它在标签上所说的 - 它相对于其他元素定位元素。所以你还需要将元素设置为position:relative;
以下是我的处理方式:
.toast-container-custo{
position: relative;
margin: 0 auto;
width: 30%;
height:30px;
}
margin:0 auto
将居中
其容器内的子元素,水平
width
现在是父容器的 30%
height
,好吧,我只是更喜欢将其设置为固定的 px
值,但是
你也可以在这里定义 %
您可以将容器更改为:
.toast-container-custo{
position: absolute;
top: 100px;
margin-left: auto;
float: none;
margin-right: auto;
left: 0;
right: 0;
}
通常,这是将绝对元素水平居中的好方法。
我想在我的 application.I 中使用 Angular Toaster 进行通知的弹出式通知的响应式设计。
例如,我将 toaster-container 元素定位在屏幕中央,但使用的是绝对位置,因此对于较小的屏幕,通知会保持在相同位置,因此不会显示。我想使通知相对于包含它们的父元素(在本例中为容器网格)。如何使用 CSS 实现该目标?这是我的 html 代码:
<body data-ng-controller="AppController">
<div id="container" class="container">
<toaster-container toaster-options="{'position-class': 'toast-container-custo','time-out': 3000, 'close-button':true}"></toaster-container>
<div id="header" data-ng-include="'partials/header/header.html'" ></div>
<div data-ng-view></div>
<div id="footer" data-ng-include="'partials/footer/footer.html'"></div>
<!-- This is the div with the overlay css class, so no matter where it is located this div inside the screen, it will cover the whole screen-->
<div id="loader" class="loading overlay" data-ng-if="loader.loading">
<p>We are loading the products. Please wait...</p>
<img alt="" src="images/ajax-loader.gif">
</div>
</div>
<div id="loginPanel" data-ng-include="'partials/content/panels/login.html'"></div>
</body>
以及我用于 toaster-container 元素的自定义 css 规则:
.toast-container-custo
{
position: absolute;
top:100px;
left: 780px;
}
- 使用百分比而不是像素
对于 width/height 和 top/left 值,您可以使用 百分比 使您的 div 与其容器相关。您在此处使用的百分比将与 父容器大小 相关。因此,如果您的父容器设置为 width:300px
,而您的子容器设置为 width:50%
,则子容器将呈现在 width:150px;
- 对元素使用相对定位。
相对定位,就是它在标签上所说的 - 它相对于其他元素定位元素。所以你还需要将元素设置为position:relative;
以下是我的处理方式:
.toast-container-custo{
position: relative;
margin: 0 auto;
width: 30%;
height:30px;
}
margin:0 auto
将居中 其容器内的子元素,水平width
现在是父容器的 30%height
,好吧,我只是更喜欢将其设置为固定的px
值,但是 你也可以在这里定义%
您可以将容器更改为:
.toast-container-custo{
position: absolute;
top: 100px;
margin-left: auto;
float: none;
margin-right: auto;
left: 0;
right: 0;
}
通常,这是将绝对元素水平居中的好方法。