bootstrap4 выровнять элемент панели навигации слева

#html #css #twitter-bootstrap

#HTML #css #twitter-bootstrap

Вопрос:

Я работаю над загрузочной навигационной панелью с версией bootstrap 4, и у меня возникла проблема с выравниванием элемента навигационной панели слева, потому что у меня есть некоторые элементы справа, и я хочу, чтобы аватар профиля был сдвинут влево. Я пытался использовать [Pull-left] и [ml-auto], нотам это не работает, и поэтому какая-нибудь помощь?

код панели навигации:-

 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1 K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2 l" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<nav class="navbar navbar-expand-md navbar-dark bg-dark shadow p-3 mb-5" style="direction: rtl; margin:0;">
  <div class="container-fluid">
    <a class="navbar-brand" href="#"><img src="styles/images/svgtopng.png" alt="" width="65" height="" class="d-inline-block align-top mr-auto"><span style="font-family: hana;">المتجر المتعدد</span></a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <div class="navbar-inner" style="float:right">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item" style="font-family: cocon-next-arabic; font-size:26px;">
            <a class="nav-link active pull-right" aria-current="page" style="direction: rtl;" href="index.php">الرئيسية<img src="styles/images/home.png" alt="" width="66" height="47" class="d-inline-block align-top mr-auto"></a>
          </li>
          <li class="nav-item" style="font-family: cocon-next-arabic; font-size:26px;">
            <a class="nav-link active pull-right" aria-current="page" style="direction: rtl;" href="store.php">المتجر<img src="styles/images/cart.png" alt="" width="66" height="47" class="d-inline-block align-top mr-auto"></a>
          </li>
          <li class="nav-item" style="font-family: cocon-next-arabic; font-size:26px;">
            <a class="nav-link active pull-left" aria-current="page" style="direction: rtl;" href="store.php">Pull Left<img src="styles/images/cart.png" alt="" width="66" height="47" class="d-inline-block align-top mr-auto"></a> 
          </li>
        </ul>
      </div>
      </ul>
    </div>
  </div>
</nav> 

Ответ №1:

Я думаю, это то, что вам нужно.

 <html>

<head>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1 K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2 l" crossorigin="anonymous">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>

<body>
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark" style="direction:rtl">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto" style="direction:ltr; padding-right:40px">
        <li class="nav-item active">
          <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Link</a>
        </li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
            <a class="dropdown-item" href="#">Action</a>
            <a class="dropdown-item" href="#">Another action</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="#">Something else here</a>
          </div>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">Disabled</a>
        </li>
      </ul>
      <ul class="mr-auto navbar-nav">
        <li class="nav-item">
          <a href="#" class="nav-link" style="display:inline-block">Avator</a>
          <img style="display:inline-block; width:40px; height:40px; border-radius:50px" src="https://png.pngtree.com/png-vector/20190223/ourmid/pngtree-vector-avatar-icon-png-image_695765.jpg" />
        </li>
      </ul>
    </div>
  </nav>

  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5 76PVCmYl" crossorigin="anonymous"></script>
  </body>

</html> 

Ответ №2:

поскольку вы добавляете встроенный css в элемент навигации и меняете направление вправо, удалите его

 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1 K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2 l" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<nav class="navbar navbar-expand-md navbar-dark bg-dark shadow p-3 mb-5" style="margin:0;">
  <div class="container-fluid">
   <a class="navbar-brand" href="#"><img src="styles/images/svgtopng.png" alt="" width="65" height="" class="d-inline-block align-top mr-auto"><span style="font-family: hana;">المتجر المتعدد</span></a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <div class="navbar-inner" style="float:right">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item" style="font-family: cocon-next-arabic; font-size:26px;">
            <a class="nav-link active pull-right" aria-current="page" style="direction: rtl;" href="index.php">الرئيسية<img src="styles/images/home.png" alt="" width="66" height="47" class="d-inline-block align-top mr-auto"></a>
          </li>
          <li class="nav-item" style="font-family: cocon-next-arabic; font-size:26px;">
            <a class="nav-link active pull-right" aria-current="page" style="direction: rtl;" href="store.php">المتجر<img src="styles/images/cart.png" alt="" width="66" height="47" class="d-inline-block align-top mr-auto"></a>
          </li>
          <li class="nav-item" style="font-family: cocon-next-arabic; font-size:26px;">
            <a class="nav-link active pull-left" aria-current="page" style="direction: rtl;" href="store.php">Pull Left<img src="styles/images/cart.png" alt="" width="66" height="47" class="d-inline-block align-top mr-auto"></a> 
          </li>
        </ul>
      </div>
      </ul>
 
    </div>
  </div>
</nav> 

Комментарии:

1. та же проблема, ничего не меняется!

2. удален встроенный и направление, возникает та же проблема