Remove white space in d3 table

纵饮孤独 提交于 2019-12-24 11:27:29

问题


I have the following table created in d3 (see image below) which has two columns. However, I am unable to remove the white space on the right hand side of the table. Here is the html and CSS for the table:

html

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="styles.css">
  </head>

  <body>
    <div class="grid-container">
      <div class="map">
        <svg></svg>
      </div>
      <div class="box-plot">
        <svg></svg>
      </div>
      <div class="table"></div>
      <div class="line-chart">
        <svg></svg>
      </div>
    </div>

    <script src="bundle.js"></script>
  </body>
</html>

/* And the css*/

.map {
  grid-area: map;
}

.map-path {
  /* fill: rgba(0,0,0,0.01); */
  /* stroke: rgba(0,0,0,0.2); */
  /* stroke-width: 1px; */
}

.map-path.counties {
  stroke: black;
  stroke-width: 1px;
}

.map-path.catchments {
  stroke: black;
  stroke-width: 1px;
}

.map-path.aquifer {
  /* stroke: rgba(0,200,0,0.5); */
  /* stroke-width: 0.5px; */
}

.map-path.gwrockunit {
  /* stroke: rgba(200,0,0,0.5); */
  /* stroke-width: 0.5px; */
}

.map-path.selected-basemap-polygon {
  stroke: black;
  stroke-width: 2px;
}

.box-plot {
  grid-area: box-plot;
}

.table {
  grid-area: table;
  overflow-y: scroll;
  font-family: Courier;
  /* max-width: 400px; */
  border-collapse: collapse;
  white-space: nowrap;
  width: 100%;
}
tr:nth-of-type(odd) {
        background: #eee;
}
th {
    background: #333;
    color: white;
    font-weight: bold;
    cursor: s-resize;
    background-repeat: no-repeat;
      background-position: 3% center;
}
td, th {
  padding: 6px;
  border: 1px solid #ccc;
  text-align: left;
}

.line-chart {
  grid-area: line-chart;
}

.grid-container {
  position: fixed;
  left: 0px;
  right: 0px;
  top: 0px;
  bottom: 0px;
  display: grid;
  grid-template-areas:
    'map map box-plot table'
    'map map line-chart table';
  grid-gap: 10px;
  background-color: #2196F3;
  padding: 10px;
}

.grid-container div {
  background-color: white;
}

.grid-container div svg {

  /* This makes it so the grid does not resize when the SVG is added */
  position: absolute;
}

.basemap-selector-widget {
  cursor: pointer;
}

.basemap-selector-widget rect {
  fill: white;
  stroke: black;
  stroke-width: 2px;
  border-radius: 25px;
}

.basemap-selector-widget text {
  font-family: sans;
  alignment-baseline: middle;
  text-anchor: middle;
}

and I am using a grid-container as the layout.

Second image where I would like to remove everything to the right of the red line. And just have the table fit within the div.


回答1:


Just replace width: auto with width: 100%. You can also want to specify box-sizing: border-box if you are not setting it document-wide.

It would be more convenient, however, if you add an HTML/CSS/JS runnable code snippet (Ctrl-M in editor).




回答2:


Without the complete code is hard to tell, but try:

.table {
grid-area: table;
overflow-y: scroll;
font-family: Courier;
border-collapse: collapse;
white-space: nowrap;
width: 100%;
}

Now,complete code I can help.. Just add to your css

 .table table {width:100%}


来源:https://stackoverflow.com/questions/51928736/remove-white-space-in-d3-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!