How to put an image in front of a button?

4

I'm trying to unsuccessfully put an image (Facebook icon) in front of a newsletter form:

Itriedtosize,butIwasnotsuccessfulbecauseofmylackofknowledgeinCSS,Itriedtodecreasethefieldofformandeventhepositionofthebutton.

Thisisthehtmlofform:

<divid="newsletter-wrap">
    <form action="newsletter.php"  method="post" class="content-form clearfix" id="newsletter-form">
        <input type="submit" class="button" name="button" id="button" value="Enviar" />
        <input id="newsletter" type="email" name="newsletter" placeholder="Fique por dentro de nossas ofertas">
     </form>
     <img src="imagens/icone-facebook.png" width="29" height="29">
     <p class="status"></p>             
     <br>
</div>

I have this CSS of form :

#newsletter-wrap {
    padding-top: 1px;
    /*border-top: 1px solid #e5e5e5;*/
}

#newsletter-form input#newsletter {
    float: left;
    width: 360px;
    margin-right: 10px;
}

#newsletter-form input.button {
    float: right;
    margin-right: 0;
    margin-bottom: 5px;
}

#newsletter-wrap .tip {
    margin-top: 7px;
}

The newsletter form is within div :

<div class="one-half column-last">O formulário está aqui</div>

.one-half {
   width: 80%;
   max-width: 460px;
}

.column-last { 
   margin-right: 0 !important;
}
    
asked by anonymous 06.02.2015 / 21:27

2 answers

3

Edit the structure. If the button comes after from input there is no reason to put it before in HTML.

<form action="newsletter.php" method="post" class="content-form clearfix" id="newsletter-form">
  <input id="newsletter" type="email" name="newsletter" placeholder="Fique por dentro de nossas ofertas">
  <input type="submit" class="button" name="button" id="button" value="Enviar">
  <img src="imagens/icone-facebook.png" width="29" height="29">
</form>

To adjust your layuot and make room for img to be right:

.one-half {
  width: 80%;
  max-width: 500px;
}

The input and the button are aligned with float: left and img with float: right .

#newsletter-form input#newsletter {
   float: left;
   width: 360px;
   margin-right: 10px;
   display: inline;
}

#newsletter-form input.button {
  float: left;
  margin-right: 0;
  margin-bottom: 5px;
  display: inline;
}

#newsletter-wrap img {
  float: right;
  display: inline;
}

Result:

If you want to bring the facebook icon closer to the Send button, just add margin-right to img and adjust until you get to where you want.

    
07.02.2015 / 02:13
3

Image is out of form and as form is block so image has to be within tag form , try to set tag img within form and add your css:

#newsletter-wrap img{
    display:block;
    float:right;
}
    
06.02.2015 / 21:59