我有2個圖像與透明的背景和需要把一個在彼此的頂部相同的定位:CSS - :: after僞元素的定位和尺寸問題
- 1紡(下)
- 1 fixed(above)
我需要將整個圖像合成爲中心並根據窗口大小調整其大小。
我使用了一個::after
僞元素爲固定的,但無法獲得其位置和大小跟隨旋轉的一個。
我想background-size
屬性應該參與,但沒有設法正確使用它。
希望得到任何建議,即使涉及的方法與僞類的完全不同。
非常感謝。
body{
\t \t \t width: 100%;
\t \t \t height: 100%;
\t \t \t background-color: #000;
\t \t \t text-align: center;
\t \t \t color: #fff;
\t \t }
\t \t .main-container{
\t \t \t background-color: #00f;
\t \t \t width: 50%;
\t \t \t margin: 0 auto;
\t \t }
\t \t .engine-container{
\t \t }
\t \t .engine-complete{
\t \t \t position: relative;
\t \t \t width: 100%;
\t \t \t height: auto;
\t \t \t margin: 0 auto; \t
\t \t }
\t \t .engine-complete::after{
\t \t \t content: "";
\t \t \t position: absolute;
\t \t \t width: 191px;
\t \t \t height: 192px;
\t \t \t top: 1px;
\t \t \t left: 0;
\t \t \t background-image: url(https://image.ibb.co/jOqNma/engine1_crpd.png);
\t \t }
\t \t .engine-rotating{
\t \t \t width: 50%;
\t \t \t height: auto; \t \t \t
\t \t }
\t \t .spin {
\t \t animation-duration: 15s;
\t \t animation-name: spin;
\t \t animation-iteration-count: infinite;
\t \t animation-timing-function:linear;
\t \t animation-play-state: running;
\t \t }
\t \t @keyframes spin {
\t \t from {
\t \t transform:rotate(360deg);
\t \t }
\t \t to {
\t \t transform:rotate(0deg);
\t \t }
\t \t }
<div class="main-container">
\t \t <h1>spinning engine</h1>
\t \t <div class="engine-container">
\t \t \t <div class="engine-complete">
\t \t \t \t <img src="https://image.ibb.co/nwOKXF/engine1.png" width=191 height=192 class="engine-rotating spin"/>
\t \t \t </div>
\t \t </div>
\t </div>
感謝萬@Jcode,這解決了我的問題,確實是一個很好的解決方案!仍然想知道是否可以用':: after'僞類實現,你認爲是嗎? – Surreal
@Surreal我在上面添加了一個備用解決方案! – Jcode
謝謝,但替代解決方案看起來它錯過了圖像大小根據窗口大小進行調整。嘗試使用':: after'僞類時遇到同樣的問題 – Surreal