【问题标题】:HTML/CSS Flowchart not fitting in screen viewHTML/CSS 流程图不适合屏幕视图
【发布时间】:2016-08-03 09:42:03
【问题描述】:

我正在尝试制作 HTML/CSS 流程图。我希望所有东西都适合宽度方向的一个屏幕视图,但目前还不是。我不介意单个盒子的宽度较小,盒子内的文字会换行。

我希望有人能够查看 CSS 代码 - 似乎应该有一个快速修复!

我从那里得到了原始代码: http://thecodeplayer.com/walkthrough/css3-family-tree

    <html>
<head>

<style>



li {
 white-space: nowrap; // stop the wrapping in the first place
 }

/*Now the CSS*/
 * {margin: 0; padding: 0;}

 .greenBox {
border: 2px solid #007f00 !important;
background-color:#e5ffe5;
}

.redBox {
border: 2px solid #FF0000 !important;
background-color:#ffe5e5;
}


.tree ul {
padding-top: 20px; position: relative;

transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}

.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;
}

/*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;
}

/*Thats all. I hope you enjoyed it.
Thanks :)*/
</style>


</head>

<body>
<!--
We will create a family tree using just CSS(3)
The markup will be simple nested lists
-->
<div class="tree" style="white-space: nowrap;">
<ul>
    <li>
    <a href="#">E. coli</a>
        <ul>
            <li>
                <a href="#">Live</a>
                <ul>
                    <li>
                        <a href="#">Keep</a>
                        <ul>
                            <li>
                            <a href="#">Excreted</a>
                                <ul>
                                    <li>
                                        <a href="#" class="greenBox">Effective waste treatment</a>
                                    </li>
                                    <li>
                                        <a href="#">Poor waste treatment</a>
                                        <ul>
                                            <li>
                                            <a href="#" class="redBox">Unknown consequence to environment</a>
                                            </li>
                                            <li>
                                                <a href="#">Contaminate other people</a>
                                            </li>
                                        </ul>
                                    </li>
                                </ul>
                            </li>
                            <li>
                                <a href="#">Stay in gut</a>
                                <ul>
                                    <li>
                                        <a href="#" class="redBox">Work too well -> copper deficiency risk</a>
                                    </li>
                                    <li>
                                        <a href="#">Imbalance (overgrowth)</a>
                                        <ul>
                                    <li>
                                        <a href="#" class="redBox">Progressive recovery of the microbiome</a>
                                    </li>
                                            <li>
                                        <a href="#" class="redBox">Unpredictable damage</a>
                                    </li>
                                            <li>
                                        <a href="#" class="redBox">Digestive disorder</a>
                                    </li>
                                </ul>
                                    </li>
                                    <li>
                                        <a href="#">Equilibrium with other flora</a>
                                        <ul>
                                    <li>
                                        <a href="#" class="redBox">Share genetic information - unknown danger</a>
                                        <ul>

                                </ul>
                                    </li>
                                    <li>
                                        <a href="#" class="redBox">Mutation - unknown danger</a>
                                        <ul>

                                </ul>
                                    </li>
                                            <li>
                                        <a href="#" class="redBox">Integration into microbiome - danger</a>
                                    </li>
                                </ul>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <a href="#" class="greenBox">Lose plasmid</a>
                    </li>
                </ul>
            </li>

            <li>
                <a href="#">Dead</a>
                <ul>
                    <li>
                         <a href="#">After low absorption</a>
                        <ul>
                            <li>
                                <a href="#" class="greenBox">No consequence</a>
                            </li>
                            <li>
                                <a href="#" class="greenBox">Modification of the gut microbiome</a>
                            </li>
                        </ul>
                    </li>
                    <li>
                         <a href="#">After high absorption</a>
                        <ul>
                            <li>
                                <a href="#">Modify Cu level significantly</a>
                                <ul>
                            <li>
                                <a href="#" class="greenBox">No consequence</a>
                            </li>
                            <li>
                                <a href="#">Modification of the gut microbiome</a>

                                <ul>
                            <li>
                                <a href="#" class="greenBox">Proliferation of neutral strains</a>
                            </li>
                            <li>
                                <a href="#" class="greenBox">Proliferation of pathogenic strains</a>
                            </li>
                        </ul>
                            </li>
                        </ul>
                            </li>
                            <li>
                                <a href="#" class="greenBox">Very low Cu absorption by gut</a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
    </li>
</ul>
</div>



</body>
</html>

【问题讨论】:

    标签: html css formatting html-lists flowchart


    【解决方案1】:

    因为你使用 float for .tree li 。当列表元素占据 .tree 整个宽度时,它会进入下一行。所以给你的父容器一个宽度

    检查这个小提琴:我已经更新了你的代码

    【讨论】:

    • Jsfiddle.net/ygpyn20f
    • 亲爱的subbu1191,非常感谢,这已经解决了它被分解的问题。现在的另一个问题是我需要按宽度滚动才能看到整个内容。我想知道是否有一种方法可以使框的宽度自动变窄,以便整个内容适合一页,而文本可以换行成多行?非常非常感谢!
    【解决方案2】:

    非常感谢,这解决了它被分解的问题。现在的另一个问题是我需要按宽度滚动才能看到整个内容。我想知道是否有一种方法可以使框的宽度自动变窄,以便整个内容适合一页,文本换行成多行?

    非常感谢! 高拉夫

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-08
      • 1970-01-01
      • 1970-01-01
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-08
      相关资源
      最近更新 更多