简体   繁体   English

我的简单按钮有什么问题?

[英]What's wrong with my simple button?

I'm essentially trying to create a div which is an image of a button, and when the user clicks it a function is executed.我实际上是在尝试创建一个 div,它是按钮的图像,当用户单击它时,会执行 function。 For some reason the div is not showing up at all?由于某种原因,div根本没有出现? What in the world am I setting wrong?我到底设置错了什么?

CSS: CSS:

#customizeButton
{
  background-image:url('images/customizeButton.png');
  position:absolute;
  top:35%;
  left:25%;
  width:370px;
  height:350px;
  background-repeat:no-repeat;
  -webkit-background-size:100% auto;
  z-index: 150;
}

HTML: HTML:

<div id ="customizeButton"></div>

It has to be something with the CSS side.它必须与 CSS 端有关。 I've got almost identical code for another "button" which I use as an exit button, but it uses a text character instead of an image.对于我用作退出按钮的另一个“按钮”,我有几乎相同的代码,但它使用文本字符而不是图像。 It works just fine...它工作得很好......

Here's the code for reference:这是供参考的代码:

CSS: CSS:

#statSheetExitButton
{
  width: 40px;
  height: 40px;
  position: absolute;
  font-weight: bold;
  top: 17%;
  left: 74%;
  font-size: 150%;
  font-style: normal;
  color: black;
  z-index: 50;
}

HTML: HTML:

<div id ="statSheetExitButton">X</div>

And again, the question is why the customizeButton is not showing up.再一次,问题是为什么customizeButton没有出现。

EDIT: ANSWER The problem was that I had the html code for my initial Stat Sheet components in another html file in the same folder, and my program was only listening to that file.编辑:回答问题是我在同一个文件夹中的另一个 html 文件中有我的初始统计表组件的 html 代码,而我的程序只收听该文件。

You are absolute positioning your element.您正在绝对定位您的元素。 Could you be positioning it on top of a relative positioned element that is causing it to be placed outside of the viewport of the browser screen.您能否将其定位在相对定位元素的顶部,从而导致它被放置在浏览器屏幕的视口之外。 Use the inspector tools in Chrome, Firefox or Safari to find out where the div is .使用 Chrome 中的检查器工具 Firefox 或 Safari 找出 div 的位置 That'll get you on the right track.这会让你走上正轨。

Is this the correct path to your image?这是您的图像的正确路径吗?

background-image:url('customizeButton.png');

This would only work if the img was in the same directory as the css.这仅在img与 css 位于同一目录中时才有效。

I think your div is empty so that,s why div is not showing, try to write some text or some thing else in div我认为你的 div 是空的,所以为什么 div 没有显示,尝试在 div 中写一些文本或其他东西

My thoughts:我的想法:

  • display: block;显示:块; missing失踪
  • you don't need background-repeat(nor -webkit-background-size), because you are giving it a height & width你不需要背景重复(也不需要-webkit-background-size),因为你给它一个高度和宽度
  • if you are only positioning this container, you do not need z-index如果你只是定位这个容器,你不需要 z-index

Make sure your button is inside a positioned element, which isn't itself hidden.确保您的按钮位于定位元素内,该元素本身并未隐藏。

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

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