search

Home  >  Q&A  >  body text

How to left align text in Bootstrap and React

I'm using react, react-bootstrap.

Here is my react code snippet:

<Navbar bg="light" expand="lg" className="d-lg-none container-fluid">
   <Navbar.Toggle aria-controls="responsive-course-nav" /> 
   <span className="d-sm-inline-block">Test 123</span>
   { // ... rest of the components }
</Navbar>

Here is the code snippet I convert to HTML when rendering to the browser:

<nav class="d-lg-none container-fluid navbar navbar-expand-lg navbar-light bg-light"><button
        aria-controls="responsive-course-nav" type="button" aria-label="Toggle navigation"
        class="navbar-toggler collapsed"><span class="navbar-toggler-icon"></span></button>
    <div class="d-flex text-right">Test 123</div>
    <div class="navbar-collapse collapse" id="responsive-course-nav">
        <div class="mr-auto navbar-nav">
            <div class="nav-item dropdown" style="padding-left: 0em; padding-right: 0.5em;"><a aria-haspopup="true"
                    aria-expanded="false" id="basic-nav-dropdown" href="#" class="dropdown-toggle nav-link"
                    role="button"><span class="d-lg-none" style="font-size: 21px;"> Course Content </span></a></div>
            <div class="nav-item dropdown" style="padding-left: 0em; padding-right: 0.5em;"><a aria-haspopup="true"
                    aria-expanded="false" id="basic-nav-dropdown" href="#" class="dropdown-toggle nav-link"
                    role="button"><span class="d-lg-none" style="font-size: 21px;"> Course Content </span></a></div>
        </div>
    </div>
</nav>

It is rendered as follows:

I want "Test 123" to be left aligned after the hamburger menu button. How to set CSS styles or bootstrap classes?

Demo

Demo Code Sandbox

##%2

P粉685757239P粉685757239302 days ago416

reply all(1)I'll reply

  • P粉354602955

    P粉3546029552024-03-27 16:58:54

    Add my automatic course.

    Test 123

    Add padding as needed, for example:- px-3

    Test 123

    Code Sandbox: https:// /codesandbox.io/s/dawn-sunset-gib5x5?file=/src/App.js:365-424

    For your bootstrap version, use the following classes. Bootloader: 4.6.0

    Test 123

    Code Sandbox: https://codesandbox.io /s/cocky-bhabha-vmlhqj?file=/src/App.js

    reply
    0
  • Cancelreply