0

I do have a div like this:

<div class="frontend-shop-cart-left">
   <a href="#">
      <img src="#" style=" display:inline; vertical-align: middle;height:60px; width:60px; " />
   </a>
   <a href="#">
      <span style="margin-left: 15px; font-size: 14px;" >1</span>
   </a>
</div>

The text ist vertical align to middle and it looks good. But if I am going to add two spans in the second href the rendering is bad.

It looks like this:

|-------|
| image | 1
|       |
|-------| 
 2 3

But I want this.

|-------|
| image | 1
|       | 2 3
|-------| 

My html code is like this:

<div class="frontend-shop-cart-left">
   <a href="#">
      <img src="#" style=" display:inline; vertical-align: middle;height:60px; width:60px; " />
   </a>
   <a href="#">
      <span style="margin-left: 15px; font-size: 14px;" >1</span> <br/>
      <span style="margin-left: 15px; font-size: 14px;" >2</span>
      <span style="font-size: 14px;" >3</span>
   </a>
</div>

What is wrong with my CSS?

craphunter
  • 961
  • 2
  • 13
  • 34

4 Answers4

1

Let the img element control the left flow using float: left

<img src="#" style="float: left; ....

DEMO

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
1

Display the anchors as inline-block elements and align them vertically by vertical-align: middle; as follows:

EXAMPLE HERE

a {
  display: inline-block;
  vertical-align: middle;
}

Also specifying vertical-align for the image removes the vertical gap under that (belonging to the inline elements which are positioned in their baseline), hence you could keep using it.

img {
  vertical-align: middle;
}
Community
  • 1
  • 1
Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
1

This is because the anchor tag is not a block element. You can either add display:inline-block to your anchor tags, or float the first or both anchor tags to the left.

Fiddle here: http://jsfiddle.net/qfx5xt0b/1/

o--oOoOoO--o
  • 770
  • 4
  • 7
1

Simply put the two <a>s in separate <div>s and style these inner <div>s display: inline-block;

Alternatively, you could display: inline-block the two <a>s too.

Here's the Fiddle: http://jsfiddle.net/o8xnfujm/

Karma
  • 2,196
  • 1
  • 22
  • 30