javascript - 如何放置 2s并排
问题描述
您好,我使用 javascript、chart.js 和 html & css 编写了这段代码:
<!DOCTYPE HTML>
<html>
<head>
<title>Index</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<canvas id="line-chart" width="800" height="450"></canvas>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id = "Global">
<div id = "right">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
</div>
<div id = "left">
<script>
var ctx = new Chart(document.getElementById("line-chart"), {
type: 'line',
data: {
/* labels: [18.123,46.8603108462,75.5976216923,104.334932538] */
datasets: [{
data: [{'y': 426777.148122,'x': 18.123},
{'y': 258927.721326,'x': 46.8603108462},
{'y': 176174.771954,'x': 75.5976216923},
{'y': 129604.15967,'x': 104.334932538},
{'y': 101328.238625,'x': 133.072243385}],
label: "Model",
borderColor: "#3e95cd",
fill: false
}, {
label : 'Data',
fill:false,
showLine: false,
backgroundColor: "#FF0000",
data : [{x: 17.0, y: 454995.091169},
{x: 18.0, y: 457656.874749},
{x: 19.0, y: 444574.49162},
{x: 20.0, y: 432511.514968},
{x: 21.0, y: 421184.776328},
{x: 22.0, y: 410452.691467}],
type: 'line'
}]
},
options: {
title:{
display: true,
text:"Tools"
},
scales: {
xAxes: [{
type: 'logarithmic',
position: 'bottom'
}],
yAxes: [{
type: 'logarithmic'
}]
}
}
})
</script>
</div>
</div>
</body>
</html>
实际上,当我在浏览器中查看结果时,我会看到上面的 javascript,
<div id = "right">
而我希望 javascript 在左侧和<div id = "right">
右侧。
这是我的CSS:
#Global
{
width:100%;
}
#Global #left {
float:left;
width:60%;
}
#Global #right {
margin-left:60%
}
我以为它会起作用,但事实并非如此。
谢谢您的帮助 !
这就是我在浏览器中查看结果时得到的原因:
解决方案
除了已经提供的选项之外,另一种选择是将您的 Global div 改为表格,而您的左右 div 可以是该表格上一行中的同级单元格。
推荐阅读
- sonarqube - 如何自动将 Google 样式规则加载到 SonarQube?
- go - golang 的 BOX / JWT OAuth 2.0
- sql - 如何使用 SQL 获取每天分类变量的百分比量?
- polymer - 将聚合物 2 覆盖到聚合物 3:调制器内存不足?
- ios - NSUserActivity 与 Core Spotlight 深层链接
- c# - 如何使用 ActionResult 进行单元测试
? - react-native - 在模拟器上反应原生 iOS 图像选择器非常慢
- java - 当该名称在列表中多次出现时,告诉删除数组列表中的名称的程序
- html - 使用css在网格上等间距按钮
- python - 如何从命令行在我的 bashrc 文件中设置路径变量以使用 python 3