Steps for connecting a div to a collapsible navigation bar

I have a website with a collapsible navbar at the top for small screens. I want to add a red circle positioned on the right side of the navbar. Something like this: view image here The circle is not a button and should be centered on the border of the navbar.

I've tried various solutions found online, like setting the parent div to relative position and the child div to absolute position. However, none of them have been responsive.

Below is my current HTML code, which is not responsive:

.circle {
  position:absolute;
  <--top:35px;-->
  right:3vw;
  width:20px;
  height:20px;
  background: #d21c2d;
  border-radius:50%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-fixed-top navbar-expand-lg green-background">
    <div class="container-fluid">
       <-- 80 lines of navbar code including a collapse navbar-collapse div -->
    </div>
    <div class="circle"></div>
</nav>

I have only been able to place the circle for a specific screen size, and it doesn't respond well to changes in screen size or when in collapsible mode.

Thank you for any assistance you can provide. Have a great day :)

Answer №1

To determine the value, utilize the calc function. Adjust the px measurement from the total % as needed.

.circle {
  position:absolute;
  top: calc(100% - 10px);
  right:30px;
  width:20px;
  height:20px;
  background: #d21c2d;
  border-radius:50%;
}
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>


</head>

<body>
   <nav class="navbar navbar-full navbar-expand-lg navbar-light bg-light">
    <div class="container logo" style="position: relative;">
      <a class="navbar-brand text-left d-block float-left d-xl-flex logo" href="assets/img/kol-logoldpi.svg"><img class="kibrislogo" height="50" src='assets/img/kol-logoldpi2.svg' /></a><button class="navbar-toggler" data-toggle="collapse" data-target="#navcol-1"><span class="sr-only">Toggle navigation</span><span class="navbar-toggler-icon"></span></button>
      <div class="collapse navbar-collapse" id="navcol-1">
        <ul class="nav navbar-nav ml-auto text-center">
          <li class="nav-item" role="presentation"><a class="nav-link active" href="index.html">Paketler</a></li>
          <li class="nav-item" role="presentation"><a class="nav-link" href="features.html">Kampanyalar</a></li>
          <li class="nav-item" role="presentation"><a class="nav-link" href="pricing.html">sss</a></li>
          <li class="nav-item" role="presentation"><a class="nav-link" href="about-us.html">Hizmet Noktalari</a></li>
          <li class="nav-item" role="presentation"><a class="nav-link" href="contact-us.html"><strong>İLETIŞIM</strong></a></li>
          <li class="nav-item" role="presentation"><a class="nav-link" href="contact-us.html" style="color: rgba(207,14,14,0.5);">TR/ENG</a></li>
        </ul>
      </div>
      <img class="logo" style="position: absolute; right: -7%; height: 70px;" src="assets/img/kol-ccldpi.svg" alt="">
    </div>
    <div class="circle"></div>
  </nav>
</body>

</html>

Answer №2

Experiment with this code snippet to enhance your navbar design:

.circle{
position: absolute;
z-index: 1001;
right: 35px;
top: 45px; 
width: 20px;
height: 20px;
background: #d21c2d;
border-radius: 50%; 
}

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

Freeze the headers of multiple tabulators on a single page without restricting the height

My website contains more than 3 tabs and several charts interspersed between tables. Based on the requirement, we have not set a fixed size for the tables. Therefore, the height of the table varies depending on the data. I am looking to fix the headers o ...

change the width of a div element to match that of its nearest sibling element

Can the width of a div be automatically set to match its closest sibling when the width is set to width: auto;? In my coding example on jsFiddle, you can observe three colored divs - red, green, and blue. I am aiming for the blue div to adjust its size ba ...

Implementing personalized SVG icons for list items

Here is some HTML code along with SCSS that I need help with: <div class="risk"> <ul> <li><span>Aggressive</span>Lorem ipsum dolor ...</li> <li><span>Growth</span>doloremque autem...</li ...

jQuery, the magical tool that can make forms disappear and reappear in a blink

As the heading suggests, here is the code I attempted. The forms are designed to be displayed one after the other, with each subsequent form's appearance being determined by the information provided in the previous forms. $(document).ready(function() ...

Is there a way to align the text input and text area next to each other?

I need help with styling a contact form that consists of 4 text input fields and 1 text area. Here is the current code for the contact form: <form class="contact_form"> <input type="text" placeholder="Name"> <input type="text" plac ...

Experiencing challenges with showcasing numerical values in the grid cells

My latest project involves creating an interactive sudoku solver. I've successfully created a grid made up of various elements to resemble an empty sudoku grid. However, my challenge lies in getting the numbers to display within the grid cells. Click ...

Tips for creating a horizontal list within a collapsible card

When a user clicks on a button, I am dynamically populating a list of items. Despite using list-group-horizontal, I am unable to make it display horizontally. HTML code <div id="textarea_display" class="mt-2 "> <label&g ...

What are the placeholders for the "localIdentName" query tag in a custom CSS-loader for Webpack?

Just starting out with Webpack and experimenting with the css-loader. I came across the option to specify a localIdentName query tag on the Github page under "Local Scope". This tag allows us to define our own custom values for how classes should be named ...

What is the best way to bring a background image to the forefront?

I am currently working on creating a list of "fake videos" which are essentially images with a play icon on them. My plan is to use the play icon as a background and bring it to the front of the image by adjusting the z-index. However, no matter what I try ...

Using Jquery to Switch Pages

Recently, I've been experimenting with using hashes to create animated transitions between pages. Interestingly, the first page that loads (the home page) fades in and out seamlessly. However, when I attempt to navigate to another page, specifically t ...

Line up with miniature stature

How can I prevent the image in this row from getting a margin at the bottom when I resize the window? <div class="row-fluid"> <div class="span2"> <img src="https://s3.amazonaws.com/media.jetstrap.com/SLgRUEHSyGwQVfG4x6ed_curso_a ...

CSS page breaks function properly in Internet Explorer 8, however, they are not functioning correctly in Firefox and Google Chrome

Help Needed: I encountered an issue where I wrote CSS to display page breaks in my HTML. It seems to work fine in Internet Explorer, but not in Firefox and Chrome. Here is the inline CSS I used: <br style="page-break-after: always;"> Below is a sni ...

Avoid repeating media queries in MUI JSS by combining them efficiently

Is there a more efficient way to apply the same set of CSS styles to multiple media query rules without repetition? Currently, the only workaround seems to be: [theme.breakpoints.up('xl')]: { color: 'red', backgroundColor: 'gre ...

Place an element in a higher position than a slideshow

I recently encountered an issue where I was trying to place a png image above my slideshow. Despite trying various solutions, the image always appeared behind or on top without transparency. Based on the erratic display, it seems like the problem might be ...

Is there a way to pick up text where a div element ends using Bootstrap or HTML?

Using Bootstrap, I placed a div on the right and now I want the text outside to seamlessly continue from where the text inside the div ends. You can see the visual representation of what I'm aiming for in this picture. Any suggestions on how to achiev ...

Stop images within contenteditable divs from being easily dragged and dropped into unrelated div elements

In order to maintain data integrity, I have implemented a rule where users are allowed to drag images within a specific div. Later on, I need to retrieve the positions of these images within the div. However, it is crucial for my business requirements tha ...

What is the best way to create a fixed contact form on specific pages?

There is a Contact Form 7 on the webpage that I want to make fixed to the right side. Initially, the form is hidden and only the form button (open) is visible. When clicked, the form should open. ...

Is it possible that a link with a negative z-index is unclickable in IE11 but functions properly in Chrome, Firefox, and Edge?

I am currently facing an issue with a menu and div content. The problem is that the link in the menu is not clickable on IE 11. What could be causing this problem? Visit this link for more details #menu { position: absolute; background: red; wid ...

Is there a way for me to establish a maximum word count for a paragraph?

When my paragraphs get lengthy, I only want the first 30 words to display on two lines. Is there a way to achieve this using HTML, CSS, or JS? The code snippet I tried did not work as expected. .long-text{ width: 70ch; overflow: hidden; white-sp ...

What is the process for incorporating a full-page blog into a blog preview?

I customized a template, but there is a blog section within the div that I am struggling to replicate. Here is the test website for reference: Below is the HTML code for the blog section: <!-- Blog Start --> <section class="section bg ...