Whitespace after image is being displayed as link

Wolfgang Roth

Given the following HTML:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
</head>
  <body>
    <div style="background-color:red">
      <a href="1__mose_info.htm">
        <img src="../img/info.png" alt="Info zum ersten Buch Mose" title="Info zum ersten Buch Mose" /></a><a href="1__mose.htm">1. Mose</a>
    </div>
    <div style="background-color:green">
      <a href="1__mose_info.htm">
        <img src="../img/info.png" alt="Info zum ersten Buch Mose" title="Info zum ersten Buch Mose" />
      </a>
      <a href="1__mose.htm">
        1. Mose
      </a>
    </div>
  </body>
</html>

The first division gets displayed as I want it (no link underline before the '1'. but if i format my code like in the second div, the space before the 1 gets an underline for a link.

If you look closely, the link of the space before '1' is the link of the image, and not the link of the text. Is there an easier way to not have this space as part of the link?

[Edit after my two upvotes and selecting the prefered answer:]

So it is best practice to keep all html elements and/or text that counts into an anchor element at one line - at least the first word. I will try to keep this in mind when editing subsequent html source code

Thank you all. Wolfgang

webbm

A line break counts as a space in HTML. You would need to change it to this to keep the same format:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
</head>
<body>
    <div style="background-color:red">
        <a href="1__mose_info.htm"><img src="../img/info.png" alt="Info zum ersten Buch Mose" title="Info zum ersten Buch Mose" /></a><a href="1__mose.htm">1. Mose</a>
    </div>
    <div style="background-color:green">
        <a href="1__mose_info.htm">
            <img src="../img/info.png" alt="Info zum ersten Buch Mose" title="Info zum ersten Buch Mose" /></a><a href="1__mose.htm">1. Mose</a>
    </div>
</body>
</html>

Take a look here for more on what you can do to overcome this if you are keen on the html formatting not affecting the display of your page: Removing whitespace between HTML elements when using line breaks

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Red block being displayed behind my image link

From Dev

Background Image is not being Displayed

From Dev

Wrong Image is being displayed

From Dev

background-image not being displayed

From Dev

Link to image within pdf, and have the image displayed?

From Dev

Why is this image inside svg not being displayed?

From Dev

Downloaded image not being displayed iOS Swift

From Dev

Image width in canvas isnt being displayed correctly

From Dev

Image not being displayed using webcam in opencv

From Dev

Redactor: image upload not being displayed in text editor

From Dev

Downloaded image not being displayed iOS Swift

From Dev

why is this image not being displayed in asp.net?

From Dev

nothing is being displayed after opening the app

From Dev

UITableView not being displayed after reloading data

From Dev

nothing is being displayed after opening the app

From Dev

Jquery - match link color to image displayed

From Dev

Jquery - match link color to image displayed

From Dev

to determine which image is being currently displayed on vertical image viewer

From Dev

How to avoid whitespace after a tag (link) in Hamlet templates?

From Dev

Why is my image not being displayed correct when loading it using readfile

From Dev

background-image not being displayed in div inside DataList ItemTemplate?

From Dev

Image not being displayed in J2ME Midlet

From Dev

Map not being displayed after refactoring to change the name of the project and package

From Dev

Rails: image change position after being updated

From Dev

Get the image sizes after being uploaded with ajax

From Dev

Rails: image change position after being updated

From Dev

Image not being deleted after actual deletion in xampp

From Dev

Trim whitespace in link with css

From Dev

Broken image being displayed when using the image path returned from cordovacapture captureimage

Related Related

  1. 1

    Red block being displayed behind my image link

  2. 2

    Background Image is not being Displayed

  3. 3

    Wrong Image is being displayed

  4. 4

    background-image not being displayed

  5. 5

    Link to image within pdf, and have the image displayed?

  6. 6

    Why is this image inside svg not being displayed?

  7. 7

    Downloaded image not being displayed iOS Swift

  8. 8

    Image width in canvas isnt being displayed correctly

  9. 9

    Image not being displayed using webcam in opencv

  10. 10

    Redactor: image upload not being displayed in text editor

  11. 11

    Downloaded image not being displayed iOS Swift

  12. 12

    why is this image not being displayed in asp.net?

  13. 13

    nothing is being displayed after opening the app

  14. 14

    UITableView not being displayed after reloading data

  15. 15

    nothing is being displayed after opening the app

  16. 16

    Jquery - match link color to image displayed

  17. 17

    Jquery - match link color to image displayed

  18. 18

    to determine which image is being currently displayed on vertical image viewer

  19. 19

    How to avoid whitespace after a tag (link) in Hamlet templates?

  20. 20

    Why is my image not being displayed correct when loading it using readfile

  21. 21

    background-image not being displayed in div inside DataList ItemTemplate?

  22. 22

    Image not being displayed in J2ME Midlet

  23. 23

    Map not being displayed after refactoring to change the name of the project and package

  24. 24

    Rails: image change position after being updated

  25. 25

    Get the image sizes after being uploaded with ajax

  26. 26

    Rails: image change position after being updated

  27. 27

    Image not being deleted after actual deletion in xampp

  28. 28

    Trim whitespace in link with css

  29. 29

    Broken image being displayed when using the image path returned from cordovacapture captureimage

HotTag

Archive