Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5982367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:04:37+00:00 2026-05-22T22:04:37+00:00

To create n span s next to each other I do: <% n.times do

  • 0

To create n spans next to each other I do:

<% n.times do |i| %> 
  <%= content_tag(:span, i + 1) %> 
<% end %>

The problem is that there is a space between the created spans.

So, I tried to create them in one line:

<% spans = "".html_safe %>
  <% n.times do |i| %> 
    <% spans += content_tag(:span, i + 1) %> 
  <% end %>
<%= spans %>

Indeed, now the spans are close to each other (no space in between).

However, I feel that this workaround is dirty.

How could achieve the same with a cleaner code ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:04:38+00:00Added an answer on May 22, 2026 at 10:04 pm

    If you check the HTML source you can see it’s not a space, but a line-break (which in HTML is displayed as a space). If you put everything in one line the spaces are gone:

    <% n.times do |i| -%><%= content_tag(:span, i + 1) %><% end -%>
    

    This gives me the following output:

    <span>1</span><span>2</span><span>3</span><span>4</span><span>5</span>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a javascript function that will take a hidden span, copy the text
How can I create a button that will scroll to the next jQuery tab.
I am trying to create a horizontal menu with the elements represented by <span>
I don't get it. I created this regular expression: <span class=copy[Green|Red].*>[\s]*(.*)[\s]*<\/span> to match certain
Create Pex test to test a DLL and hardware controlled by that DLL? I
I'd like to use an element like 'span' or any other regular ole' element
Okay, I'm working on a problem that I've been holding off on for three
I have a horizontal navigation bar. Each button is a span with a background
I have created a table that will do an AJAX search for a car
trying to create a simple slider for an input. Using a survey gem that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.