Search code examples
htmlruby-on-railscontent-tag

make Content_tag to print two elements in same line(Rails)


content_tag(:p, "link : ") + content_tag(:p, link_to("abc","www.abc.com"))

This prints

link:
abc

But I want it to print

link: abc

Solution

  • <p>(Paragraph) is a block element and it's HTML mechanics (so it always takes the whole width of it's container). It doesn't have any relation to ruby/rails code and you can't achieve it making any changes in ruby code. You can achieve with some hacky CSS solutions. But good solution is to go with inline <span> tags. It will do what you want. And you can use single <p> as root element for 2 <span>