我尝试修改此demo in codepen
中的代码我想让它看起来像下面的图表,但不知道如何自定义它:
这是一个包含原始代码的片段 - 欢迎任何建议。
Func<string, string> transformer = str => str.ToUpper();
&#13;
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
position: relative;
}
.cf:before,
.cf:after {
content: " ";
/* 1 */
display: table;
/* 2 */
}
.cf:after {
clear: both;
}
/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.cf {
*zoom: 1;
}
/* Generic styling */
body {
background: #F5EEC9;
}
.content {
width: 100%;
max-width: 1142px;
margin: 0 auto;
padding: 0 20px;
}
a:focus {
outline: 2px dashed #f7f7f7;
}
@media all and (max-width: 767px) {
.content {
padding: 0 20px;
}
}
ul {
padding: 0;
margin: 0;
list-style: none;
}
ul a {
display: block;
background: #ccc;
border: 4px solid #fff;
text-align: center;
overflow: hidden;
font-size: .7em;
text-decoration: none;
font-weight: bold;
color: #333;
height: 70px;
margin-bottom: -26px;
box-shadow: 4px 4px 9px -4px rgba(0, 0, 0, 0.4);
-webkit-transition: all linear .1s;
-moz-transition: all linear .1s;
transition: all linear .1s;
}
@media all and (max-width: 767px) {
ul a {
font-size: 1em;
}
}
ul a span {
top: 50%;
margin-top: -0.7em;
display: block;
}
/*
*/
.administration>li>a {
margin-bottom: 25px;
}
.director>li>a {
width: 50%;
margin: 0 auto 0px auto;
}
.subdirector:after {
content: "";
display: block;
width: 0;
height: 130px;
background: red;
border-left: 4px solid #fff;
left: 45.45%;
position: relative;
}
.subdirector,
.departments {
position: absolute;
width: 100%;
}
.subdirector>li:first-child,
.departments>li:first-child {
width: 18.59894921190893%;
height: 64px;
margin: 0 auto 92px auto;
padding-top: 25px;
border-bottom: 4px solid white;
z-index: 1;
}
.subdirector>li:first-child {
float: right;
right: 27.2%;
border-left: 4px solid white;
}
.departments>li:first-child {
float: left;
left: 27.2%;
border-right: 4px solid white;
}
.subdirector>li:first-child a,
.departments>li:first-child a {
width: 100%;
}
.subdirector>li:first-child a {
left: 25px;
}
@media all and (max-width: 767px) {
.subdirector>li:first-child,
.departments>li:first-child {
width: 40%;
}
.subdirector>li:first-child {
right: 10%;
margin-right: 2px;
}
.subdirector:after {
left: 49.8%;
}
.departments>li:first-child {
left: 10%;
margin-left: 2px;
}
}
.departments>li:first-child a {
right: 25px;
}
.department:first-child,
.departments li:nth-child(2) {
margin-left: 0;
clear: left;
}
.departments:after {
content: "";
display: block;
position: absolute;
width: 81.1%;
height: 22px;
border-top: 4px solid #fff;
border-right: 4px solid #fff;
border-left: 4px solid #fff;
margin: 0 auto;
top: 130px;
left: 9.1%
}
@media all and (max-width: 767px) {
.departments:after {
border-right: none;
left: 0;
width: 49.8%;
}
}
@media all and (min-width: 768px) {
.department:first-child:before,
.department:last-child:before {
border: none;
}
}
.department:before {
content: "";
display: block;
position: absolute;
width: 0;
height: 22px;
border-left: 4px solid white;
z-index: 1;
top: -22px;
left: 50%;
margin-left: -4px;
}
.department {
border-left: 4px solid #fff;
width: 18.59894921190893%;
float: left;
margin-left: 1.751313485113835%;
margin-bottom: 60px;
}
.lt-ie8 .department {
width: 18.25%;
}
@media all and (max-width: 767px) {
.department {
float: none;
width: 100%;
margin-left: 0;
}
.department:before {
content: "";
display: block;
position: absolute;
width: 0;
height: 60px;
border-left: 4px solid white;
z-index: 1;
top: -60px;
left: 0%;
margin-left: -4px;
}
.department:nth-child(2):before {
display: none;
}
}
.department>a {
margin: 0 0 -26px -4px;
z-index: 1;
}
.department>a:hover {
height: 80px;
}
.department>ul {
margin-top: 0px;
margin-bottom: 0px;
}
.department li {
padding-left: 25px;
border-bottom: 4px solid #fff;
height: 80px;
}
.department li a {
background: #fff;
top: 48px;
position: absolute;
z-index: 1;
width: 90%;
height: 60px;
vertical-align: middle;
right: -1px;
background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMTAwJSI+CiAgICA8c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjMDAwMDAwIiBzdG9wLW9wYWNpdHk9IjAuMjUiLz4KICAgIDxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIgc3RvcC1vcGFjaXR5PSIwIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background-image: -moz-linear-gradient(-45deg, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 100%) !important;
background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0%, rgba(0, 0, 0, 0.25)), color-stop(100%, rgba(0, 0, 0, 0)))!important;
background-image: -webkit-linear-gradient(-45deg, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 100%)!important;
background-image: -o-linear-gradient(-45deg, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 100%)!important;
background-image: -ms-linear-gradient(-45deg, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 100%)!important;
background-image: linear-gradient(135deg, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 100%)!important;
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#40000000', endColorstr='#00000000', GradientType=1);
}
.department li a:hover {
box-shadow: 8px 8px 9px -4px rgba(0, 0, 0, 0.1);
height: 80px;
width: 95%;
top: 39px;
background-image: none!important;
}
/* Department/ section colors */
.department.dep-a a {
background: #FFD600;
}
.department.dep-b a {
background: #AAD4E7;
}
.department.dep-c a {
background: #FDB0FD;
}
.department.dep-d a {
background: #A3A2A2;
}
.department.dep-e a {
background: #f0f0f0;
}
&#13;
答案 0 :(得分:0)
作为替代图表工具,您可以使用Google Visualizations - Charts
以下是 Stack Snippets 中的示例:
library(tidyverse)
separate_rows(quest, key_value, sep=";") %>%
separate(key_value, into = c("key", "value"), sep="=") %>%
separate_rows(value, sep="[|]", convert = TRUE) %>%
group_by(city, key) %>%
mutate(rn = row_number()) %>%
spread(key, value) %>%
select(-rn)
# A tibble: 7 x 4
# Groups: city [3]
# city qty rev zip
#* <fctr> <dbl> <dbl> <dbl>
#1 Atlanta 1 63.0 45987
#2 Atlanta 1 12.0 74268
#3 New York 1 10.6 12686
#4 New York 2 34.0 12694
#5 Tampa 1 3.0 33684
#6 Tampa 6 24.0 36842
#7 Tampa 3 8.0 30254
&#13;
google.charts.load('current', {
packages: ["orgchart"]
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'Manager');
data.addColumn('string', 'ToolTip');
// For each orgchart box, provide the name, manager, and tooltip to show.
data.addRows([
[{
v: 'Mike',
f: 'Mike<div style="color:red; font-style:italic">President</div>'
},
'', 'The President'
],
[{
v: 'Jim',
f: 'Jim<div style="color:red; font-style:italic">Vice President</div>'
},
'Mike', 'VP'
],
[{
v: 'Ankush',
f: 'Ankush<div style="color:red; font-style:italic">Home minister</div>'
},
'Jim', 'HM'
],
['Alice', 'Mike', ''],
['Bob', 'Jim', 'Bob Sponge'],
['Carol', 'Bob', '']
]);
// Create the chart.
var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
// Draw the chart, setting the allowHtml option to true for the tooltips.
chart.draw(data, {
allowHtml: true
});
}
&#13;
.google-visualization-orgchart-table {
border: 0;
text-align: center;
}
.google-visualization-orgchart-table * {
margin: 0;
padding: 2px;
}
.google-visualization-orgchart-space-small {
width: 4px;
height: 1px;
border: 0;
}
.google-visualization-orgchart-space-medium {
width: 10px;
height: 1px;
border: 0;
}
.google-visualization-orgchart-space-large {
width: 16px;
height: 1px;
border: 0;
}
.google-visualization-orgchart-noderow-small {
height: 12px;
border: 0;
}
.google-visualization-orgchart-noderow-medium {
height: 30px;
border: 0;
}
.google-visualization-orgchart-noderow-large {
height: 46px;
border: 0;
}
.google-visualization-orgchart-connrow-small {
height: 2px;
font-size: 1px;
}
.google-visualization-orgchart-connrow-medium {
height: 6px;
font-size: 4px;
}
.google-visualization-orgchart-connrow-large {
height: 10px;
font-size: 8px;
}
.google-visualization-orgchart-node {
text-align: center;
vertical-align: middle;
font-family: arial, helvetica;
cursor: default;
border: 2px solid #b5d9ea;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-webkit-box-shadow: rgba(0, 0, 0, 0.5) 3px 3px 3px;
-moz-box-shadow: rgba(0, 0, 0, 0.5) 3px 3px 3px;
background-color: #edf7ff;
background: -webkit-gradient(linear, left top, left bottom, from(#edf7ff), to(#cde7ee));
}
.google-visualization-orgchart-nodesel {
border: 2px solid #e3ca4b;
background-color: #fff7ae;
background: -webkit-gradient(linear, left top, left bottom, from(#fff7ae), to(#eee79e));
}
.google-visualization-orgchart-node-small {
font-size: 0.6em;
}
.google-visualization-orgchart-node-medium {
font-size: 0.8em;
}
.google-visualization-orgchart-node-large {
font-size: 1.2em;
font-weight: bold;
}
.google-visualization-orgchart-linenode {
border: 0;
}
.google-visualization-orgchart-lineleft {
border-left: 1px solid #3388dd;
}
.google-visualization-orgchart-lineright {
border-right: 1px solid #3388dd;
}
.google-visualization-orgchart-linebottom {
border-bottom: 1px solid #3388dd;
}
table {
width: 45% !important;
margin: auto !important;
}
.google-visualization-orgchart-table * {
margin: 0;
padding: 13px 0 !important;
}
&#13;
答案 1 :(得分:0)
它不是世界上最具扩展性的代码段,但第一项任务是实际更改HTML以反映新的语义结构。这很容易。
CSS并不是真正用于处理n
级别的复杂单元或非常好的扩展,但您可以在那里使用什么来移动屏幕上的元素。这应该让你从一个非常高的水平开始,但是你应该熟悉进行个别调整以查看通过并尝试提出更尖锐的问题,如果你遇到困难试图完成一项特定的任务。
下面的代码段如下所示:
*{
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
position: relative;
}
.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.cf:after {
clear: both;
}
/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.cf {
*zoom: 1;
}
/* Generic styling */
body{
background: #F5EEC9;
}
.content{
width: 100%;
max-width: 1142px;
margin: 0 auto;
padding: 0 20px;
}
a:focus{
outline: 2px dashed #f7f7f7;
}
@media all and (max-width: 767px){
.content{
padding: 0 20px;
}
}
ul{
padding: 0;
margin: 0;
list-style: none;
}
ul a{
display: block;
background: #ccc;
border: 4px solid #fff;
text-align: center;
overflow: hidden;
font-size: .7em;
text-decoration: none;
font-weight: bold;
color: #333;
height: 70px;
margin-bottom: -26px;
box-shadow: 4px 4px 9px -4px rgba(0,0,0,0.4);
-webkit-transition: all linear .1s;
-moz-transition: all linear .1s;
transition: all linear .1s;
}
@media all and (max-width: 767px){
ul a{
font-size: 1em;
}
}
ul a span{
top: 50%;
margin-top: -0.7em;
display: block;
}
/*
*/
.administration > li > a{
margin-bottom: 25px;
}
.director > li > a{
width: 50%;
margin: 0 auto 0px auto;
}
.subdirector:after{
content: "";
display: block;
width: 0;
height: 130px;
background: red;
border-left: 4px solid #fff;
left: 45.45%;
position: relative;
}
.subdirector,
.departments{
position: absolute;
width: 100%;
}
.departments > li:first-child{
width: 18.59894921190893%;
height: 66px;
/* margin: 0 auto 92px auto; */
padding-top: 25px;
/* border-bottom: 4px solid white;*/
/* z-index: 1; */
}
.departments > li:first-child{
/* float: left; */
left: 27.2%;
border-right: 4px solid white;
}
.departments > li:first-child a{
width: 100%;
}
@media all and (max-width: 767px){
.subdirector > li:first-child,
.departments > li:first-child{
width: 40%;
}
.subdirector > li:first-child{
right: 10%;
margin-right: 2px;
}
.subdirector:after{
left: 49.8%;
}
.departments > li:first-child{
left: 10%;
margin-left: 2px;
}
}
.departments > li:first-child a{
right: 25px;
}
.department:first-child,
.departments li:nth-child(2){
/*margin-left: 0; */
/*clear: left; */
margin-left: 12%
}
.departments:after{
content: "";
display: block;
position: absolute;
width: 48.2%;
height: 22px;
border-top: 4px solid #fff;
border-right: 4px solid #fff;
border-left: 4px solid #fff;
margin: 0 auto;
top: 38px;
left: 21%
}
@media all and (max-width: 767px){
.departments:after{
border-right: none;
left: 0;
width: 49.8%;
}
}
@media all and (min-width: 768px){
.department:first-child:before,
.department:last-child:before{
border:none;
}
}
.department:before{
content: "";
display: block;
position: absolute;
width: 0;
height: 22px;
border-left: 4px solid white;
z-index: 1;
top: -22px;
left: 50%;
margin-left: -4px;
}
.department{
border-left: 4px solid #fff;
width: 18.59894921190893%;
float: left;
margin-left: 5.751313485113835%;
margin-bottom: 60px;
}
.lt-ie8 .department{
width: 18.25%;
}
@media all and (max-width: 767px){
.department{
float: none;
width: 100%;
margin-left: 0;
}
.department:before{
content: "";
display: block;
position: absolute;
width: 0;
height: 60px;
border-left: 4px solid white;
z-index: 1;
top: -60px;
left: 0%;
margin-left: -4px;
}
.department:nth-child(2):before{
display: none;
}
}
.department > a{
margin: 0 0 -26px -4px;
z-index: 1;
}
.department > a:hover{
height: 80px;
}
.department > ul{
margin-top: 0px;
margin-bottom: 0px;
}
.department li{
padding-left: 25px;
border-bottom: 4px solid #fff;
height: 80px;
}
.department li a{
background: #fff;
top: 48px;
position: absolute;
z-index: 1;
width: 90%;
height: 60px;
vertical-align: middle;
right: -1px;
background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMTAwJSI+CiAgICA8c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjMDAwMDAwIiBzdG9wLW9wYWNpdHk9IjAuMjUiLz4KICAgIDxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIgc3RvcC1vcGFjaXR5PSIwIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background-image: -moz-linear-gradient(-45deg, rgba(0,0,0,0.25) 0%, rgba(0,0,0,0) 100%) !important;
background-image: -webkit-gradient(linear, left top, right bottom, color-stop(0%,rgba(0,0,0,0.25)), color-stop(100%,rgba(0,0,0,0)))!important;
background-image: -webkit-linear-gradient(-45deg, rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 100%)!important;
background-image: -o-linear-gradient(-45deg, rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 100%)!important;
background-image: -ms-linear-gradient(-45deg, rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 100%)!important;
background-image: linear-gradient(135deg, rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 100%)!important;
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#40000000', endColorstr='#00000000',GradientType=1 );
}
.department li a:hover{
box-shadow: 8px 8px 9px -4px rgba(0,0,0,0.1);
height: 80px;
width: 95%;
top: 39px;
background-image: none!important;
}
/* Department/ section colors */
.director a{ background: #5b9bd5; }
.department.dep-b a{ background: #ed7d31; }
.department.dep-c a{ background: #70ad47; }
.department.dep-d a{ background: #ffc000; }
&#13;
<div class="content">
<h1>Responsive Organization Chart</h1>
<figure class="org-chart cf">
<ul class="administration">
<li>
<ul class="director">
<li>
<a href="#"><span>Director</span></a>
<ul class="departments cf">
<li></li>
<li class="department dep-b">
<a href="#"><span>Department B</span></a>
<ul class="sections">
<li class="section"><a href="#"><span>Section B1</span></a></li>
<li class="section"><a href="#"><span>Section B2</span></a></li>
<li class="section"><a href="#"><span>Section B3</span></a></li>
<li class="section"><a href="#"><span>Section B4</span></a></li>
</ul>
</li>
<li class="department dep-c">
<a href="#"><span>Department C</span></a>
<ul class="sections">
<li class="section"><a href="#"><span>Section C1</span></a></li>
<li class="section"><a href="#"><span>Section C2</span></a></li>
<li class="section"><a href="#"><span>Section C3</span></a></li>
<li class="section"><a href="#"><span>Section C4</span></a></li>
</ul>
</li>
<li class="department dep-d">
<a href="#"><span>Department D</span></a>
<ul class="sections">
<li class="section"><a href="#"><span>Section D1</span></a></li>
<li class="section"><a href="#"><span>Section D2</span></a></li>
<li class="section"><a href="#"><span>Section D3</span></a></li>
<li class="section"><a href="#"><span>Section D4</span></a></li>
<li class="section"><a href="#"><span>Section D5</span></a></li>
<li class="section"><a href="#"><span>Section D6</span></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</figure>
</div>
&#13;