桌子的无边框标题

时间:2016-11-04 08:30:25

标签: html css

我想要实现的目标是:

borderless header

最左边的标题列没有边框,但它是表格的一部分。

我尝试了以下HTML:

<table class="my-table" style="border-left: 0">
    <tr>
        <td style="border-left: 0;border-top: 0; border-bottom: 0">x</td>
        <td>1</td>
        <td>2</td>
        <td>3</td>
    </tr>
    <tr>
        <td style="border-left: 0;border-top: 0; border-bottom: 0">f(x)</td>
        <td>1</td>
        <td>4</td>
        <td>9</td>
    </tr>
</table>

使用以下CSS:

table.my-table {
    border-collapse: collapse;
    border: 1px solid grey;
}
table.my-table td {
    border: 1px solid grey;
    padding: 0 0.5em;
    text-align: center;
}

https://jsfiddle.net/96vk704s/

但是第1列的上下边框仍然存在。

not quite borderless

我知道我可以使用两个绝对大小的表来解决这个问题,但是在一个表中可能有很好的方法吗?

4 个答案:

答案 0 :(得分:3)

删除table上的边框,它可以正常工作

Fiddle here

table.my-table {
    border-collapse: collapse;
}

答案 1 :(得分:1)

删除表格的边框,因为边框为table.my-table td,它会包裹所有td的所有边,因此无需为table提供边框

table.my-table {
    border-collapse: collapse;
}

&#13;
&#13;
table.my-table {
  border-collapse: collapse;
}
table.my-table td {
  border: 1px solid grey;
  padding: 0 0.5em;
  text-align: center;
}
&#13;
<table class="my-table" style="border-left: 0">
  <tr>
    <td style="border-left: 0;border-top: 0; border-bottom: 0">x</td>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
  <tr>
    <td style="border-left: 0;border-top: 0; border-bottom: 0">f(x)</td>
    <td>1</td>
    <td>4</td>
    <td>9</td>
  </tr>
</table>
&#13;
&#13;
&#13;

答案 2 :(得分:1)

<table class="my-table" style="border:none;">
<tr>
    <td style="border:none;">x</td>
    <td>1</td>
    <td>2</td>
    <td>3</td>
</tr>
<tr>
    <td style="border:none;">f(x)</td>
    <td>1</td>
    <td>4</td>
    <td>9</td>
</tr>

只需将您的HTML更改为此即可。您刚删除了 td 的边框,甚至应删除表格的边框,您可以通过这样做来实现。

Jsfiddle

答案 3 :(得分:1)

CSS

<!DOCTYPE html>
<meta charset="utf-8">
 <link type="text/css" rel="stylesheet" href="d3map.css" />
<link rel="stylesheet" href="leaflet.css"/>
    <script src="leaflet.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script src="http://d3js.org/colorbrewer.v1.min.js"></script>

<script src="http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/tile.js" type="text/javascript">
</script>
<script src="http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/d3.quadtiles.js" type="text/javascript">
</script>
<script src="http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/d3.geo.raster.js" type="text/javascript">
</script>
<script src="https://rawgit.com/emeeks/d3-carto-map/master/d3.carto.map.js" type="text/javascript">
</script>
<style>
svg{
    position: absolute;
}

 html,body {
    height: 100%;
    width: 100%;
    margin: 0;
  }

  #map {
    height: 500px;
    width: 960px;
    position: absolute;
  }

  .reproject {
    position: absolute;
    z-index: 99;
    left: 50px;
    top: 250px;
  }


  .metro {
    fill: rgba(255,0,255,.5);
    stroke: darkred;
    stroke-width: 1
  }
.markerButton {
    position: fixed;
    top: 20px;
    cursor: pointer;
    z-index: 99;
  }

body {
  background: #fcfcfa;
}

.stroke {
  fill: none;
  stroke: #000;
  stroke-width: 3px;
}

.fill {
  fill: #fff;
}

.graticule {
  fill: none;
  stroke: #777;
  stroke-width: .5px;
  stroke-opacity: .5;
}

.land {
  fill: #222;
}

.boundary {
  fill: none;
  stroke: #fff;
  stroke-width: .5px;
}

</style>
<body onload="makeSomeMaps()">




<script>

var width = 960,
    height = 500;

var projection = d3.geo.mollweide()
    .scale(165)
    .translate([width / 2, height / 2])
    .precision(.1);

var path = d3.geo.path()
    .projection(projection);

var graticule = d3.geo.graticule();

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);


svg.append("defs").append("path")
    .datum({type: "Sphere"})
    .attr("id", "sphere")
    .attr("d", path);

svg.append("use")
    .attr("class", "stroke")
    .attr("xlink:href", "#sphere");

svg.append("use")
    .attr("class", "fill")
    .attr("xlink:href", "#sphere");

svg.append("path")
    .datum(graticule)
    .attr("class", "graticule")
    .attr("d", path);

d3.json("world-50m.json", function(error, world) {
  if (error) throw error;

  svg.insert("path", ".graticule")
      .datum(topojson.feature(world, world.objects.land))
      .attr("class", "land")
      .attr("d", path);

  svg.insert("path", ".graticule")
      .datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
      .attr("class", "boundary")
      .attr("d", path);
});

d3.select(self.frameElement).style("height", height + "px");
var marker=L.marker([0,0],
             {draggable:true,

             });


marker.on('dragend',function(e){
             //alert(marker.getLatLng().toString());
             marker.getPopup().setContent('Clicked'+marker.getLatLng().toString()).openOn(map);
             });


function circleMarker() {
    var sizeScale = d3.scale.linear().domain([0,100,2000]).range([2,10,20]).clamp(true);
    var randomDatapoint = "r" + Math.ceil(Math.random() * 7);
    markers.append("circle").selectAll("*").remove();
    markers.append("circle")
    .attr("class", "metro")
    .attr("r", function(d) {return sizeScale(d[randomDatapoint])})
  }

function makeSomeMaps() {
    map = d3.carto.map();



d3.select("#map").call(map);
    map.centerOn([-99,39],"latlong");
    map.setScale(4);

    map.refresh();

cityLayer = d3.carto.layer.csv();
    cityLayer
    .path("cities.csv")
    .label("Metro Areas")
    .cssClass("metro")
    .renderMode("svg")
    .x("x")
    .y("y")
    .clickableFeatures(true)
    .on("load", function(){console.log(cityLayer.dataset())});

    map.addCartoLayer(cityLayer);

}



</script>
<div id="map">
<button style="left: 340px;" class="markerButton" onclick="circleMarker();">Circle Marker</button>
</div>

</body>
</html>

HTML

table.my-table {
 border-collapse: collapse;
}
table.my-table td {
 border: 1px solid grey;
 padding: 0 0.5em;
 text-align: center;
}
tr > :first-child{
 border:none !important;
}