【问题标题】:How to keep text in an x,y coordinate in html?如何将文本保存在 html 中的 x,y 坐标中?
【发布时间】:2021-08-29 07:47:19
【问题描述】:

我试图通过 HTML 在我的网站页面上的 x,y 坐标窗口中放置文本,我该怎么做?这是我到目前为止的代码:

<!DOCTYPE html>
     <html>
           <head>
                  <center><h1>Hello</h1></center>
           </head>
     </html>

目前,代码将在窗口中心显示“Hello”,但我希望它位于 (100,100)。

【问题讨论】:

    标签: html text position coordinates


    【解决方案1】:

    使用position:fixedtop:100pxleft:100px

    <!DOCTYPE html>
    <html>
    
    <head>
      <style>
        h1 {
          position: fixed;
          top: 100px;
          left: 100px;
        }
      </style>
    </head>
      <body>
        <h1>Hello</h1>
      </body>
    
    </html>

    【讨论】:

    • 我尝试运行程序,但我是否将第一个代码 sn-p 保存在单独的文件中?这是我当前的代码:&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; h1{position:fixed;top:100px;left:100px;} &lt;h1&gt;Hello&lt;/h1&gt; &lt;/head&gt; &lt;body&gt; &lt;/html&gt;
    • 当我运行 StackOverflow“运行代码 sn-p”按钮时它可以工作,但当我在本地磁盘上执行它时它不起作用。
    • @ViperStream 我已经编辑了我的答案。您现在可以将其复制并粘贴到本地磁盘。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多