【发布时间】:2019-01-21 01:43:05
【问题描述】:
是否可以使用html和css绘制以下内容?
我只对线条部分感兴趣。 Here 是我迄今为止所尝试的。
html:
<div class="outer">
<div class="inner">
<div class="topPart">
TOP
</div>
<div class="middlePart">
<div class="program selectedProgram">
<div class="programName">
foo program
</div>
<div class="modulesDiv">
<div class="module">
<div class="moduleName">
foo module foo module foo module foo module foo module
</div>
</div>
<div class="module">
<div class="moduleName">
foo short name
</div>
</div>
<div class="module">
<div class="moduleName">
foo module foo module foo module foo module foo module
</div>
</div>
</div>
</div>
</div>
<div class="bottomPart">
BOTTOM
</div>
</div>
</div>
css:
.outer {
background-color: red;
position: relative;
margin: 0 auto;
top: 40px;
width: 200px;
height: 2000px;
background-image: url('https://mdn.mozillademos.org/files/7693/catfront.png');
background-repeat: no-repeat;
background-size: cover;
}
.inner {
position: -webkit-sticky;
position: sticky;
top: 0;
background-color: cyan;
width: 200px;
height: 400px/* 100vh */
;
}
.topPart {
position: absolute;
height: 10%;
width: 100%;
top: 0;
background-color: pink;
text-align: center;
}
.middlePart {
position: absolute;
height: 80%;
width: 100%;
top: 10%;
background-color: yellow;
text-align: center;
}
.bottomPart {
position: absolute;
height: 10%;
width: 100%;
top: 90%;
background-color: #66aa11;
text-align: center;
}
.program {
height: auto;
text-align: left;
width: 100%;
cursor: pointer;
padding-top: 5%;
padding-bottom: 5%;
padding-left: 5%;
padding-right: 5%;
word-wrap: break-word;
border-bottom: 1px solid #afadad;
position: relative;
}
.program.selectedProgram {
border-left: 4px solid #289efd;
}
.program .programName {
display: inline;
font-size: 110%;
color: #484646;
padding-left: 5%;
vertical-align: middle;
}
.selectedProgram.program .programName {
font-weight: bold;
color: #289efd;
}
.program:hover .programName {
color: #289efd;
}
.program .programName {
white-space: pre-wrap;
white-space: -moz-pre-wrap !important;
white-space: -webkit-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
white-space: pre-wrap;
word-wrap: break-word;
word-break: break-all;
white-space: normal;
}
.modulesDiv {
height: auto;
width: 100%;
position: relative;
padding-left: 5%;
padding-top: 5%;
display: none;
}
.selectedProgram .modulesDiv {
display: block;
}
.module {
height: auto;
text-align: left;
width: 100%;
cursor: pointer;
padding-top: 5%;
padding-bottom: 5%;
padding-left: 5%;
padding-right: 5%;
word-wrap: break-word;
position: relative;
}
.program .moduleName {
display: inline;
font-size: 110%;
color: #484646;
padding-left: 5%;
vertical-align: middle;
}
.selectedModule.module .moduleName {
font-weight: bold;
color: #289efd;
}
.module:hover .moduleName {
color: #289efd;
}
我在这里面临两个问题。
- 我不知道如何仅使用
html和css绘制一条随机定位的线。 - 我无法事先猜测每个模块将占用多少高度,因此无法在代码中推断出何时必须在模块名称上画一个水平叉。
我将屏幕截图中粗体的主名称称为程序名称,将左侧缩进的名称称为模块名称。
我希望有人能够在这里至少提供帮助。
【问题讨论】:
标签: html css dynamic line draw