简体   繁体   English

在html input type = button顶部添加图标图像

[英]Add an icon image on top of an html input type=button

I need to add an .PNG image on top of my css button, the image will be a hamburger menu icon to show that the button is expandable. 我需要在css按钮上方添加.PNG图像,该图像将是一个汉堡菜单图标,以显示该按钮是可扩展的。

These are my buttons. 这些是我的按钮。

这些是我的按钮

The buttons are created with this HTML: 按钮是使用以下HTML创建的:

                    While($row1=mysql_fetch_array($retServerNames)){

                        $serverID = $row1['id'];
                        $serverName = $row1['servername'];



                        echo"<input type='button' id='$buttonId' class='btn' name='show' value='".$serverName."' onclick='javascript:showServer(".$buttonId.");'
                            style='width: 90%; margin: 1%; text-align:left;'>";

                        echo"<div id='$serverName' style='margin: 3%; display:none;'>";

                        echo"<table style='border-bottom: 1px solid black;' cellspacing='10px'>

                                            <thead>
                                                <tr>
                                                    <th></th>
                                                    <th>Task</th>
                                                    <th>Status</th>
                                                    <th>Agent</th>
                                                    <th>Date Completed</th>
                                                    <th></th>
                                                </tr>
                                            </thead>";      

I have tried putting both the image tag and the input type inside a div element and tired to position the image over the button with no success, is there a better way to do this? 我尝试将图像标签和输入类型都放在div元素中,并且累了将图像放置在按钮上没有成功,是否有更好的方法呢? or can any one suggest an alternative element that will allow me to do this more easily than the button element? 还是有人建议一种替代性的元素,使我比按钮元素更容易做到这一点? thank you in advance. 先感谢您。

The easy way is to use an actual button element. 最简单的方法是使用实​​际的按钮元素。

<button type="button"
        id="<?php echo htmlspecialchars($buttonId); ?>"
        onclick="showServer(this.id);">
    <img src="hambuger.png" alt="">
    <?php echo htmlspecialchars($serverName); ?>
</button>

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

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