-2

I'm trying to change a word in a hyperlink text.

Let's say the hyperlink is "foofoofoo". How to change the middle foo to italics?

I've tried this:

<a href="#">
foo<div style="font-style: italic;">foo<div>foo
</a>

However, my IDE states underlines the div as error and the whole hyperlink style gets messed up. Am I doing it wrong?

Thank you for the help!

Kotoriii
  • 9
  • 1
  • 6

2 Answers2

0

You shouldn't be using a block element for this. You really should use an inline element like span.

<a href="#">
foo<span style="font-style: italic;">foo</span>foo
</a>

Here is a great write-up on the differences: What is the difference between display: inline and display: inline-block?

Community
  • 1
  • 1
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
0

Wrap the middle foo in the italic tag instead of a division.

foo<i>foo</i>foo
deflator
  • 169
  • 1
  • 8