代码之家  ›  专栏  ›  技术社区  ›  Maxxx

在HTML中创建中心虚线

  •  2
  • Maxxx  · 技术社区  · 7 年前

    我正在做一个乒乓球游戏,目前,为了一个设计,我试图在画布的中心创建一条垂直的虚线,但我不知道如何在HTML中这样做。 enter image description here

    我目前拥有的HTML代码是

    <html>
    <head>
        <style>
            @import url(style.css);
            p.highlight {
                color: red;
            }
            svg {
                background-color: rgb(41, 41, 36);
            }
        </style>
        <script src="svgelement.js"></script>
        <script src="observable.js"></script>
        <script src="pong.js"></script>
    </head>
    <body>
        <h1>Pong</h1>
        <svg id="canvas" width="600" height="600"/>
    
    </body>
    

    希望能得到一些帮助。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Jithin Raj P R    7 年前


    我不知道你是否会喜欢这个,但我建议,改变SVG标签,并使之简单,使用盒子模型或盒子形状与简单的CSS。它看起来有点像这样:

    .box {
      height: 500px;
      width: 800px;
      background-color: black;
      position: absolute;
      left: 280px;
      bottom: 50px;
    }
    
    .pong1 {
      height: 80px;
      width: 20px;
      background-color: grey;
      z-index: 1;
      position: absolute;
      left: 300px;
      bottom: 300px;
    }
    
    .pong2 {
      height: 80px;
      width: 20px;
      background-color: grey;
      z-index: 1;
      position: absolute;
      right: 300px;
      bottom: 300px;
    }
    
    .border:before {
      content: "";
      position: absolute;
      left: 425px;
      bottom: 294px;
      height: 10px;
      width: 36.7%;
      border-bottom: 3px dotted white;
      transform: rotate(270deg);
    }
    <div class="box"></div>
    <div class="pong1"></div>
    <div class="pong2"></div>
    <div class="border"></div>

    我知道它看起来很笨拙,不完美,但它很有效,很简单, 谢谢您。