css實(shí)現(xiàn)組織架構(gòu)圖2-一對(duì)多,再多對(duì)一,再對(duì)多

先看下效果圖


organization2.png

其中html代碼

<div class="org-tree">
  <ul>
    <li class="ceo">
      <div>
        <span>總經(jīng)理</span><br/>
        <span>張三,李四四四</span>
      </div>
      <ul>
        <li class="manager lineLeft">
          <div>技術(shù)總監(jiān)</div>
        </li>
        <li class="manager line">
          <i class="left"></i>
          <div>產(chǎn)品總監(jiān)</div>
          <i class="right"></i>
        </li>
        <li class="manager lineRight">
          <div>運(yùn)營(yíng)總監(jiān)</div>
        </li>
      </ul>
      <div class="companyManagerBox">
        <div class="companyManager">
          <span>總經(jīng)理</span><br/>
          <span>張三,李四四四</span>
        </div>
      </div>
      <ul>
        <li class="department">
          <div>前端開發(fā)部</div>
          <ul>
            <li class="employee">
              <div>
                <span>前端工程師A</span>
                <span>張三,李思思</span>
              </div>
            </li>
            <li class="employee"><div>前端工程師</div></li>
            <li class="employee"><div>前端工程師C</div></li>
          </ul>
        </li>
        <li class="department">
          <div>后端開發(fā)部</div>
          <ul>
            <li class="employee"><div>后端工程師A</div></li>
            <li class="employee"><div>
              <span>前端工程師A</span>
              <span>張三,李思思</span>
            </div></li>
            <li class="employee"><div>后端工程師C</div></li>
          </ul>
        </li>
        <li class="department">
          <div>測(cè)試部</div>
          <ul>
            <li class="employee"><div>測(cè)試工程師A</div></li>
            <li class="employee"><div>測(cè)試工程師B</div></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</div>

css代碼,主要用ullibefore、after偽元素進(jìn)行設(shè)置,其中ul偽元素主要用來(lái)實(shí)現(xiàn)連接下方的線,li的偽元素主要是來(lái)實(shí)現(xiàn)連接左右的線,li要加上padding,這樣可以實(shí)現(xiàn)左右有間隔距離,并且偽元素連接的線也正好是li的一半寬度

其中第二層組織,是單獨(dú)添加一個(gè)ul標(biāo)簽來(lái)實(shí)現(xiàn)的

ul,li{
  list-style: none;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.org-tree {
  display: flex;
  justify-content: center;
  padding: 20px;
}
.org-tree ul {
  position: relative;
  padding: 16px 0;
  margin: 0 auto;
  text-align: center;
  display: flex;
  justify-content: center;
}
.org-tree ul::after {
  content: '';
  display: block;
  clear: both;
}

.org-tree li {
  /* display: inline-block; */
  float: left;
  text-align: center;
  position: relative;
  padding: 16px 8px 0 8px;
}
.org-tree li::before,
.org-tree li::after {
  content: '';
  position: absolute;
  top: 0;
  right: 50%;
  border-top: 2px solid #ccc;
  width: 50%;
  height: 16px;
}

.org-tree li::after {
  left: 50%;
  border-left: 2px solid #ccc;
}
.org-tree li:first-child::before,
.org-tree li:last-child::after {
  border: 0 none;
}
.org-tree li:last-child::before {
  border-right: 2px solid #ccc;
  border-radius: 0 5px 0 0;
}

.org-tree li:first-child::after {
  border-radius: 5px 0 0 0;
}

.org-tree .ceo::after,
.org-tree .ceo::before {
  height: 0;
}
.org-tree ul ul::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  border-left: 2px solid #ccc;
  width: 0;
  height: 16px;
}
.org-tree li div {
  border: 2px solid #ccc;
  padding: 8px 3px;
  display: inline-block;
  border-radius: 5px;
  color: #333;
  font-size: 14px;
  background: #fff;
  width: 120px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.org-tree .employee div {
  width: 40px;
  height: 150px;
}
.org-tree .employee div span {
  display: inline-block;
}
.org-tree .employee div span:first-child { 
  margin-bottom: 10px;
}
.org-tree .companyManagerBox {
  border: 0;
  padding: 16px 8px 0 8px;
  box-shadow: none;
  background-color: transparent;
  width:auto;
  position: relative;
}
.org-tree .companyManagerBox::before{
  position: absolute;
  content: '';
  width: 50%;
  height: 16px;
  left: 0%;
  top: 0;
  border-right: 2px solid #ccc;
}
.line .left {
  position: absolute;
  content: '';
  width: 50%;
  height: 16px;
  left: 0%;
  bottom: -16px;
  border-bottom: 2px solid #ccc;
}
.line .right {
  position: absolute;
  content: '';
  width: 50%;
  height: 16px;
  left: 50%;
  bottom: -16px;
  border-left: 2px solid #ccc;
  border-bottom: 2px solid #ccc;
}
.org-tree .ceo .lineLeft::before {
  left: 50%;
  bottom: -16px;
  top: auto;
  border-left: 2px solid #ccc;
  border-bottom: 2px solid #ccc;
  border-radius: 0 0px 0 5px;
}
.org-tree .ceo .lineRight::after {
  right: 50%;
  bottom: -16px;
  left: auto;
  top: auto;
  border-right: 2px solid #ccc;
  border-bottom: 2px solid #ccc;
  border-radius: 0 0px 5px 0;
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • """1.個(gè)性化消息: 將用戶的姓名存到一個(gè)變量中,并向該用戶顯示一條消息。顯示的消息應(yīng)非常簡(jiǎn)單,如“Hello ...
    她即我命閱讀 5,069評(píng)論 0 6
  • 為了讓我有一個(gè)更快速、更精彩、更輝煌的成長(zhǎng),我將開始這段刻骨銘心的自我蛻變之旅!從今天開始,我將每天堅(jiān)持閱...
    李薇帆閱讀 2,246評(píng)論 1 4
  • 似乎最近一直都在路上,每次出來(lái)走的時(shí)候感受都會(huì)很不一樣。 1、感恩一直遇到好心人,很幸運(yùn)。在路上總是...
    時(shí)間里的花Lily閱讀 1,739評(píng)論 1 3
  • 1、expected an indented block 冒號(hào)后面是要寫上一定的內(nèi)容的(新手容易遺忘這一點(diǎn)); 縮...
    庵下桃花仙閱讀 1,078評(píng)論 1 2
  • 一、工具箱(多種工具共用一個(gè)快捷鍵的可同時(shí)按【Shift】加此快捷鍵選取)矩形、橢圓選框工具 【M】移動(dòng)工具 【V...
    墨雅丫閱讀 1,524評(píng)論 0 0

友情鏈接更多精彩內(nèi)容