[英]How to update the style of all the items which are iterated using *ngFor in Angular
[英]How to display items inline using angular's *ngFor
我正在嘗試內聯顯示項目,而不是出現在不同的行中。 請看下面的代碼和圖片。 我試圖在網上尋找解決方案,但其他人都在問不同的用例。 請告訴我。 謝謝!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<div class="pimg1">
<div class="ptext">
<span class="borderStyle">
Kenny's Site
</span>
</div>
</div>
<section class="section section-light">
<h2>Skills</h2>
<p class="skills" *ngFor="let skill of skills">{{skill.skill}}</p>
</section>
<div class="pimg2">
<div class="ptext">
<span class="borderStyle">
Image2 Text
</span>
</div>
</div>
<section class="section section-dark">
<h2>Section 1</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolores, saepe.</p>
</section>
<div class="pimg3">
<div class="ptext">
<span class="borderStyle">
Image3 Text
</span>
</div>
</div>
<section class="section section-dark">
<h2>Section 3</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolores, saepe.</p>
</section>
<div class="pimg1">
<div class="ptext">
<span class="borderStyle">
Kenny's Site
</span>
</div>
</div>
</div>
</body>
</html>
我認為這不是 angular 問題案例。 您需要管理 css 以使技能以 flex 或 grid 顯示。
也許你可以嘗試在一個 div 容器中制作所有技能,然后靈活運用它們。
html:
<section class="section section-light">
<h2>Skills</h2>
<div class="skill-list">
<p class="skills" *ngFor="let skill of skills">{{skill.skill}}</p>
</div>
</section>
css:
.skill-list{
display : flex;
justify-content: between;
}
您可以在此處使用 css flexbox 模式。嘗試將 class 添加到您的<p>
標簽並為它們提供以下屬性
.<your class name> {
display: flex;
flex-wrap: nowrap;
}
if you don't want to mess around that much with CSS attributes you should have a look at [@angular/flex-layout][1]
[1]: https://github.com/angular/flex-layout
1. Rows made like this:
<div fxLayout="row wrap">
<div fxFlex="50%" [fxFlex.lt-md]="100%" fxLayoutAlign="start center">
</div>
<div fxFlex="50%" [fxFlex.lt-md]="100%" fxLayoutAlign="end center">
</div>
</div>
2. Columns made like this:
<div fxLayout="column wrap">
<div fxFlex="50%" fxLayoutAlign="start center">
</div>
<div fxFlex="50%" fxLayoutAlign="end center">
</div>
</div>
[fxFlex.lt-md] makes the styling responsive, depending on your current user's viewport. There are *.lt-sm, *.lt-md and also *.gt-sm and so on...
And you may use on any flexLayout directives like "fxLayoutAlign" and others...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.