Creating a static menu icon and implementing a wide dropdown menu in Bootstrap 4

I am facing two major challenges and I am struggling to find solutions for them!

Below is the code snippet I am working with:

@font-face {
    font-family: 'yekani';
    src: url("../fonts/yekan.ttf");
}
@font-face {
    font-family: 'yekani';
    src: url("../fonts/yekan.eot");
}
@font-face {
    font-family: 'yekani';
    src: url("../fonts/yekan.woff");
}

body{
    font-family: yekani;
}
.container-fluid{
    padding: 0 6rem;
}
.menu{
}
.links a{
    font-size: 1.25rem;
    color: #333;
}
.menu{
    box-shadow: 0 1px 4px 1px #d0d0d0;
}
.logo img{
    width: 120px;
}
.btn-outline-primary{
    border-width: 2px;
    border-color: #cce1e7;
    color: #3dacd9;
}

.navbar-nav .nav-link{
    padding-left: 2rem !important;
}
.links i{
    color: #f5f5f5;
    font-size: 1.2rem;
}
.navbar-toggler i{
font-size: 2rem;
}


.navbar .dropdown {position:static;}

.navbar .dropdown-menu {
    width:80rem;
    left:0;
    right:40rem;
    /*  height of nav-item  */
    top:5rem;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <title>مثال بوت استرپ</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">

</head>
<body>

    <div class="container-fluid menu">
    <div class="d-flex  ">
        <div class="mr-auto ">
        <button class="btn btn-outline-primary btn-lg mb-4 mt-4 pt-2 pb-2 ">
            <i class="fas fa-arrow-left"></i>
            عضویت : ورود
        </button>
        </div>
        <div class="links ">
            <nav class=" navbar navbar-expand-xl mb-4 mt-4">

                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar" >
                    <i class="fas fa-bars text-dark "></i>
                </button>

            <div class="collapse navbar-collapse" id="collapsibleNavbar">
            <ul class="navbar-nav navbar-light">
                <li class="nav-item "><a class="nav-link " href="">ارتباط با ما</a></li>
                <i class="fas fa-ellipsis-v  m-3"></i>

                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown" >
                        دوره های مجازی
                    </a>
                    <div class="dropdown-menu">
                        <a class="dropdown-item" href="#" > دوره های مجازی</a>
                        <a class="dropdown-item" href="#">دوره های مجازی</a>
                        <a class="dropdown-item" href="#">دوره های مجازی</a>
                    </div>
                </li>

                <i class="fas fa-ellipsis-v m-3"></i>

                <li class="nav-item "><a class="nav-link" href="">دوره های متخصص</a></li>
                <i class="fas fa-ellipsis-v m-3"></i>

                <li class="nav-item "><a class="nav-link borderl" href="">محتوا</a></li>
            </ul>
            </div>
            </nav>
        </div>
        <div class="logo mt-4 mb-4 ml-5 d-none d-xl-block">
            <img src="https://s.7learn.com/themes/slt/assets/img/logo.png" alt="">
        </div>
    </div>
</div>

</body>
</html>

One issue I am facing is with the menu icon, which seems to be moving unexpectedly. I have tried to make it stationary, but have not been successful. The second problem relates to the dropdown menu, which I want to be full width. Despite my efforts, the dropdown menu width is not as expected and causes the layout to break to the right. If you make any changes to my code, please explain them to me. Thank you and apologies for any grammatical errors, as English is not my first language.

Answer №1

Make the following changes to your layout. Place your left button within the navbar instead of outside it, and use the navbar-brand class from Bootstrap for styling.

@font-face {
  font-family: 'yekani';
  src: url("../fonts/yekan.ttf");
}

@font-face {
  font-family: 'yekani';
  src: url("../fonts/yekan.eot");
}

@font-face {
  font-family: 'yekani';
  src: url("../fonts/yekan.woff");
}

body {
  font-family: yekani;
}

.container-fluid {
  padding: 0 6rem;
}

.menu {}

.links a {
  font-size: 1.25rem;
  color: #333;
}

.menu {
  box-shadow: 0 1px 4px 1px #d0d0d0;
}

.logo img {
  width: 120px;
}

.btn-outline-primary {
  border-width: 2px;
  border-color: #cce1e7;
  color: #3dacd9;
}

.navbar-nav .nav-link {
  padding-left: 2rem !important;
}

.links i {
  color: #f5f5f5;
  font-size: 1.2rem;
}

.navbar-toggler i {
  font-size: 2rem;
}

.navbar .dropdown {
  position: static;
}

.navbar .dropdown-menu {
  width: 80rem;
  left: 0;
  right: 40rem;
  /*  height of nav-item  */
  top: 5rem;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">

</head>

<body>

  <div class="container-fluid menu">
    <div class="links ">
      <nav class=" navbar navbar-expand-xl mb-4 mt-4">
        <button class="btn btn-outline-primary btn-lg mb-4 mt-4 pt-2 pb-2 navbar-brand ">
            <i class="fas fa-arrow-left"></i>
            Sign Up: Login
        </button>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
                    <i class="fas fa-bars text-dark "></i>
                </button>

        <div class="collapse navbar-collapse" id="collapsibleNavbar">
          <ul class="navbar-nav navbar-light">
            <li class="nav-item "><a class="nav-link " href="">Contact Us</a></li>
            <i class="fas fa-ellipsis-v  m-3"></i>

            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
                        Virtual Courses
                    </a>
              <div class="dropdown-menu">
                <a class="dropdown-item" href="#"> Virtual Courses</a>
                <a class="dropdown-item" href="#">Virtual Courses</a>
                <a class="dropdown-item" href="#">Virtual Courses</a>
              </div>
            </li>

            <i class="fas fa-ellipsis-v m-3"></i>

            <li class="nav-item "><a class="nav-link" href="">Specialized Courses</a></li>
            <i class="fas fa-ellipsis-v m-3"></i>

            <li class="nav-item "><a class="nav-link borderl" href="">Content</a></li>
          </ul>
        </div>
      </nav>
    </div>
    <div class="logo mt-4 mb-4 ml-5 d-none d-xl-block">
      <img src="https://s.7learn.com/themes/slt/assets/img/logo.png" alt="">
    </div>
  </div>


</body>

</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling with incorporating a web link into a structured data table

I am currently working on a Django application that utilizes jQuery DataTables to display a list view of items. My goal is to include a hyperlink in the first element of the table, which represents the primary key for the model being displayed. This link s ...

Using Express.js, the require() method is called, followed by a function that takes

I'm relatively new to Node.js and Express. While browsing tutorials and examples, I came across the following code snippet inside app.js: var router = require('./router')(app); I'm curious about the purpose of this line of code. What ...

User has logged out, triggering the browser tab to close automatically

Is it possible to automatically log out the user when all browser tabs are closed? How can I obtain a unique ID for each browser tab in order to store it in local storage upon opening and remove it upon closing? Here is what I have attempted: I am utiliz ...

Trouble with executing jQuery $.ajax post to PHP within the same file

Here is the code snippet: <script> $( document ).ready(function() { $( ".button" ).click(function() { var clickBtnValue = $(this).val(); $.ajax({ //url: '', // url is empty because I'm working in the ...

"Cookie Magic: Unleashing the Power of Ajax and

I am currently working on an ASP.NET 3.5sp1 application with a single page layout where all interactions are handled through ajax, eliminating the need for postbacks. The website in question is . This app does not require user accounts and allows anonymou ...

Is there a way to prevent the text next to these FontAwesome icons from moving whenever the icon itself changes?

I am currently working on creating a unique custom checkmark using FontAwesome in my project. Below is the snippet of HTML and CSS style code that I am using: .check { font-size: 1.25rem; cursor: pointer; } .check-unselected { color: #4E44 ...

Nuxt - issue with updating window innerwidth getter

The class based components in our project utilize a getter to retrieve the window innerWidth. However, I've noticed that the value is only set once and doesn't update if the window width changes. get viewPortWidth() { if (process.client) { ...

Using JavaScript in Selenium, you can check a checkbox and verify whether it is checked

How can I select a checkbox and determine if it is checked using JavaScript, Selenium, and Node.js? I have attempted to use the .click method on the element and also tried native JavaScript code, but unfortunately it has not worked for me. driver.findElem ...

"Modifying a variable within an object while iterating through a loop

I am attempting to update a variable within an object while looping through the elements. Specifically, I am targeting all parent elements with the class "parent" to use with the ScrollMagic plugin. Here is my code: var childElement = $('.child' ...

Custom palette in Material UI design palette allows users to create

Hey there everyone! I've been working on a website using ReactJS and Material UI, starting with this cool template. One thing I'm trying to do is change the color of the TextField when it's focused. Right now it's blue, but I want it ...

Transmit information to a webpage using jQuery AJAX and the .data() function as you navigate to the page

<script> function sendUserData(username){ $.post("userprofile.php", { username:username } ); document.location.href="userprofile.php"; } $(document).on('click','#userprofile',function(){ var username=$(this).data('id4&apo ...

Initiating and pausing an Interval using a single button

I'm attempting to create a JavaScript-based chronometer that starts and stops when a single button is clicked. However, I am struggling to figure out how to properly implement the setInterval function to achieve this functionality. Below is my current ...

When aligning divs at the center, they may not all be perfectly in a straight

My goal is to align 4 div boxes in a vertical line using the translate method typically used for centering objects on a webpage. Here is the code snippet I have utilized: link .body-component { position: relative; margin: 10px; color: #000; disp ...

Are you in the business of building JavaScript hubs?

I have a unique setup where my express server is in charge of handling all routing and session functionalities. I've envisioned a system where logged-in users can connect to distinct "hubs" based on the location of each hub. My idea was to treat each ...

Learn the secret to displaying and concealing images with jquery!

I'm working on enhancing a question I recently published. After scrolling down the page 200px, the image changes its size. I'm also looking to implement additional functions that I'm struggling to make work. Specifically, I want to achiev ...

Tips for updating the background color when clicking in Vue

I've been attempting to change the background color of an element upon clicking it using Vue, but so far I haven't had any success. Here's what I have come up with, including a method that has two functions for the onclick event in Vue. &l ...

Node.js throwing error due to incorrect format of bind parameters as an array

I have been working with Nodejs/express and trying to implement a paramerized query in my API. However, I encountered the following error message in my console: Bind parameters must be array if namedPlaceholders parameter is not enabled Below is a snippet ...

Tips for Implementing CSS Styles on Ruby on Rails HTML Pages

Just starting out with RoR and trying to customize my form with CSS classes. Here's what I have so far: <%= form_tag :action => 'create' do %> <p><label for = "name">Name</label>: <%= text_field ...

Set the text above the image in HTML and center align it

Hey everyone, I'm new to the world of HTML and CSS. Currently, I am working on designing some text above and centering an image. Additionally, I want the text to automatically wrap if the image is too long. Thank you for your help! Below is the code I ...

Are Global variables supported in the EXT JS framework?

When working with Java and C++, it is common practice to store a variable globally so that its value can be accessed from anywhere within the project. For example, if I am working inside a class named Residence and saving an INT as the residenceNumber to a ...