What is the best way to enclose a parent div around a child div that has been

I'm struggling to figure out how to make the headerLinks div encompass both headerLink divs so that I can adjust the links' positions and margins as a group. Is there a better approach I should be taking? If so, could you provide guidance on how to correct my code? Thank you in advance.

Here is the code snippet:

#header {
  background-color: #EDEDED;
  position: fixed;
  width: 100%;
  top: 0px;
  box-shadow: rgb(0, 0, 0) 0px 0px 10px;
}

#headerItems {
  list-style-type: none;
  overflow: hidden;
  margin: 10px;
  padding: 0px;
}

#headerName {
  float: left;
  display: inline-block;
  color: #3D3D3B;
  font-size: 28px;
}

.headerLinks {
  display: inline-block;
  float: right;
}

.headerLink {
  text-align: center;
  margin: 5px;
  float: right;
}

.headerLink a {
  color: black;
  padding: 5px;
  background-color: #E1E1E1;
  text-decoration: none;
  font-size: 20px;
}
<div id="header">
  <ul id="headerItems">
    <li id="headerName">My name</li>
    <div id="headerLinks">
      <li class="headerLink"><a href="" target="_blank">Link 1</a>
      </li>
      <li class="headerLink"><a href="" target="_blank">Link 2</a>
      </li>
    </div>
  </ul>
</div>

Answer №1

Ensure that only the links on the right are contained within a ul.

To prevent the links from reversing order, apply float:right to the parent (headerLinks) and float left to the lis

* {box-sizing: border-box;}
body {margin: 0;}
#header {
  background-color: #EDEDED;
  position: fixed;
  width: 100%;
  top: 0px;
  box-shadow: rgb(0, 0, 0) 0px 0px 10px;
  padding: 10px;
}
#headerName {
  float: left;
  display: inline-block;
  color: #3D3D3B;
  font-size: 28px;
}
#headerLinks {
  list-style-type: none;
  overflow: hidden;
  padding: 0;
  margin: 0;
  float: right;
}
.headerLink {
  text-align: center;
  margin: 5px;
  float: left;
}
.headerLink a {
  color: black;
  padding: 5px;
  background-color: #E1E1E1;
  text-decoration: none;
  font-size: 20px;
}
<div id="header">
    <span id="headerName">My name</span>
    <ul id="headerLinks">
      <li class="headerLink"><a href="" target="_blank">Link 1</a></li>
      <li class="headerLink"><a href="" target="_blank">Link 2</a></li>
    </ul>
</div>

If you plan to create a dropdown menu, nest another ul inside the li

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

Transform the text upon hovering over the image, with the text positioned separate from the image

I'm looking for a solution where hovering over images in a grid area will change the text on the left side of the screen to display a predefined description of that image. I've been working on this problem for hours and would appreciate any help. ...

Controlling the Alignment of HTML Div Elements

I'm struggling to align some of these divs, especially centering them. I want the page to closely resemble this image: Here are the specific requirements: 1) The header text should be centered vertically and placed in a separate div with a black back ...

What is the best way to include a search box in the mobile view between the brand and menu toggle?

Is there a way to place the search bar between the brand and menu toggle on the mobile view without it appearing on a separate row either under or over the navbar? I've been trying to override some Bootstrap CSS but haven't found a solution yet. ...

Inspired by the organization and depth provided by nested lists

I am facing an issue with my ul list where adding a nested ul causes the li items above to move. Can anyone explain why this is happening and suggest a solution? Here is an example: http://jsfiddle.net/y5DtE/ HTML: <ul> <li> first ...

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() ...

How can I achieve a similar layout in my .cshtml file?

https://i.sstatic.net/f1C0G.png Hey there, I'm looking to achieve a layout similar to the one shown in the image. Specifically, I want the left side panel to remain unchanged when expanding the Accordion control on the right side. Can someone guide ...

Can a CSS Grid layout be achieved without prior knowledge of image sizes?

I am working on a project where I am pulling images from Reddit and aiming to showcase them in a gallery-style grid. I have tried using a flex display and resizing the images to match dimensions, but unfortunately not all images have the same dimensions ...

Guide to customizing color themes using Twitter Bootstrap 3

Recently, I dove into the world of Twitter Bootstrap 3 without any prior experience with earlier versions. It's been a learning curve, but I managed to set up a WordPress theme using it as the framework. All my elements are in place, but they all see ...

Extract particular details from my database

I need help creating a table to display all chat messages sent to the server. I have the table set up, but now I want to make it so that when I click on a user's name like 'demo', it will show me all the chat messages sent by that specific u ...

Proper techniques for enlarging a background image using CSS

When utilizing the CSS scale() function along with a transition and transform on a div element that contains a high-quality background image, I noticed that the image becomes blurry when zoomed in. How can I achieve a smoother zoom effect for high-quality ...

Overriding table styling with Bootstrap in a custom stylesheet

Recently, I made the switch from bootstrap v4 to v5 and I am in the process of identifying and fixing any issues that may have arisen. One particular issue that I am stuck on is the <th> tag not displaying correctly in the table. It seems like my tab ...

Problem displaying images in Mean stack app using CSS background-image and Webpack

Currently, I am enhancing my skills by working on my own projects. One of the projects I'm focused on right now is designing a MEAN-stack app that utilizes Webpack. In the past, I encountered an issue where I couldn't display images in my app. Ho ...

Struggling with getting the Bootstrap Carousel to switch between slides?

I'm facing a challenge in creating a functioning carousel with Bootstrap. I've utilized a template for this purpose, but the issue lies in the slides not transitioning correctly when I click the arrow buttons to move to the next or previous slide ...

Using Ajax to seamlessly replace content with a smooth fade effect

Is it possible to add a fade effect to the code below, where the content of "demo" div is replaced with the content of "newpage.html"? <button onclick="loadDoc()">Click here</button> function loadDoc() { var xhttp = new XMLHttpRe ...

managing data in an uncomplicated manner

In my website, users can select animals from a database without the page reloading. For example, under the category "Brown Animals," a user might choose "kittens" by checking a checkbox. Later, when browsing through "Cute Animals," if "Kittens" is displaye ...

Adjusting the appearance of internal components with material-ui icons

Currently working on a project using react and material-ui where I am looking to customize the styles of specific elements within components. An example is the ListItem component which includes primaryText, leftIcon among others, and my goal is to modify t ...

Creating a CSS path that incorporates two conditions simultaneously

I'm currently facing a challenge with finding the CSS path in this scenario: There are over 20 child nodes, and I need to identify every node that has fill attribute not equal to none. I understand that I can target a specific node using :nth-child( ...

Exploring the world of jQuery and Ajax to retrieve a full HTML framework

I'm a beginner in jQuery and JavaScript programming. While I've managed to use jQuery for my Ajax calls, I'm facing an issue that has me stumped. When making an Ajax call, I'm trying to return a complete HTML structure, specifically a ...

Move the final column from one table to another table given a specific criterion

I have a task where I need to extract the last column from table3 and transfer it into table4. For example, consider table3: Names Process_id Total construction 1 1111 construction_1 1 0000 engineering 1 22 ...

Issues with the Jquery feedback plugin's functionality are currently preventing it

I wanted to incorporate a feedback feature into my web application. To do this, I searched on Google and found a suitable jQuery plugin. I followed the documentation provided by the plugin, including the library in my HTML file, and then wrote the code as ...