【问题标题】:CSS vertical to horizontal flow chartCSS垂直到水平流程图
【发布时间】:2015-10-20 14:16:09
【问题描述】:

我一直在玩这支笔,但不知道如何使它水平而不是垂直,这样父母首先会垂直居中,然后孩子会向右而不是从上到下。

http://codepen.io/abennington/pen/MajVxa

* {
  margin: 0;
  padding: 0;
}
.tree {
  white-space: nowrap;
  display: block;
  overflow: auto;
  width: auto !important;
}
.tree ul {
  padding-top: 20px;
  position: relative;
  transition: all 0.5s;
  -webkit-transition: all 0.5s;
  -moz-transition: all 0.5s;
  white-space: nowrap;
}
.tree li {
  float: left;
  text-align: center;
  list-style-type: none;
  position: relative;
  padding: 20px 5px 0 5px;
  transition: all 0.5s;
  -webkit-transition: all 0.5s;
  -moz-transition: all 0.5s;
  white-space: normal;
  display: inline-block;
}
/*We will use ::before and ::after to draw the connectors*/

.tree li::before,
.tree li::after {
  content: '';
  position: absolute;
  top: 0;
  right: 50%;
  border-top: 1px solid #ccc;
  width: 50%;
  height: 20px;
}
.tree li::after {
  right: auto;
  left: 50%;
  border-left: 1px solid #ccc;
}
/*We need to remove left-right connectors from elements without 
    any siblings*/

.tree li:only-child::after,
.tree li:only-child::before {
  display: none;
}
/*Remove space from the top of single children*/

.tree li:only-child {
  padding-top: 0;
}
/*Remove left connector from first child and 
    right connector from last child*/

.tree li:first-child::before,
.tree li:last-child::after {
  border: 0 none;
}
/*Adding back the vertical connector to the last nodes*/

.tree li:last-child::before {
  border-right: 1px solid #ccc;
  border-radius: 0 5px 0 0;
  -webkit-border-radius: 0 5px 0 0;
  -moz-border-radius: 0 5px 0 0;
}
.tree li:first-child::after {
  border-radius: 5px 0 0 0;
  -webkit-border-radius: 5px 0 0 0;
  -moz-border-radius: 5px 0 0 0;
}
/*Time to add downward connectors from parents*/

.tree ul ul::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  border-left: 1px solid #ccc;
  width: 0;
  height: 20px;
}
.tree li a {
  border: 1px solid #ccc;
  padding: 5px 10px;
  text-decoration: none;
  color: #666;
  font-family: arial, verdana, tahoma;
  font-size: 11px;
  display: inline-block;
  border-radius: 5px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  transition: all 0.5s;
  -webkit-transition: all 0.5s;
  -moz-transition: all 0.5s;
}
/*Time for some hover effects*/

/*We will apply the hover effect the the lineage of the element also*/

.tree li a:hover,
.tree li a:hover+ul li a {
  background: #c8e4f8;
  color: #000;
  border: 1px solid #94a0b4;
}
/*Connector styles on hover*/

.tree li a:hover+ul li::after,
.tree li a:hover+ul li::before,
.tree li a:hover+ul::before,
.tree li a:hover+ul ul::before {
  border-color: #94a0b4;
}
<div class="tree">
  <ul>
    <li>
      <a href="#">Parent</a>
      <ul>
        <li>
          <a href="#">Child</a>
          <ul>
            <li>
              <a href="#">Grand Child</a>
            </li>
            <li>
              <a href="#">Grand Child</a>
              <ul>
                <li>
                  <a href="#">Grand Child</a>
                </li>
                <li>
                  <a href="#">Grand Child</a>
                  <ul>
                    <li>
                      <a href="#">Grand Child</a>
                    </li>
                    <li>
                      <a href="#">Grand Child</a>
                    </li>
                  </ul>
                </li>
              </ul>
            </li>
          </ul>
        </li>
        <li>
          <a href="#">Child</a>
          <ul>
            <li><a href="#">Grand Child</a>
            </li>
            <li>
              <a href="#">Grand Child</a>
              <ul>
                <li>
                  <a href="#">Great Grand Child</a>
                </li>
                <li>
                  <a href="#">Great Grand Child</a>
                </li>
                <li>
                  <a href="#">Great Grand Child</a>
                </li>
              </ul>
            </li>
            <li><a href="#">Grand Child</a>
            </li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</div>

非常感谢任何帮助!

【问题讨论】:

  • 它已经是垂直流动的了,也许你想把它变成水平的?
  • 您尝试的代码在哪里。?预计您至少会尝试自己编写代码。 Stack Overflow 不是代码编写服务。我建议你做一些额外的研究,无论是通过谷歌还是通过搜索,尝试一下。如果您仍然遇到问题,请返回您的代码并解释您尝试过的方法以及为什么它不起作用。
  • 是的,抱歉它应该是水平的。
  • 我尝试的代码是如此的失败,以至于我试图做的事情毫无意义。我已经搜索了所有内容,但没有得到 Google 的帮助。
  • 你可以参考codepen.io/P233/pen/Kzbsi

标签: html list css flowchart


【解决方案1】:

也许这会有所帮助。

.tree {
  box-sizing: border-box;
  outline: none;
  display: flex;
  justify-content: center;
  margin: 0;
  padding: 0;
  list-style: none;
  width: 100%;
  text-align: center;
  font-size: 2vw;
}

.tree *,
.tree *::after,
.tree *::before {
  box-sizing: border-box;
  outline: none;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tree ul {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  position: relative;
  padding: 0;
}

.tree ul:after {
  content: '';
  position: absolute;
  top: 50%;
  left: .5em;
  width: 1em;
  border-top: 1px solid black;
}

.tree > ul {
  padding: 0;
}

.tree li {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  position: relative;
  padding: .5em 1em .5em 3em;
}

.tree li:before {
  content: '';
  position: absolute;
  top: 0;
  left: 1.5em;
  height: 100%;
  border-left: 1px solid black;
}

.tree li:after {
  content: '';
  position: absolute;
  top: 50%;
  left: 1.5em;
  width: 1em;
  border-top: 1px solid black;
}

.tree li:first-child:before {
  top: 50%;
  height: 50%;
}

.tree li:last-child:before {
  bottom: 50%;
  height: 50%;
}

.tree li:only-child:before {
  display: none;
}

.tree > li {
  padding: 0;
}

.tree > li:before, .tree > li:after {
  display: none;
}

.tree li a:hover, .tree li a:hover+ul li a {
    background: #c8e4f8; color: #000; border: 1px solid #94a0b4;
}

.tree li a:hover+ul li::after, 
.tree li a:hover+ul li::before, 
.tree li a:hover+ul::before, 
.tree li a:hover+ul ul::before,
.tree li a:hover+ul::after,
.tree li a:hover+ul ul::after
{
    border-color:  #94a0b4;
}

【讨论】:

猜你喜欢
  • 2014-02-23
  • 2010-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-01
  • 2016-05-23
  • 2011-01-29
相关资源
最近更新 更多