gpt4 book ai didi

html - 使用 CSS 在节点之间绘制线条

转载 作者:行者123 更新时间:2023-11-28 15:36:36 25 4
gpt4 key购买 nike

我很难找到合适的词来描述我手头的挑战。我有一组以组织结构图方式排列的节点。我想知道是否有办法通过线连接这些节点,这些线应该是动态的——可能使用 CSS 绘制它们是正确的方法。

enter image description here

事情看起来与图片中显示的类似。

连同绘制连接节点的线的方法,我很乐意知道是否有更有效的方法来动态生成这些节点,如 <ul><li>结构。

以下是我用来生成上图的代码片段(对 Bootstrap 的使用非常少):

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html"; charset="utf-8" />
<title>Oval</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style type="text/css">
body{
padding-top: 20px;
}

.oval {
width: 400px;
height: 160px;
background: #5fa2dd;
border-radius: 50%;
text-align: center;
}

.circle {
width: 190px;
height: 190px;
background: #9cc96b;
border-radius: 50%;
}

.emptyrow{
margin : 50px 0;
}

.med-circle{
width: 150px;
height: 150px;
background: #9cc96b;
border-radius: 50%;
}
</style>
</head>
<body class="container">
<div class="row">
<div class="col-lg-4 col-lg-offset-4 oval"><p>key1 : value1</p><p>key2 : value2</p><p>key3 : value3</p></div>
</div>
<div class="row emptyrow">
</div>
<div class="row">
<div class="col-lg-2 col-lg-offset-2 circle"></div>
<div class="col-lg-2 col-lg-offset-2 circle"></div>
<div class="col-lg-2 col-lg-offset-2 circle"></div>
</div>
</body>
</html>

问题简而言之:

  1. 动态生成节点的更好方法
  2. 如何画线连接这些节点?

最佳答案

我会选择 SVG。

有了它,你几乎可以做任何你想做的事情,包括行,CSS 将很难处理

Fiddle demo

堆栈片段

svg {
display: block;
margin: auto;
width: 100vmin;
}
.shadow {
-webkit-filter: drop-shadow( 2px 2px 2px rgba(0,0,0,0.5) );
filter: drop-shadow( 2px 2px 2px rgba(0,0,0,0.5) );
}
.line {
stroke: gray;
}
.ellipse {
fill: lightblue;
}
.circle {
fill: lightgreen;
}
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="395" height="305" viewBox="0 0 395 305" class="shadow">
<line x1="195" y1="70" x2="50" y2="200" stroke-width="1" class="line"/>
<line x1="195" y1="70" x2="195" y2="200" stroke-width="1" class="line"/>
<line x1="195" y1="70" x2="340" y2="200" stroke-width="1" class="line"/>

<ellipse cx="195" cy="70" rx="120" ry="70" class="ellipse"/>
<text x="50%" y="70" text-anchor="middle" dy=".3em">Some text...</text>

<circle cx="50" cy="250" r="50" class="circle"/>
<text x="50" y="250" text-anchor="middle" dy=".3em">Some text...</text>

<circle cx="195" cy="250" r="50" class="circle"/>
<text x="195" y="250" text-anchor="middle" dy=".3em">Some text...</text>

<circle cx="340" cy="250" r="50" class="circle"/>
<text x="340" y="250" text-anchor="middle" dy=".3em">Some text...</text>
</svg>

关于html - 使用 CSS 在节点之间绘制线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44048449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com