英文:
How to make horizontal cards using Angular Material
问题
我正在尝试将这些垂直卡片变成水平卡片。
我正在使用Angular Material的Cards组件。
我只能创建垂直卡片,但我需要将卡片水平排列。
这里是我附上的代码供参考。
HTML:
<body>
<div class="wrap">
<!-- <img class="img-bg" background-image src="assets/logo.png"> -->
<div class="text">
<h1 style="font-weight: bold; text-align: center;">欢迎使用数据门户...</h1>
<br>
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>Catalog</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>在这里,您可以找到有关用户/角色的详细信息。</p>
</mat-card-content>
<mat-card-header>
<mat-card-title>Data Portal</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>在这里,您可以找到有关所有数据库和表的详细信息。</p>
</mat-card-content>
</mat-card>
<br>
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>Data Portal</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>在这里,您可以找到有关所有数据库和表的详细信息。</p>
</mat-card-content>
</mat-card>
</div>
</div>
</body>
CSS:
.example-card {
height: 200px;
width: 400px;
max-width: 300px;
margin-left: 100px;
background-color: lightgrey;
color: black;
text-align: center;
}
<details>
<summary>英文:</summary>
I am trying to make these vertical cards into horizontal cards.
I am using the Cards component from Angular Material.
I can create cards only vertically, but I need the cards arranged on a horizontal level.
Here I'm attaching my code for reference.
HTML:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<body>
<div class="wrap">
<!-- <img class="img-bg" background-image src="assets/logo.png"> -->
<div class="text">
<h1 style="font-weight: bold; text-align: center;">Welcome to Data Portal...</h1>
<br>
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>Catalog</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>Here you can find the details about users/roles.</p>
</mat-card-content>
<mat-card-header>
<mat-card-title>Data Portal</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>Here you can find the details about all the databases and tables.</p>
</mat-card-content>
</mat-card>
<br>
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>Data Portal</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>Here you can find the details about all the databases and tables.</p>
</mat-card-content>
</mat-card>
</div>
</div>
</body>
<!-- end snippet -->
CSS:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.example-card {
height: 200px;
width: 400px;
max-width: 300px;
margin-left: 100px;
background-color: lightgrey;
color: black;
text-align: center;
}
<!-- end snippet -->
[sample image](https://i.stack.imgur.com/PRKzY.png)
</details>
# 答案1
**得分**: 2
创建一个容器来包裹所有的`mat-card`,然后使用CSS改变容器内元素的布局流动方式。例如:
```html
<div style="display: flex;">
<mat-card>...</mat-card>
<mat-card>...</mat-card>
</div>
英文:
Create a container for all the mat-cards
, then change the flow of the elements inside the container using CSS. For example:
<div style="display: flex;">
<mat-card>...</mat-card>
<mat-card>...</mat-card>
</div>
答案2
得分: 1
以下是您提供的代码的翻译:
<div fxLayout="row wrap" fxLayoutGap="16px grid">
<div fxFlex="25%" fxFlex.xs="100%" fxFlex.sm="33%">
<mat-card class="mat-elevation-z4">
</mat-card>
</div>
</div>
请注意,这是提供的代码的直译翻译,没有进行任何其他修改。如果您需要进一步的帮助或解释,请告诉我。
英文:
<div fxLayout="row wrap" fxLayoutGap="16px grid">
<div fxFlex="25%" fxFlex.xs="100%" fxFlex.sm="33%">
<mat-card class="mat-elevation-z4" >
</mat-card>
</div>
See link below for reference https://zoaibkhan.com/blog/create-a-responsive-card-grid-in-angular-using-flex-layout-part-1/
答案3
得分: 1
你需要先为mat-cards创建一个容器,然后可以设置flex属性,使其水平或垂直排列,如果需要的话。以下是一些可能会帮助你的代码。
.wrap {
display: flex;
margin: 0 auto; /* 居中内容 */
}
.example-card {
border: 1px solid black;
border-radius: 5px;
text-align: center;
height: 200px;
width: 400px;
max-width: 300px;
margin-left: 100px;
background-color: lightgrey;
color: black;
text-align: center;
}
<div class="wrap">
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>Catalog</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>在这里,您可以找到有关用户/角色的详细信息。</p>
</mat-card-content>
<mat-card-header>
<mat-card-title>Data Portal</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>在这里,您可以找到有关所有数据库和表的详细信息。</p>
</mat-card-content>
</mat-card>
<br>
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>Data Portal</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>在这里,您可以找到有关所有数据库和表的详细信息。</p>
</mat-card-content>
</mat-card>
</div>
英文:
You need a container for mat-cards first, then you can set flex to make it horizontal or even vertical if you want. Some code is below maybe will help you.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.wrap{
display: flex;
margin: 0 auto //center the content
}
.example-card{
border: 1px solid black;
border-radius: 5px;
text-align: center;
height: 200px;
width: 400px;
max-width: 300px;
margin-left: 100px;
background-color: lightgrey;
color: black;
text-align: center;
}
<!-- language: lang-html -->
<div class="wrap">
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>Catalog</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>Here you can find the details about users/roles.</p>
</mat-card-content>
<mat-card-header>
<mat-card-title>Data Portal</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>Here you can find the details about all the databases and tables.</p>
</mat-card-content>
</mat-card>
<br>
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>Data Portal</mat-card-title>
</mat-card-header>
<mat-card-content>
<p>Here you can find the details about all the databases and tables.</p>
</mat-card-content>
</mat-card>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论