具有水平线和垂直线的html页面设计

时间:2018-10-05 06:49:15

标签: html css

我试图获得以下输出。

enter image description here

但是我的代码输出以不同的方式显示它(查看整页)。

<html>

<head>
    <style>
        h2 {
            width: 100%;
            text-align: center;
            border-bottom: 1px solid #000;
            line-height: 10em;
            margin: 20px 0 40px;
        }

        h2 span {
            background: #fff;
            padding: 0 1px;
        }

        .vl {
            border-left: 1px solid green;
            height: 100%;
            position: absolute;
            left: 50%;
            top: 0;
        }
    </style>
</head>

<body>
    <h2>
        <span>
            <div class="vl"></div>
        </span>
    </h2>
</body>

</html>

它在两条水​​平线之间显示一条垂直线。

3 个答案:

答案 0 :(得分:1)

这是一个简单的代码,可以为您提供帮助。

body{
  overflow:hidden;
}
.line1{
  position:absolute;
  width:50%;
  height:30%;
  border-right:2px solid black;
  border-bottom:2px solid black;
}
.vertical{
  position:absolute;
  width:50%;
  height:40%;
  top:30%;
  border-right:2px solid black;
}
.line2{
  position:absolute;
  width:50%;
  height:30%;
  border-top:2px solid black;
  border-left:2px solid black;
  bottom:0;
  right:-10px;
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div class="container">
    <span class="line1"></span>
    <span class="vertical"></span>
    <span class="line2"></span>
  <div>
</body>
</html>

答案 1 :(得分:0)

更新代码以获取所需的输出     

<head>
    <style>
        body{
            display: flex;
            margin: 0;
            padding: 0;
        }
        .left-div{
            height: 30%;
            border-bottom: 1px solid #000;
            align-self: flex-start;
            width: 50%;
        }
        .right-div{
            align-self: flex-end;
            height: 30%;
            border-top: 1px solid #000;
            width: 50%;
        }
        .vertical-line{
            position: absolute;
            top:0;
            left:50%;
            height: 100vh;
            width: 1px;
            background-color: #000;
            transition: translateY(-50%);
        }
     </style>
</head>

<body>
    <span class="vertical-line"></span>
    <div class="left-div"></div>
    <div class="right-div"></div>
</body>

</html>

答案 2 :(得分:0)

尝试一下

CSS:

body,html{
    height:100%;
}
.flex{
    display:flex;
    height:100%;
}

.flex-wrap{
    flex-wrap:wrap;
}

.bottom-border{
    border-bottom:1px solid; 
}

.top-border{
    border-top:1px solid; 
 }

 .side{
     width:50%;
     height:100%;
 }

 .left-side{
     border-right:1px solid; 
     width:calc(50% - 1px);
 }

 .element{
     height:30%;
     width:100%;
 }

 .margin-top-auto{
     margin-top:auto;
 }

HTML:

<div class="flex flex-wrap">
  <div class="side left-side">
      <div class="bottom-border element">
        30%
      </div>
  </div>
  <div class="side flex">
      <div class="top-border element margin-top-auto">
        30%
      </div>
  </div>
</div>

JSFiddle:

https://jsfiddle.net/e3j2oh4q/