如何使用HTML制作一条垂直线?


当前回答

在HTML中没有任何创建垂直线的标记。

方法:加载直线图像。然后你设置它的样式像"height: 100px;宽:2 px” 方法:你可以使用<td>标签<td style="border-left: 1px solid red;填充:5 px;"> X </td> .

其他回答

另一种选择是使用1像素的图像,并设置高度-这个选项将允许您将其浮动到您需要的位置。

但这不是最优雅的解决方案。

如果你的目标是在容器中放置垂直线来分离并排的子元素(列元素),你可以考虑这样样式化容器:

.container > *:not(:first-child) {
  border-left: solid gray 2px;
}

这将为从第2个子元素开始的所有子元素添加左边框。换句话说,相邻子节点之间有垂直边界。

>是子选择器。它匹配左边指定的元素的任何子元素。 *是一个通用选择器。它匹配任何类型的元素。 :not(:first-child)表示它不是其父节点的第一个子节点。

浏览器支持:> *:first-child和:not()

我认为这比简单的.child-except-first {border-left:…}规则,因为让垂直线来自容器的规则,而不是不同子元素的规则更有意义。

这是否比使用临时的垂直规则元素(通过样式化水平规则等)更好,将取决于您的用例,但这至少是一种替代方案。

我认为这是一种简单的方法,你可以根据你的需要左右改变边界

.vertical-line { 左边框:1px实线#000 } < span class = "垂直线" > < /跨度

垂直到div

<div style="width:50%"> <div style="border-right:1px solid;"> <ul> <li> Empty div didn't shows line </li> <li> Vertical line length depends on the content in the div </li> <li> Here I am using inline style. You can replace it by external style or internal style. </li> </ul> </div> </div>

到div左边的垂直线

<div style="width:50%"> <div style="border-left:1px solid;"> <ul> <li> Empty div didn't shows line </li> <li> Vertical line length depends on the content in the div </li> <li> Here I am using inline style. You can replace it by external style or internal style. </li> </ul> </div> </div>

旋转a <hr> 90度:

<人力资源风格= "宽度:100 px;变换:旋转(90度);" >