0

I want a margin between my button (increment) and badge (bootstrap classes badge badge-primary). The tutorial I am using is outdated and I am having trouble finding it online. What is the proper margin class to use (tutorial said m-2)

 render() {
//React.createElement('div')
return (
  //in curly braces any js statement is valid
  <div>
    <span className="badge badge-primary m-2">
      {this.formatCount()}
    </span>
    <button>Increment</button>
  </div>
);
}

And to be clear, the issue is in this exact snippet.

<span className="badge badge-primary m-2">

Thank you for any responses, I am a beginner :)

3
  • 1
    Which version of boostrap are you using? Can you please post a code snippet which reproduces your problem? Commented Jun 21, 2020 at 19:02
  • @MarkoGrešak in my package.json it says 3.4.1. I also did post a code snippet after which shows where I had the problem, what did you mean?
    – apsasha
    Commented Jun 21, 2020 at 19:06
  • the m-2 (utility classes) is a feature of Bootstrap 4. getbootstrap.com/docs/4.3/utilities/spacing Commented Jun 21, 2020 at 19:22

1 Answer 1

1

With m-2 you should have 0.5 rems of margin on all four sides of that span element. Are the badge and badge-primary classes being applied? I suggest using Google Chrome Dev tools => Elements tab => ".cls" button => add and remove classes to see how elements receive styles. Refer to Bootstrap spacing docs: https://getbootstrap.com/docs/4.0/utilities/spacing/

EDIT: It's also probably because the span element is an inline element, so try either adding class d-block or d-inline-block to see m-2 apply, or change from span to a block-level element like div.

3
  • thank you for your response, I have already looked at the bootstrap docs, m-2 and mx-2 are not working for some reason. I changed span to div (resulted in error) and adding the d-block classes did not work, any idea why?
    – apsasha
    Commented Jun 21, 2020 at 19:14
  • 1
    I noted in one of your previous comments that you're using Bootstrap 3.4.1. That is probably why the m-2 class is not being applied as it was introduced Bootstrap 4. I haven't yet been able to find how to add margin using that version of Boostrap, so I would either install a later version or manually apply the style e.g. style={{ margin: '0.5rem' }}.
    – user9856145
    Commented Jun 21, 2020 at 19:27
  • Now I have "bootstrap": "^4.0.0-alpha.6" (found in package.json). m-2 still is not working.
    – apsasha
    Commented Jun 21, 2020 at 19:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.