开发者

Need a simple way to set width and height of an empty block element

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
     <style type="text/css" media="all">
         .prod
        {
         display: inline-block;
         border: 1px solid grey;
         width: 158;
         height: 124;
         cursor: pointer;
        }
      </style>
      <script type="text/javascript">
         function swap(x,y,z)
         {
          var node = document.getElementById(x);
          node.src = node.src.indexOf(y)>=0 ? z : y;
          node.style.border = node.src.indexOf(y)>=0 ? '' : '1px solid grey';
          node.style.position = node.src.indexOf(y)>=0 ? 'static':'fixed';
          node.style.top = node.src.indexOf(y)>=0 ? '' : '20%';
          node.style.left = node.src.indexOf(y)>=0 ? '' : '20%';
         }
      </script>开发者_如何学Python;
  </head>
  <body>
      <span class="prod">   
          <img id="im0001" src="thumbnail.gif" onclick="swap ('im0001','thumbnail.gif','fullsize.gif');" /> 
      </span>
      <br />
      <br />
  </body>
  </html>


Missing CSS dimension units

You have to set dimension unit in your CSS for it to work. Your CSS only defines width as

width: 158;

that should be:

width: 158px;

That would do the trick for you.

JSFiddle demo.


Like mentioned in one of the comments, your height and width are incorrect. You need to change width: 158 to: width: 158px

Same goes with height

See: http://jsfiddle.net/jwKpN/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜