html - 将表格与绘图相邻
问题描述
我对在 html 中移动/放置项目感到震惊。我们可以尝试移动表格,如底部所示(预期输出)。是否可以有如下布局。将底部移动到图旁边
<html>
<style>
table {
{
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
}
td,
th {
{
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
}
tr:nth-child(even) {
{
background-color: #dddddd;
}
}
</style>
<body>
<table>
<tr>
<th>Region</th>
<th>Experience</th>
<th>Paper</th>
</tr>
<tr>
<td>REGION</td>
<td>MInition</td>
<td>Papt</td>
</tr>
</table>
</body>
<br></br>
</html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<body>
<canvas id="myChart" style="width:90%;max-width:600px"></canvas>
<div style="width:100%">
<div class="box">
<script>
var xValues = [1, 2];
new Chart("myChart", {
type: "line",
data: {
labels: xValues,
datasets: [{
data: [1, 2],
borderColor: "red",
fill: false
}, {
data: [3, 4],
borderColor: "green",
fill: false
}, {
data: [4, 5],
borderColor: "blue",
fill: false
}, {
data: [6, 7],
borderColor: "black",
fill: false
}, {
data: [8, 9],
borderColor: "#8E44AD",
fill: false
}]
},
options: {
legend: {
display: false
}
}
});
</script>
</div>
<div class="box">
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
</table>
</div>
</div>
<style>
.b {
display: inline-block;
width: 100px;
height: 100px;
padding: 5px;
border: 1px solid blue;
background-color: yellow;
}
.c {
display: block;
width: 100px;
height: 100px;
padding: 5px;
border: 1px solid blue;
background-color: yellow;
}
</style>
解决方案
给你,但一定要调整代码并添加媒体查询,以保持设计在较小的屏幕上响应
<html>
<head>
<style>
table {{
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}}
td, th {{
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}}
tr:nth-child(even) {{
background-color: #dddddd;
}}
</style>
</head>
<body>
<table>
<tr>
<th>Region</th>
<th>Experience</th>
<th>Paper</th>
</tr>
<tr>
<td>REGION</td>
<td>MInition</td>
<td>Papt</td>
</tr>
</table>
</body>
<br></br>
</html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<body>
<canvas id="myChart" style="display:inline-block;max-width:600px"></canvas>
<div style="display:inline-block;">
<div class="box"><script>
var xValues = [1,2];
new Chart("myChart", {
type: "line",
data: {
labels: xValues,
datasets: [{
data: [1,2],
borderColor: "red",
fill: false
}, {
data: [3,4],
borderColor: "green",
fill: false
}, {
data: [4,5],
borderColor: "blue",
fill: false
}, {
data: [6,7],
borderColor: "black",
fill: false
}, {
data: [8,9],
borderColor: "#8E44AD",
fill: false
}]
},
options: {
legend: {display: false}
}
});
</script></div>
<div class="box" style="position:absolute;top:90">
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
</table>
</div>
</div>
<style>
.b {
display: inline-block;
width: 100px;
height: 100px;
padding: 5px;
border: 1px solid blue;
background-color: yellow;
}
.c {
display: block;
width: 100px;
height: 100px;
padding: 5px;
border: 1px solid blue;
background-color: yellow;
}
</style>
推荐阅读
- python - 清理 x 轴,因为数据点太多
- python - 无论键或条件如何,如何更新 DynamoDB 表中的属性?
- angular - Angular 9如何在返回上一页后保持组件状态?
- javascript - 颜色在开始时不适合进度条
- javascript - 我在 express 中遇到 graphql 解析器错误
- java - 如何在 Android Studio 中重新定位 Google Maps API 的 controlMarkerUI
- javascript - 合并两张图片模拟服装店
- swiftui - 使用带有 CLGeocoder 的 mapViewDidChangeVisibleRegion 返回国家名称
- python - __call__() 缺少 1 个必需的位置参数:App Engine 上的“发送”FastAPI
- batch-file - 如何在命令提示符下修剪字符串?