Ich habe ein SVG-Hexagon-Raster, das um 45 Grad geneigt ist. Auf einzelnen Hexfeldern möchte ich Bilder (dargestellt durch die roten Rechtecke) platzieren, die scheinbar senkrecht zur Gitterebene stehen. Die Bilder/Rechtecke müssen nicht notwendigerweise volle 90 Grad haben, aber ich habe die schwierigste Zeit, sie dazu zu bringen, eine Perspektive zu haben, die sich sogar ein wenig von der Ebene unterscheidet.Einstellung der richtigen Perspektive für untergeordnete Elemente auf einer 3D-Ebene in CSS
Gibt es eine Möglichkeit, die Perspektive für untergeordnete Elemente zu deaktivieren oder die CSS-Transformationen irgendwie zu überarbeiten, damit dies richtig aussieht?
-Code
.display {
animation: displayFlicker 100ms cubic-bezier(.37, 0, .41, 1.74) 100ms 1 normal forwards;
-webkit-animation: displayFlicker 100ms cubic-bezier(.37, 0, .41, 1.74) 100ms 1 normal forwards;
background: #000;
display: block;
border-left: 0.25rem solid #000;
border-right: 0.25rem solid #000;
box-sizing: border-box;
-moz-box-sizing: border-box;
height: 480px;
overflow: hidden;
width: 1096px;
}
#hexGrid {
box-sizing: border-box;
-moz-box-sizing: border-box;
display: block;
height: 100%;
-webkit-transform: perspective(44vw) rotateX(45deg) scale3d(1.6, 1.6, 1.6);
-moz-transform: perspective(44vw) rotateX(45deg) scale3d(1.6, 1.6, 1.6);
-ms-transform: perspective(44vw) rotateX(45deg) scale3d(1.6, 1.6, 1.6);
-o-transform: perspective(44vw) rotateX(45deg) scale3d(1.6, 1.6, 1.6);
transform: perspective(44vw) rotateX(45deg) scale3d(1.6, 1.6, 1.6);
transform-style: preserve-3d;
width: 100%;
}
.hexContainer {
outline: none;
transform-style: preserve-3d;
}
.hex {
box-sizing: border-box;
-moz-box-sizing: border-box;
display: inline-block;
height: 4.4vmin;
opacity: 1;
outline: none;
position: relative;
stroke: #0CF;
stroke-width: 0.0625rem;
transform: scale3d(1, 1, 1);
transition: all linear 300ms;
width: 8vmin;
}
.hex.open {
fill: rgba(0, 204, 255, 0.3);
}
.hex.blocked {
fill: url(#blockedHexPattern);
fill-opacity: 0.3;
}
.hexContainer:focus .open, .hexContainer:hover .open {
cursor: pointer;
fill: rgba(0, 204, 255, 0.8);
outline: none;
}
.hexContainer:focus .blocked, .hexContainer:hover .blocked {
cursor: pointer;
fill: url(#blockedHexPattern);
fill-opacity: 1;
outline: none;
}
.hexContainer:focus .occupied, .hexContainer:hover .occupied {
cursor: pointer;
fill: rgba(50, 50, 50, 0.8);
outline: none;
}
.hexContainer:focus .open, .hexContainer:focus .open.unblock {
transform-origin: 50% 0%;
}
.hexContainer:focus .blocked {
opacity: 1;
transform-origin: 50% 0%;
}
.hexContainer.active .open {
fill: rgba(0, 204, 255, 0.8);
opacity: 1;
}
#blockedHexPattern line {
stroke: #0CF;
stroke-width: 0.0625rem;
}
#hexGrid .rect {
transform: rotateX(0deg);
}
<div id="stationMap" class="display">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="55 -30 360 360" id="hexGrid">
<defs>
<pattern x="0" y="0" height="10" width="10" patternUnits="userSpaceOnUse" id="blockedHexPattern">
<line x1="0" y1="10" x2="10" y2="0"></line>
</pattern>
</defs>
<a id="hex0-0" class="hexContainer">
<polygon class="hex open" points="81.96152422706632,45 55.98076211353316,60 30,45 30.000000000000004,14.999999999999996 55.98076211353315,0 81.96152422706632,14.999999999999986"></polygon>
</a>
<a id="hex0-2" class="hexContainer">
<polygon class="hex blocked" points="185.88457268119896,45 159.9038105676658,60 133.92304845413264,45 133.92304845413264,14.999999999999996 159.9038105676658,0 185.88457268119896,14.999999999999986" fill="url(#blockedHexPattern)"></polygon>
</a>
<a id="hex0-6" class="hexContainer">
<polygon class="hex blocked" points="393.7306695894642,45 367.749907475931,60 341.76914536239786,45 341.76914536239786,14.999999999999996 367.749907475931,0 393.7306695894642,14.999999999999986" fill="url(#blockedHexPattern)"></polygon>
</a>
<a id="hex0-7" class="hexContainer">
<polygon class="hex blocked" points="445.6921938165305,45 419.71143170299734,60 393.7306695894642,45 393.7306695894642,14.999999999999996 419.71143170299734,0 445.6921938165305,14.999999999999986" fill="url(#blockedHexPattern)"></polygon>
</a>
<a id="hex1-0" class="hexContainer">
<polygon class="hex open" points="55.98076211353316,90 30.000000000000004,105 4.01923788646684,90 4.019237886466843,60 29.999999999999993,45 55.98076211353315,59.999999999999986"></polygon>
<rect class="rect" fill="red" x="5" y="67.5" width="50" height="40"/>
</a>
<a id="hex1-3" class="hexContainer">
<polygon class="hex blocked" points="211.8653347947321,90 185.88457268119893,105 159.90381056766577,90 159.90381056766577,60 185.88457268119893,45 211.8653347947321,59.999999999999986" fill="url(#blockedHexPattern)"></polygon>
</a>
<a id="hex1-4" class="hexContainer">
<polygon class="hex open" points="263.82685902179844,90 237.84609690826525,105 211.8653347947321,90 211.8653347947321,60 237.84609690826525,45 263.8268590217984,59.999999999999986"></polygon>
</a>
<a id="hex1-5" class="hexContainer">
<polygon class="hex open" points="315.7883832488647,90 289.80762113533154,105 263.8268590217984,90 263.8268590217984,60 289.80762113533154,45 315.7883832488647,59.999999999999986"></polygon>
</a>
<a id="hex1-6" class="hexContainer">
<polygon class="hex open" points="367.749907475931,90 341.76914536239786,105 315.7883832488647,90 315.7883832488647,60 341.76914536239786,45 367.749907475931,59.999999999999986"></polygon>
</a>
<a id="hex1-7" class="hexContainer">
<polygon class="hex open" points="419.71143170299734,90 393.7306695894642,105 367.749907475931,90 367.749907475931,60 393.7306695894642,45 419.71143170299734,59.999999999999986"></polygon>
<rect class="rect" fill="red" x="369" y="67.5" width="50" height="40"/>
</a>
<a id="hex2-0" class="hexContainer">
<polygon class="hex open" points="81.96152422706632,134.99999999999997 55.98076211353316,150 30,134.99999999999997 30.000000000000004,104.99999999999999 55.98076211353315,89.99999999999999 81.96152422706632,104.99999999999997"></polygon>
</a>
<a id="hex2-2" class="hexContainer">
<polygon class="hex blocked" points="185.88457268119896,134.99999999999997 159.9038105676658,150 133.92304845413264,134.99999999999997 133.92304845413264,104.99999999999999 159.9038105676658,89.99999999999999 185.88457268119896,104.99999999999997" fill="url(#blockedHexPattern)"></polygon>
</a>
<a id="hex2-3" class="hexContainer">
<polygon class="hex open" points="237.84609690826525,134.99999999999997 211.8653347947321,150 185.88457268119893,134.99999999999997 185.88457268119893,104.99999999999999 211.8653347947321,89.99999999999999 237.84609690826525,104.99999999999997"></polygon>
</a>
<a id="hex2-4" class="hexContainer">
<polygon class="hex open" points="289.80762113533154,134.99999999999997 263.8268590217984,150 237.84609690826522,134.99999999999997 237.84609690826522,104.99999999999999 263.8268590217984,89.99999999999999 289.80762113533154,104.99999999999997"></polygon>
</a>
<a id="hex2-5" class="hexContainer">
<polygon class="hex open" points="341.76914536239786,134.99999999999997 315.7883832488647,150 289.80762113533154,134.99999999999997 289.80762113533154,104.99999999999999 315.7883832488647,89.99999999999999 341.76914536239786,104.99999999999997"></polygon>
</a>
<a id="hex2-6" class="hexContainer">
<polygon class="hex open" points="393.7306695894642,134.99999999999997 367.749907475931,150 341.76914536239786,134.99999999999997 341.76914536239786,104.99999999999999 367.749907475931,89.99999999999999 393.7306695894642,104.99999999999997"></polygon>
</a>
<a id="hex2-7" class="hexContainer">
<polygon class="hex open" points="445.6921938165305,134.99999999999997 419.71143170299734,150 393.7306695894642,134.99999999999997 393.7306695894642,104.99999999999999 419.71143170299734,89.99999999999999 445.6921938165305,104.99999999999997"></polygon>
</a>
<a id="hex3-0" class="hexContainer">
<polygon class="hex open" points="55.98076211353316,179.99999999999997 30.000000000000004,194.99999999999997 4.01923788646684,179.99999999999997 4.019237886466843,149.99999999999997 29.999999999999993,134.99999999999997 55.98076211353315,149.99999999999994"></polygon>
</a>
<a id="hex3-3" class="hexContainer">
<polygon class="hex blocked" points="211.8653347947321,179.99999999999997 185.88457268119893,194.99999999999997 159.90381056766577,179.99999999999997 159.90381056766577,149.99999999999997 185.88457268119893,134.99999999999997 211.8653347947321,149.99999999999994" fill="url(#blockedHexPattern)"></polygon>
</a>
<a id="hex3-5" class="hexContainer">
<polygon class="hex blocked" points="315.7883832488647,179.99999999999997 289.80762113533154,194.99999999999997 263.8268590217984,179.99999999999997 263.8268590217984,149.99999999999997 289.80762113533154,134.99999999999997 315.7883832488647,149.99999999999994" fill="url(#blockedHexPattern)"></polygon>
</a>
<a id="hex3-7" class="hexContainer">
<polygon class="hex blocked" points="419.71143170299734,179.99999999999997 393.7306695894642,194.99999999999997 367.749907475931,179.99999999999997 367.749907475931,149.99999999999997 393.7306695894642,134.99999999999997 419.71143170299734,149.99999999999994" fill="url(#blockedHexPattern)"></polygon>
</a>
<a id="hex4-0" class="hexContainer">
<polygon class="hex open" points="81.96152422706632,224.99999999999997 55.98076211353316,239.99999999999997 30,224.99999999999997 30.000000000000004,194.99999999999997 55.98076211353315,179.99999999999997 81.96152422706632,194.99999999999994"></polygon>
</a>
<a id="hex4-1" class="hexContainer">
<polygon class="hex blocked" points="133.92304845413264,224.99999999999997 107.94228634059948,239.99999999999997 81.96152422706632,224.99999999999997 81.96152422706632,194.99999999999997 107.94228634059948,179.99999999999997 133.92304845413264,194.99999999999994" fill="url(#blockedHexPattern)"></polygon>
</a>
<a id="hex4-2" class="hexContainer">
<polygon class="hex blocked" points="185.88457268119896,224.99999999999997 159.9038105676658,239.99999999999997 133.92304845413264,224.99999999999997 133.92304845413264,194.99999999999997 159.9038105676658,179.99999999999997 185.88457268119896,194.99999999999994" fill="url(#blockedHexPattern)"></polygon>
</a>
<a id="hex4-3" class="hexContainer">
<polygon class="hex blocked" points="237.84609690826525,224.99999999999997 211.8653347947321,239.99999999999997 185.88457268119893,224.99999999999997 185.88457268119893,194.99999999999997 211.8653347947321,179.99999999999997 237.84609690826525,194.99999999999994" fill="url(#blockedHexPattern)"></polygon>
</a>
<a id="hex4-4" class="hexContainer">
<polygon class="hex open" points="289.80762113533154,224.99999999999997 263.8268590217984,239.99999999999997 237.84609690826522,224.99999999999997 237.84609690826522,194.99999999999997 263.8268590217984,179.99999999999997 289.80762113533154,194.99999999999994"></polygon>
</a>
<a id="hex4-5" class="hexContainer">
<polygon class="hex open" points="341.76914536239786,224.99999999999997 315.7883832488647,239.99999999999997 289.80762113533154,224.99999999999997 289.80762113533154,194.99999999999997 315.7883832488647,179.99999999999997 341.76914536239786,194.99999999999994"></polygon>
</a>
<a id="hex4-6" class="hexContainer">
<polygon class="hex open" points="393.7306695894642,224.99999999999997 367.749907475931,239.99999999999997 341.76914536239786,224.99999999999997 341.76914536239786,194.99999999999997 367.749907475931,179.99999999999997 393.7306695894642,194.99999999999994"></polygon>
</a>
</svg>
</div>
Leider gibt es keine (einfache) Möglichkeit, die untergeordneten Elemente zurückzusetzen. Wenn Sie eine Svg transformieren, transformieren Sie auch das gesamte Koordinatensystem. Möglicherweise können Sie eine Matrixmathematik machen, um die Transformation des Koordinatensystems für die roten Quadrate rückgängig zu machen, aber dann würden sie nicht mehr in einer Linie stehen. Es kann einige fortgeschrittene Matrix-Transformation geben, die Sie tun könnten, aber an einem bestimmten Punkt kann es einfacher sein, eine echte 3D-Engine wie three.js (http://threejs.org/) zu verwenden, die gebaut wird, um zu tun, was Sie wollen . –
@RobLouie Ich bin "irgendwie" es jetzt mit CSS-Transformationen auf den Kind-Elementen zu beheben, insbesondere skewX und übersetzen, aber es ist wirklich heikel, es erfordert verschiedene Transformationen für jeden Browser, und ich muss den Inhalt für jedes Hex anpassen individuell mit dem Auge. Idealerweise hätte ich gerne etwas robusteres, aber ich fürchte, Sie haben vielleicht Recht. – VirtuosiMedia