简体   繁体   English

文本未显示在边框 html/css 上

[英]text not showing over border html/css

I'm trying to make a simple button.我正在尝试制作一个简单的按钮。 But instead of <button> , I'm using <div> and <p> , but the result will show up as only border, and the text won't show up over the border.但不是<button> ,我使用的是<div><p> ,但结果只会显示为边框,文本不会显示在边框上。

Am I doing something wrong?难道我做错了什么?

Screenshot of the button:按钮截图​​:

按钮截图

 .Something4 { margin-top: -72px; margin-left: 335px; font-size: 20px; width: 110px; height: 60px; border: 1px solid #E12976; border-radius: 20px; } .Something4 p2 { margin-left: 335px; width: 100px; height: 50px; }
 <div onclick="location.href='Login.php';" style="cursor: pointer;" class="Something4"> <p2 style="font-family: Sans-serif;font-size:16px;font-style:normal;">Login</p2> </div>

I copied your code into codepen.com.我将您的代码复制到 codepen.com。 margin-top: -72px; is moving your button off the screen.正在将您的按钮移出屏幕。 The second margin-left: 335px;第二个margin-left: 335px; in the p2 section is moving the text out of your button.在 p2 部分将文本移出按钮。 Try removing all your margins and see how it looks:尝试删除所有边距并查看它的外观:

.Something4 {
  font-size: 20px;
  width: 110px;
  height: 60px;
  border: 1px solid #E12976;
  border-radius: 20px;
}
.Something4 p2 {
    width: 100px;
    height: 50px;
}

Keep in mind the margin inside the p2 tag will not replace the margin on the border itself, and having negative margins might not always do what you think.请记住,p2 标签内的边距不会替换边框本身的边距,并且负边距可能并不总是如您所想。

I would highly recommend using semantic markup to describe the content of your page.我强烈建议使用语义标记来描述页面的内容。 This helps make your content accessible and work as expected across a variety of devices and use cases that you might not be capturing.这有助于使您的内容可访问并在您可能未捕获的各种设备和用例中按预期工作。

So use an anchor tag <a> to link to \\login.php , and then you can choose to style that similar to a button if you'd like.因此,使用锚标记<a>链接到\\login.php ,然后您可以根据需要选择类似于按钮的样式。

 body { padding: 15px; background: #211f1f; } a.login-button { color: salmon; border: 1px solid salmon; padding: 10px 15px; border-radius: 20px; text-decoration: none; }
 <a href="login.php" class="login-button">Login</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM