用css重现这种布局效果的方法?

8 html css html-table

如果没有创建一个7列/ 3行表,其中1像素图像可以扩展以模拟线条,那么如何使用HTML和CSS重现这种布局而不使用表格或图像作为"分隔符"?

我真正喜欢它的是线条不相交的方式.

在此输入图像描述

<!-- layout reproduced -->
<TABLE BORDER="0" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
    <TR ALIGN="center">
        <TD CLASS="boldedcolor4text">the first</TD>
        <TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="20"></TD>
        <TD CLASS="boldedcolor4text">the second</TD>
        <TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="20"></TD>
        <TD CLASS="boldedcolor4text">the third</TD>
        <TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="20"></TD>
        <TD CLASS="boldedcolor4text">the fourth</TD>
    </TR>
    <TR ALIGN="center">
        <TD COLSPAN="7"><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="520" HEIGHT="1"></TD>
    </TR>
    <TR ALIGN="center">
        <TD><A CLASS="image" HREF="><IMG SRC="1.jpg" ALT="" BORDER="0"></A></TD>
        <TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="135"></TD>
        <TD><A CLASS="image" HREF="><IMG SRC="2.jpg" ALT="" BORDER="0"></A></TD>
        <TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="135"></TD>
        <TD><A CLASS="image" HREF="><IMG SRC="3.jpg" ALT="" BORDER="0"></A></TD>
        <TD><IMG SRC="/gfx/Style1/color1.gif" ALT="" WIDTH="1" HEIGHT="135"></TD>
        <TD><A CLASS="image" HREF="><IMG SRC="4.jpg" ALT="" BORDER="0"></A></TD>
    </TR>
</TABLE>
Run Code Online (Sandbox Code Playgroud)

And*_*man 10

我的解决方案没有依赖关系.我创建了一个flexbox .container,然后是四个flex .item.flexbox的默认方向是row,我们想要外部布局,但不是行中每个项目的内容.为了调整这个,我flex-direction将children(.item)更改为,column因为在您的示例中,图像堆叠在锚点下方.

对于锚点和图像之间的非破坏边界,我采用了一些快捷方式并将样式移动到伪类.注意position: relative;.item.这样做是为了创建一个安全的容器,用于保存绝对定位的伪类边界.

.container, .item {
  display: flex;
}

.item {
  flex-direction: column;
  position: relative;
}

.item:before {
  content: '';
  border-top: 1px solid;
  position: absolute;
  width: 100%;
  top: 2em;
}

.item:first-child:before {
  left: 1.5em;
}

.item:last-child:before {
  left: -1.5em;
}

.item:last-child .link,
.item:last-child .img {
  border-right: none;
}

.link,
.img {
  border-right: 1px solid;  
}

.link {
  text-align: center;
}

.img {
  margin-top: 2em;
  padding: 0.5em 1em 0.5em;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
  <div class="item">
    <a class="link" href="">link 1</a>
    <img class="img" src="http://placehold.it/100x130" alt="" />
  </div>
  <div class="item">
    <a class="link" href="">link 2</a>
    <img class="img" src="http://placehold.it/100x130" alt="" />
  </div>
  <div class="item">
    <a class="link" href="">link 3</a>
    <img class="img" src="http://placehold.it/100x130" alt="" />
  </div>
  <div class="item">
    <a class="link" href="">link 4</a>
    <img class="img" src="http://placehold.it/100x130" alt="" />
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

小提琴:https://jsfiddle.net/1sbx2h5e/


Ser*_*gej 1

你可以尝试一下: https: //jsfiddle.net/wh48rjvt/

社会保障体系:

$border: 1px solid grey;
.table-row {
  border-bottom: $border;
  &:last-child {
    border-bottom: 0;
  }
  .table-box {
    border-right: $border;
    margin: 0.75rem 0;
    &:last-child {
      border-right: 0;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这会产生以下 CSS:

.table-row {
  border-bottom: 1px solid grey;
}
.table-row:last-child {
  border-bottom: 0;
}
.table-row .table-box {
  border-right: 1px solid grey;
  margin: 0.75rem 0;
}
.table-row .table-box:last-child {
  border-right: 0;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<div class="container">
  <div class="table-row row">
    <div class="table-box col-xs-3">1</div>
    <div class="table-box col-xs-3">2</div>
    <div class="table-box col-xs-3">3</div>
    <div class="table-box col-xs-3">4</div>
  </div>
  <div class="table-row row">
    <div class="table-box col-xs-3">5</div>
    <div class="table-box col-xs-3">6</div>
    <div class="table-box col-xs-3">7</div>
    <div class="table-box col-xs-3">8</div>
  </div>
  ...
</div>
Run Code Online (Sandbox Code Playgroud)

我使用 Bootstrap 作为网格。