如何让组织结构图的连接线在响应式布局中保持对齐?
问题描述
我正在制作一张组织结构图,除连接线出现错位外其余显示正常。在响应式布局下,根据各框内内容不同,错位情况会加剧。请问有没有办法让连接线在移动端与桌面端保持同步对齐?感谢支持。
代码实现
CSS 代码
:root { --level-1: #8dccad; } .orgchart { margin: 0 auto; overflow: auto; height: 610px; width: 722px; } * { padding: 0; margin: 0; } ol { list-style: none; } .rectangle { position: relative; padding: 20px; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15); text-align: center; border: solid black 1px; font-size: 12px !important; transition: background-color 0.3s ease; /* Add a smooth transition effect */ /* Add a default background color */ background-color: #0071bc; } /* Add hover effect */ .rectangle:hover { background-color: #205493; /* Change the background color on hover */ } /* LEVEL-1 STYLES –––––––––––––––––––––––––––––––––––––––––––––––––– */ .level-1 { width: 50%; margin: 0 auto 40px; background: var(--level-1); text-align: center; color: white; } /* LEVEL-2 STYLES –––––––––––––––––––––––––––––––––––––––––––––––––– */ .level-2-wrapper { flex: 1; padding: 5px; margin: 0 20px; position: relative; } .level-2-wrapper::before { content: ""; position: absolute; top: -40px; left: 105%; width: 2px; height: calc(99.5%); background: #a1b8e1; } .level-2-wrapper li+li { margin-top: 20px; } .level-2 { font-weight: normal; color: #fff; } .level-2::before { content: ""; position: absolute; top: 50%; left: 109%; transform: translate(-100%, -50%); width: 17px; height: 2px; background: #a1b8e1; } .oc { display: flex; } /* LEVEL-2 STYLES –––––––––––––––––––––––––––––––––––––––––––––––––– */ .level-sub-wrapper { flex: 1; padding: 5px; margin: 0 20px; position: relative; } .level-sub-wrapper::before { content: ""; position: absolute; top: -40px; left: -10px; width: 2px; height: 23%; background: #a1b8e1; } .level-sub-wrapper li+li { margin-top: 20px; } .level-sub { font-weight: normal; background: #0071bc; color: #fff; } .level-sub::before { content: ""; position: absolute; top: 50%; left: 0%; transform: translate(-100%, -50%); width: 14px; height: 2px; background: #a1b8e1; } .level-sub-wrapper::after { content: ""; position: absolute; top: 24.2%; left: 80px; transform: translate(-50%, -50%); width: 2px; height: 21px; background: #a1b8e1; } .level-sub2 { font-weight: normal; color: #fff; } .orgchart a:visited { color: white; text-decoration: underline; } .orgchart a { color: #105183; text-decoration: none; font-size: 12px !important; } /* level-3 STYLES –––––––––––––––––––––––––––––––––––––––––––––––––– */ .level-3-wrapper { flex: 1; padding: 5px; margin: 0 20px; position: relative; } .level-3-wrapper::before { content: ""; position: absolute; top: -40px; left: 105%; width: 2px; height: calc(74%); background: #a1b8e1; } .level-3-wrapper li+li { margin-top: 20px; } .level-3 { font-weight: normal; color: #fff; } .level-3::before { content: ""; position: absolute; top: 50%; left: 109%; transform: translate(-100%, -50%); width: 17px; height: 2px; background: #a1b8e1; }
HTML 代码
<div class="rxbodyfield"> <div class="orgchart"> <h2 class="level-1 rectangle"> <a href="">CEO<br />Test1</a></h2> <div class="oc"> <ol class="level-2-wrapper"> <li> <div class="level-2 rectangle"><a href=""><strong>Manager1</strong><br /> Test ABCD</a></div> </li> <li> <div class="level-2 rectangle"><strong>Manager2</strong> <a href=""><br /> </a>Test</div> </li> <li> <div class="level-2 rectangle"><strong>Manager3</strong><br /> Test </div> </li> <li> <div class="level-2 rectangle"><strong>Manager4</strong><br /> Senior Chief Counsel<br>fdffdg<br>dfddffdfdffd</div> </li> </ol> <ol class="level-3-wrapper"> <li> <div class="level-3 rectangle"><strong>Manager5</strong><br /> Senior Deputy Director</div> </li> <li> <div class="level-3 rectangle"><strong>Manager 6</strong><br /> Blah blah blah blah</div> </li> <li> <div class="level-3 rectangle"><strong>Manager7</strong><br /> Test </div> </li> </ol> <ol class="level-sub-wrapper"> <li> <div class="level-sub rectangle"><strong>Manager8</strong><br /> Senior Staff</div> </li> <li> <div class="level-sub2 rectangle" style=" margin-left: 20px;"><strong>Manager9</strong><br /> Executive Director</div> </li> </ol> </div> </div> </div>
内容的提问来源于stack exchange,提问作者newuser
相关产品推荐
相关产品推荐

