开发者

Centering an image with an input?

开发者 https://www.devze.com 2023-01-13 02:54 出处:网络
I have an image next to an input, and I was wondering how I centered both with one another. I need the center of the image to be vertically aligned with the center of the input. How do I make this hap

I have an image next to an input, and I was wondering how I centered both with one another. I need the center of the image to be vertically aligned with the center of the input. How do I make this happen?

Markup:

<span class="my-span">
  <input 开发者_StackOverflowtype="text" .../><a href="..."><img .../></a>
</span>


Setting the vertical-align to middle on the <img> should put you in business:

<span class="my-span">
    <input type="text" .../><a href="..."><img ... style="vertical-align: middle"/></a>
</span>

You can see it in action here.


Your image should have the ff styles to work:

img { vertical-align: middle; display: table-cell; }

and to your input element, add

input { float: left; }


Setting vertical-align on both input and img elements works for me:

<span class="my-span">
   <input type="text" style="vertical-align: middle" /><a href="..." ><img style="vertical-align: middle" ... /></a>
</span>

Check it here

0

精彩评论

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