HTML div 带有卡片的响应式设计
HTML div responsive design with cards
标题并没有真正描述我的问题。
我有一个带有描述我的项目的“卡片”的网络应用程序,但我需要它填满屏幕,同时保持相同的大小。
我现在的设计是这样的:
current design
我希望我的设计是这样的:design that I want
请原谅我糟糕的图形设计技巧,提前致谢!
编辑:当前代码
<div class="row">
{% for task in tasks %}
<div class="card">
<div class="alert">
<strong>Status: </strong> {{ task.status }}
</div>
{% if logo == False %}
<img src="[redacted]" alt="Logo for {{ task.content }}" style="width:100%">
{% else %}
<img src="{{ task.logo }}" alt="Logo for {{ task.content }}" style="width:50%">
{% endif %}
<h1>{{ task.content }}</h1>
<p>{{ task.description }}</p>
<a href='https://{{ task.website }}'><button>Visit {{ task.content }}'s website</button></a>
<div class="btn-group"><p><a href='delete/{{ task.id }}'><button style="width:50%">Delete</button></a><a href='update/{{ task.id }}'><button style="width:50%">Edit</button></a></p></div>
</div>
<br>
{% endfor %}
{% endif %}
您应该使用 css 样式表来创建类似卡片的结构。
下面给出了示例代码。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
/* Float four columns side by side */
.column {
float: left;
width: 25%;
padding: 0 10px;
}
/* Remove extra left and right margins, due to padding */
.row {margin: 0 -5px;}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive columns */
@media screen and (max-width: 600px) {
.column {
width: 100%;
display: block;
margin-bottom: 20px;
}
}
/* Style the counter cards */
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 16px;
text-align: center;
background-color: #f1f1f1;
}
</style>
</head>
<body>
<h2>Responsive Column Cards</h2>
<p>Resize the browser window to see the effect.</p>
<div class="row">
<div class="column">
<div class="card">
<h3>Card 1</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div class="column">
<div class="card">
<h3>Card 2</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div class="column">
<div class="card">
<h3>Card 3</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div class="column">
<div class="card">
<h3>Card 4</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
</div>
</body>
</html>
标题并没有真正描述我的问题。 我有一个带有描述我的项目的“卡片”的网络应用程序,但我需要它填满屏幕,同时保持相同的大小。
我现在的设计是这样的: current design
我希望我的设计是这样的:design that I want
请原谅我糟糕的图形设计技巧,提前致谢!
编辑:当前代码
<div class="row">
{% for task in tasks %}
<div class="card">
<div class="alert">
<strong>Status: </strong> {{ task.status }}
</div>
{% if logo == False %}
<img src="[redacted]" alt="Logo for {{ task.content }}" style="width:100%">
{% else %}
<img src="{{ task.logo }}" alt="Logo for {{ task.content }}" style="width:50%">
{% endif %}
<h1>{{ task.content }}</h1>
<p>{{ task.description }}</p>
<a href='https://{{ task.website }}'><button>Visit {{ task.content }}'s website</button></a>
<div class="btn-group"><p><a href='delete/{{ task.id }}'><button style="width:50%">Delete</button></a><a href='update/{{ task.id }}'><button style="width:50%">Edit</button></a></p></div>
</div>
<br>
{% endfor %}
{% endif %}
您应该使用 css 样式表来创建类似卡片的结构。 下面给出了示例代码。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
/* Float four columns side by side */
.column {
float: left;
width: 25%;
padding: 0 10px;
}
/* Remove extra left and right margins, due to padding */
.row {margin: 0 -5px;}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive columns */
@media screen and (max-width: 600px) {
.column {
width: 100%;
display: block;
margin-bottom: 20px;
}
}
/* Style the counter cards */
.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 16px;
text-align: center;
background-color: #f1f1f1;
}
</style>
</head>
<body>
<h2>Responsive Column Cards</h2>
<p>Resize the browser window to see the effect.</p>
<div class="row">
<div class="column">
<div class="card">
<h3>Card 1</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div class="column">
<div class="card">
<h3>Card 2</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div class="column">
<div class="card">
<h3>Card 3</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
<div class="column">
<div class="card">
<h3>Card 4</h3>
<p>Some text</p>
<p>Some text</p>
</div>
</div>
</div>
</body>
</html>