【问题标题】:Build responsive button with image, text and a link using css使用 css 构建带有图像、文本和链接的响应式按钮
【发布时间】:2017-01-20 14:46:36
【问题描述】:

我尝试了几件事,但我不走运。我需要在按钮背景图像上构建一个包含图像和文本的按钮。此外,单击按钮内的任意位置应重定向到页面,例如 google.com。这就是按钮的样子

我面临的挑战是,当按钮文本发生变化或屏幕大小发生变化时,图像和文本的对齐会变得混乱。如果按钮文本太大,我想换行。如何包装按钮文本并仍然正确对齐所有内容?此外,我希望按钮的宽度与我必须构建多个大小相同且文本和图像不同的按钮相同。太感谢了。一个更快的解决方案将不胜感激,因为我急于看到我做错了什么。这是我到目前为止的代码:JSFiddle

<a href="https://www.google.com" style="color: white !important; background-color: #7FFF00;padding: 25px;width: 50px;"> 
    <span style="margin-bottom: 5%;"> 
        <img src="http://placehold.it/30x30" height:100%; style="display: inline-block;" width="30" height="30" /> 
        <span style="display: inline-block;"> 
            <b><font size ="2" color="BLACK" face="Arial">CLICK ON THE IMAGE TO VIEW MORE DETAILS ABOUT THE ITEM </font> </b> 
        </span> 
    </span> 
</a> 

【问题讨论】:

    标签: html css button


    【解决方案1】:

    img{
      width:30px;
      height:30px;
    }
    a{
    text-decoration:none;
    color:black;}
    #img{
      float:left;
    }
    #img,#text{
     display:inline;
    }
    
    #main{
      margin-top:20px;
      width:250px;
      border:2px solid black;
      border-radius:10px;
      background:yellowgreen;
    }
    #container{
      margin:15px;
      }
    div.clickable {
        position:relative;
    }
    div.clickable #mainlink {
        position:absolute;
        width:100%;
        height:100%;
    }
    <div class="clickable">
    <a href="www.google.com" id="mainlink">
    <div id="main">
    <div id="container">
    <div id="img">
    <a href="www.google.com"><img src="http://oer.nios.ac.in/wiki/images/thumb/4/47/Thumpsup.png/200px-Thumpsup.png"/></a>
    </div>
    <div id="text">
    <span>Click on the image to view more about the item</span>
    </div>
    </div>
    </div>
      </a>
      </div>

    【讨论】:

    • 非常感谢......对不起,我应该提到单击按钮上的任何位置应该重定向到网页,而不仅仅是单击图像。
    • 非常感谢。当文本变大时,它会包裹在图像下方。有没有办法不将文本包装在图像下方?再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    • 2014-05-09
    • 1970-01-01
    相关资源
    最近更新 更多