Why can't a <button> element contain a
?

前端 未结 4 765
夕颜
夕颜 2020-12-02 01:46

My company is building a website and we had some problems with a JavaScript library not replacing something. We decided to throw our HTML in to the W3C validator and it info

4条回答
  •  执念已碎
    2020-12-02 02:20

    Well I posted a comment but no love.

    You can achieve a W3C valid button by simply putting an image inside the button.

    Fiddle

    Granted you'll have to create your images and add the text to them. But since you've already created images for the corners that shouldn't be too hard.

    Also image sprites are a great thing.

    .test {
      width: 258px;
      height: 48px;
      background: none;
      border: 1px solid transparent;
    }
    .test:active {
      outline: 0;
    }
    .test > img {
      width: 258px;
      height: 45px;
      opacity: 1;
      background: url('http://www.copygirlonline.com/wp-content/plugins/maxblogpress-subscribers-magnet/lib/include/popup1/images/btn/blue-button.png');
      background-position: -3px 0px;
    }
    .test > img:hover {
      background-position: -3px -50px;
    }

    If you want to stick with 3 images here's an updated version.

    button {
      margin: 0;
      padding: 0;
      border: none;
    }

    Also, without additional CSS, it seems you need to keep all of the tags on the same line or it treats the images as having space between them.

提交回复
热议问题