.circle { width: 40px; height: 40px; border-radius: 50%; background-color: yellow; position: absolute; z-index: 20; border: 1px solid #AAAAAA; Box-shadow: 0 0 8px 2px yellow; } .roof { width: 280px; height: 80px; background-color: gray; border-top-left-radius: 50%; border-top-right-radius: 50%; left: 0; z-index: -2; position: relative; } .windscreen { width: 260px; height: 75px; background: rgb(41,137,216); /* Old browsers */ background: -moz-linear-gradient(-45deg,rgba(41,216,1) 10%,rgba(170,170,1) 22%,1) 35%,1) 50%,1) 65%,1) 78%,1) 90%,1) 100%); /* FF3.6+ */ background: -webkit-gradient(linear,left top,right bottom,color-stop(10%,1)),color-stop(22%,color-stop(35%,color-stop(50%,color-stop(65%,color-stop(78%,color-stop(90%,color-stop(100%,1))); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(-45deg,1) 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(-45deg,1) 100%); /* Opera 11.10+ */ background: -ms-linear-gradient(-45deg,1) 100%); /* IE10+ */ background: linear-gradient(135deg,1) 100%); /* W3C */ filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#2989d8',endColorstr='#2989d8',GradientType=1); /* IE6-9 fallback on horizontal gradient */ margin-left: 10px; Box-shadow: inset 0 0 0 2px #000; /*not sure of this*/ } .roof-bonnet { height: 320px; margin-top: -100px; } #numberplate { height: 40px; width: 190px; background-color: white; bottom: 10px; position: relative; margin-top: -45px; margin-left: 44px; border: 2px solid black; font-size: auto; text-align: center; } .circle-headlight { margin-top: -55px; background-color: white; Box-shadow: 0 0 8px 2px white; } .right-headlight { margin-left: 238px; }
<div class="circle"></div> <div class="circle" style="margin-left:240px;"></div> <div class="roof"></div> <div class="windscreen"></div> <div class="roof roof-bonnet"></div> <div class="circle circle-headlight"></div> <div class="circle circle-headlight right-headlight"></div> <div id="numberplate">REG PLATE</div>
我一直试图在CSS中生成一辆卡车,但是在生成侧镜时有一些困难,我认为主要是因为我的设计/使用不好。
我想添加一些东西:
+-------+ | | \ | | | | /| | | //| | | // | | | // /| | | // //| | | // // |_________/ --- +// -----+ | |
到任何一边
有没有人有任何建议,添加这个没有“打破”现在的笔?
到目前为止,我已经尝试生成这种形状,使用:
#wing-mirror { margin-top:40px; width: 100px; height: 50px; background: red; position: relative; transform: rotate(-90deg); border-radius:20px; } #wing-mirror:after { content: ""; position: absolute; bottom: 0; left: 0; border-top: 10px solid red; border-left: 29px solid #fff; border-right: 29px solid #fff; width: 42px; height: 0; }
经过多次尝试,并撰写这个问题后,
我已经创造了这个“镜子”,但是由于我使用了具体的价值观,将这个“下一个”放在我的货车上,所以这个对齐方式就没有了,所以没有一个“发动机罩/挡风玻璃/在我的html镜像。
我完成的机翼看起来像这样:
#wing-mirror { margin-top: 40px; width: 100px; height: 50px; background: gray; position: relative; transform: rotate(-90deg); border-radius: 20px; } #wing-mirror:after { content: ""; position: absolute; bottom: 0; left: 0; border-top: 10px solid gray; border-left: 29px solid #fff; border-right: 29px solid #fff; width: 42px; height: 0; } .border-div { width: 75px; background-color: gray; height: 10px; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); transform: rotate(45deg); margin-left: 30px; } .border-div-top { width: 50px; background-color: gray; height: 10px; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); transform: rotate(45deg); margin-left: 50px; margin-top: -20px; }
<div id="wing-mirror"></div> <div class="border-div"></div> <div class="border-div-top"></div>
但是我怎么能把这个附加在我的整车里?正如我所尝试的一切都会导致“跳跃”的元素(他们不会’卡在卡车上),并且它们不正确地对准元素的一侧(不要出现在货车左侧或右侧,可能是由于执行不良)。
解决方法
Disclaimer: I don’t believe this approach is the best to create the shape you are after. Depending on your use case,you should look into 07000 or a normal png/jpeg.
我为每个镜像添加了一个元素,并在镜像臂的.windscreen div上使用带有边框的偏斜伪元素。
为了定位镜子,我添加了位置:相对;到.windscreen div并插入镜像作为该div的孩子。这样,您可以使用绝对定位将镜子左右相对于挡风玻璃。
body{ padding-left:100px; } .circle { width: 40px; height: 40px; border-radius: 50%; background-color: yellow; position: absolute; z-index: 20; border: 1px solid #AAAAAA; Box-shadow: 0 0 8px 2px yellow; } .roof { width: 280px; height: 80px; background-color: gray; border-top-left-radius: 50%; border-top-right-radius: 50%; left: 0; z-index: -2; position: relative; } .windscreen { position:relative; width: 260px; height: 75px; background: rgb(41,GradientType=1); /* IE6-9 fallback on horizontal gradient */ margin-left: 10px; Box-shadow: inset 0 0 0 2px #000; /*not sure of this*/ } .roof-bonnet { height: 320px; margin-top: -100px; } #numberplate { height: 40px; width: 190px; background-color: white; bottom: 10px; position: relative; margin-top: -45px; margin-left: 44px; border: 2px solid black; font-size: auto; text-align: center; } .circle-headlight { margin-top: -55px; background-color: white; Box-shadow: 0 0 8px 2px white; } .right-headlight { margin-left: 238px; } .windscreen:after{ content:''; position:absolute; left:100%; bottom:15px; width:10px; height:20px; transform:skewX(-30deg); border-bottom:12px solid #000; border-right: 12px solid #000; z-index:-1; } .windscreen:before{ content:''; position:absolute; right:100%; bottom:15px; width:10px; height:20px; transform:skewX(30deg); border-bottom:12px solid #000; border-left: 12px solid #000; z-index:-1; } .mirror{ position:absolute; left:100%; top:20px; margin-left:19px; height: 30px; width:20px; background:#000; } .mirror:before,.mirror:after{ content:''; position:absolute; width:100%; Box-sizing:border-Box; bottom:100%; border-color: #000 transparent; border-width: 0 5px 10px 0; border-style:solid; } .mirror:after{ bottom:auto; top:100%; border-width: 7px 3px 0 0; } .mirrorL{ position:absolute; right:100%; top:20px; margin-right:19px; height: 30px; width:20px; background:#000; } .mirrorL:before,.mirrorL:after{ content:''; position:absolute; width:100%; Box-sizing:border-Box; bottom:100%; border-color: #000 transparent; border-width: 0 0 10px 5px; border-style:solid; } .mirrorL:after{ bottom:auto; top:100%; border-width: 7px 0 0 3px; }
<div class="circle"></div> <div class="circle" style="margin-left:240px;"></div> <div class="roof"></div> <div class="windscreen"><div class="mirror"></div><div class="mirrorL"></div></div> <div class="roof roof-bonnet"></div> <div class="circle circle-headlight"></div> <div class="circle circle-headlight right-headlight"></div> <div id="numberplate">REG PLATE</div>