我需要做什么才能让“标题”包含在这个片段中?此外,当它包裹时,它应该将 table 向下推。下面是一张图片。我希望以 This is the title 开头的行换行。
我已经导入了 JS Fiddle
代码:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ANSI">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<style type='text/css'>
#body {
width:400px;
margin:0 auto;
background-color: #fff;
}
#content-1 {
float:left;
width:100%;
background:#f7f7f7;
}
#wrapper { bottom:0;overflow: hidden; }
.tablecontent { z-index: 99; margin: 10px; padding: 35px 5px 5px 5px;background-color:#FFFFFF; border: 1px solid; border-color: #B8B8B8; border-radius: 4px;}
.tabletitle {color: #005c9c;padding-top: 20px;padding-left: 20px;z-index: 100;position:absolute;}
</style>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart","table"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var cssClassNames = {
'tableCell': 'wrapall'};
var datatable = new google.visualization.DataTable();
datatable.addColumn('string','Country','col1');
datatable.addColumn('number','Metric 1');
datatable.addColumn('number','Metric2');
datatable.addColumn('number','Metric3');
datatable.addRows(2);
datatable.setCell(0,0,'United States');
datatable.setCell(0,1,7);
datatable.setCell(0,2,306);
datatable.setCell(0,3,67.32,'67.32%');
datatable.setCell(1,0,'India');
datatable.setCell(1,1,5);
datatable.setCell(1,2,139);
datatable.setCell(1,3,76.98,'76.98%');
var table = new google.visualization.Table(document.getElementById('dashboardtable_20'));
table.draw(datatable, {showRowNumber: false, 'allowHtml': true, 'cssClassNames': cssClassNames});
}
</script>
</head>
<body>
<div id="body">
<div id="wrapper">
<div id="main">
<div id="content-1">
<div class="tabletitle">This is the title of my widget. But I want this to wrap if the title is long.</div>
<div id="dashboardtable_20" class="tablecontent"></div>
</div>
</div>
</div>
</body>
</html>
我建议不要使用 position:absolute
,而是尝试匹配标题和表格的样式,如下所示:
.tablecontent {
margin: 10px;
padding: 5px;
background-color: #FFFFFF;
border: 1px solid #B8B8B8;
border-radius: 0 0 4px 4px;
border-top: none;
margin-top: 0;
}
.tabletitle {
color: #005c9c;
padding: 5px;
background: white;
border: 1px solid #B8B8B8;
border-bottom: none;
margin: 10px;
margin-bottom: 0;
border-radius: 4px 4px 0 0;
}
我是一名优秀的程序员,十分优秀!