Unveiled absolute positioned element disrupts page layout when revealed

I'm facing an issue where an absolutely positioned element is causing content to move when it's displayed. You can see the problem in action by clicking on Profile in this fiddle.

Can anyone help me understand what is causing this behavior and how I can fix it?

Link to the fiddle

$(document).ready(function(){
    $(".navbar-profile").click(function(){
        $(".navbar-profile-content").slideToggle(80);
    });
});
nav {
    width: 100%;
    background-color: #cecece;
}

li {
  list-style: none;
}

nav {
  display: table;
  position: relative;
}

nav .navbar-title {
  width: 10%;
  display: table-cell;
  text-align: left;
}

nav .navbar-site-content {
  width: 80%;
  display: table-cell;
  text-align: center;
}

nav .navbar-site-content li {
  display: inline-block;
}

nav .navbar-profile {
  width: 10%;
  display: table-cell;
  color: #000;
  cursor: pointer;
  text-align: right;
}

nav .navbar-profile-content a {
  display: block;
  background-color: #000;
  color: #fff;
  cursor: pointer;
}

nav .navbar-profile-content {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav>
  <div class="navbar-title">
    <a href="">title</a>
  </div>
  <div class="navbar-site-content">
    <ul>
      <li><a href="">Link1</a></li>
      <li><a href="">Link2</a></li>
      <li><a href="">Link3</a></li>
      <li><a href="">Link4</a></li>
      <li><a href="">Link5</a></li>
      <li><a href="">Link6</a></li>
    </ul>
  </div>
  <div class="navbar-profile">
    <span>Profile</span>
  </div>
  <div class="navbar-profile-content">
    <ul>
      <li><a href="">Link7</a></li>
      <li><a href="">Link8</a></li>
      <li><a href="">Link9</a></li>
      <li><a href="">Link10</a></li>
    </ul>
  </div>
</nav>

Answer №1

Replace display: table-cell with block

header .title {
  width: 10%;
  display: block;
  text-align: left;
}

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

The SyntaxError message indicates that there was an unexpected non-whitespace character found after the JSON data when parsing it

I received an Error message: SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data Here is the code snippet: <script> $(document).ready(function () { $('.edit1').on('change', function () { ...

.htaccess file encounters an error when attempting to incorporate an argument related to HTTP 451

My website includes a .htaccess file with the following contents: <Files .htaccess> order allow,deny deny from all </Files> ErrorDocument 404 /websites/404/index.php Adding additional ErrorDocument lines should work, like so: <Files .hta ...

Combining ajax and jsp to fetch data for a servlet

In my JSP file, I have two text fields - signUp and post. I want the post text to be sent to a servlet using AJAX function while the signUp text should be sent in the usual way through request.getParameter(). Can these two functionalities be combined with ...

Looking to incorporate multiple accordion drop down menus on your website? Utilize a combination of HTML, CSS, and JavaScript to

I am experiencing a challenge with implementing multiple accordion menus on my website. Whenever I attempt to duplicate the code, the new accordion menu appears but clicking on the first bar simply scrolls me back to the top of the webpage. Below is the H ...

Can a webpage be redirected to another page while passing along the id from the original page?

https://i.sstatic.net/3LhYJ.png I have a page that displays shop names and addresses along with an edit function in views.py: def update_shop(request, id): context = {} # * fetch the object related to passed id obj_shop = get_object_or_404(VideoL ...

Issues with creating modal images using only JavaScript

I am facing an issue with modal popup images. I have a collection of images and attempted to implement this code (with some modifications): https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal_img However, it seems to only work for the initi ...

Guide on validating an input field with an array type name using the jquery.validate.min.js plugin

I am dealing with input tag fields that each have a name attribute within an array. For example: <div class="form-group"> <label class="col-sm-2 control-label"> <span style="color: red;">*</span> Title</label ...

How to Keep PHP Include Visible within the div using Bootstrap 4

I utilized PHP include to add the information inside the modals for the albums, but it is not hidden as specified in the div class where it is included. You can check out the music page on . However, here is the code snippet for the music page where I in ...

How do you set a background image for the color of the font?

Imagine I have this piece of code: <span>Hello world!</span> Along with the following CSS: span{ color:red; } Is it possible to replace the red value with an image? Something like url(images/text-bg.png);? I am looking to add a texture to m ...

Enhancing websites with CSS3 and VueJS for fluid and captivating background gradients transitions

After implementing a logic in the application, the gradient is now changing dynamically. <template> <div :style="`background-image: ${backgroundImage}`" class="background"> <snackbar /> <nuxt /> <default-footer /&g ...

Utilizing JavaScript to adjust the width of an HTML element

Struggling to manipulate the position and size of a div tag using a JavaScript function, particularly confused about how to retrieve the current width of the div. Here is the function in question function socialExt() { document.getElementById("Left") ...

How can transitions be activated in Bootstrap 4 carousel?

Having an issue with my Bootstrap 4 carousel where I need to move 4 slides at a time. I have tried using the code below: $(this).carousel(4); However, the problem is that the carousel only jumps to that index without showing any transitions. Using $(this) ...

Button click functionality for updating in Classic ASP is functioning correctly exclusively in Internet Explorer and not in other web browsers

Currently, I am in the process of enhancing a Classic ASP application. Within this application, there is an HTML table that is populated from a SQL database. One cell within the table contains checkboxes. Upon clicking one of these checkboxes, a popup wind ...

Trouble with the Rotate <text> feature in Internet Explorer 11 on Windows 10

I am using d3.js to draw SVG with the transform:rotate(180deg) property. It displays perfectly on Chrome, but doesn't work on IE11. I tried changing it to rotateY(180deg), and it works with div elements but not with text elements. Here is my screen an ...

Passing information from the created hook to the mounted hook in VueJS

How can I transfer data from the created function to the mounted function in VueJS? In my VueJS application, the code in my created function is as follows: created: function(){ $.getJSON({ url: 'static/timeline.json', success:function( ...

The intersection observer fails to detect any new elements or entries that are appended to the page after it has

When I press the "add section" button to create a new section, the intersection observer does not seem to observe it. Even when I try to run the observer again after pressing the button, it still doesn't work. I suspect that I need to reassign the `se ...

Creating a custom dropdown behavior using Angular

I have a unique interface requirement where users must be able to click on an element to view its options, which are displayed as checkbox inputs. Essentially, I need a custom 'select' element that allows for multiple checkbox selections. ...

Which JSF element is capable of displaying a <div> element?

For example, h:inputText will display an "input type='text'". Which JSF tag is used to render a "div" element? ...

grasping the intricacies of certain JQuery syntax

I could really use some assistance understanding this jQuery code. I've tried searching online without much luck, and I'm not even sure what exactly to search for! (It seems like the lines in question may relate to a jQuery extension). JSP < ...

Struggling to get my upload form to function properly with two different versions of jQuery, even after attempting to use jQuery.noConflict

I am facing an issue with a webpage that contains two different forms. The first form is for uploading pictures and generating the link for the uploaded images, while the second form is a regular one used to add products to a database using the links from ...