我正在本地工作一個WordPress網站,我正在嘗試動態調用自定義頁眉。我使用下面的代碼:W3C驗證錯誤:百分位高度和寬度屬性
<img src="<?php header_image(); ?>" height="20%<?php echo get_custom_header()->height; ?>" width="20%<?php echo get_custom_header()->width; ?>" alt="header-image" />
上面的代碼,將輸出以下行到瀏覽器:
<img src="http://localhost/wordpress-folder/wp-content/uploads/2017/10/image.jpg" height="20%3484" width="20%2439" alt="header-image" />
雖然上面的代碼調用成功的自定義頁眉,它並不能W3C驗證。該錯誤消息是如下:
Bad value 20%3484 for attribute height on element img: Expected a digit but saw % instead.
我似乎可以消除這種誤差的唯一方法,是通過去除%(PX也產生錯誤),並且僅在數離開。
有沒有一種方法可以繼續使用像素/百分比,而不是重新組織我的代碼,以便我可以實現一些內聯/外部樣式表?
高度和寬度屬性被假定爲像素。刪除除數字以外的任何內容或使用style屬性。 'style =「width:100px; height100;」' – bassxzero
https://www.w3schools.com/tags/tag_img.asp – bassxzero
@bassxzero謝謝。我最初嘗試了這種方法,並在工作的同時,將圖像放大以覆蓋整個屏幕;即使當px設置爲1.我注意到如果我刪除了'<?php echo get_custom_header() - > height;那麼問題就解決了。謝謝。另外,感謝您分享鏈接。 – Craig