Shift the position of menu items to the left as the search box expands

When I click on my search box, it expands to the left. However, I want the links next to the search box to also move to the left when the search box expands.

This is the code snippet I am currently working with:

Example Link

<nav class="header-menu">
  <ul>
    <li><a href="">Menu 1</a></li>
    <li><a href="">Menu 2</a></li>
    <li><a href="">Menu 3</a></li>

    <li class="search-wrap">
      <input class="search" type="search" placeholder="Search"></li>
  </ul>
</nav>

.header-menu ul li {
  display: inline-block;
  vertical-align: middle;
}

.search-wrap {
  width: 175px;
  position: relative;
  height: 27px;
  vertical-align: middle;
  display: inline-block;
}

.search {
  border: 1px solid #ccc;
  padding: 5px 7px;
  margin-left: 15px;
  width: 175px;
  -webkit-transition: all .5s ease;
  -moz-transition: all .5s ease;
  transition: all .5s ease;
  position: absolute;
  right: 0;
  top: 0;
}

.search:focus {
  width: 225px;
}

Currently, the search box expands to the left upon clicking but the menu items do not move accordingly. How can I adjust this? Any suggestions would be greatly appreciated.

Thank you for your assistance!

Answer №1

To align the text to the right within the parent UL, you should use the CSS property text-align:right;


.header-menu ul {
  text-align:right;
}

.header-menu ul li {
  display: inline-block;
  vertical-align: middle;
}

.search-wrap {
  width: 175px;
  position: relative;
  height: 27px;
  vertical-align: middle;
  display: inline-block;
  border: 1px solid #ccc;
  margin-left: 15px;
  -webkit-transition: all .5s ease;
  -moz-transition: all .5s ease;
  transition: all .5s ease;
}

.search {
  border: none;
  padding: 5px 7px;
  width: 100%;
}

.search-wrap:focus-within {
  width: 225px;
}

If you require absolute positioning, it is recommended to apply it to the nav element and not its li or inner elements.

For further reference, you can check out this fiddle: https://jsfiddle.net/qz1m5hub/

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

What are the steps to resolve issues with URL Encoding?

Here is my website link: forumdisplay.php?462-%EE%F9%E7%F7%E9%ED-%E1%F8%F9%FA I suspect that the url is URL Encoded. I am using vbulletin 4.1.12 How can I resolve this issue? Replace 462-%EE%F9%E7%F7%E9%ED-%E1%F8%F9%FA with f=462 ...

To indicate surpassing the character limit, add ... to the conclusion

Is it possible to add ellipsis (...) at the end when the character limit is exceeded? I currently have code that keeps characters on the same line, but I would like it to be displayed in a maximum of two columns and place the excess content at the end. T ...

Navigating through an array of images using ng-repeat

I am attempting to iterate through the image array and have each image correspond to a separate li. Despite using the variable "image" as my identifier, I am encountering difficulties looping through the array. The line that I am trying to modify is as fol ...

Navigating to User's Specific Info Page using Node.js

Would love some input on my current issue. I have a table featuring a list of users, and my goal is to display user information in detail whenever a user (which corresponds to a row in the table) is clicked. The process involves identifying which user was ...

Customizing jQueryUI Button: Changing the Color of Button Icons

I have embedded an HTML button within a div using the following structure: <div class="ui-state-highlight"> <button type="button" class="ui-button ui-state-default ui-corner-all ui-button-text-icon-primary"> <!-- first span --&g ...

The expression "routerlink" in Angular 9 is not recognized,

Currently, I am in the process of developing an Angular 9 application and have encountered two challenging issues. Firstly, as I navigate through the routes using the navbar, I notice an error message in the console stating "Syntax error, unrecognized exp ...

What is the best way to add a character within a YouTube JSON link?

Fetching json data from a link, the youtube format in the link is http:\/\/www.youtube.com\/watch?v=UVKsd8z6scw. However, I need to add the letter "v" in between this link to display it in an iframe. So, the modified link should appear as ht ...

Convert a fixed Jquery div to absolute positioning when it reaches the end of the page

I've implemented a Jquery code that adds a fixed class to a div when scrolling down. However, I now want to remove this fixed class when it reaches the bottom of the page and replace it with a new one that includes position:absolute; and margin-bottom ...

Building a HTML table using PHP

My goal is to generate a dynamic table using data from mysql. I am trying to create the table layout as shown in 'demo1', but I am facing challenges with the formatting, similar to what is depicted in 'demo'. The query and values are co ...

Tips for connecting a webpage element with endless scrolling functionality

Currently, I am dealing with a webpage that features a container utilizing infinite scroll to load numerous articles. I am faced with the challenge of how to effectively link to a particular article when its corresponding div is only loaded into the DOM u ...

The active class in CSS will not function properly; only the default Bootstrap active class will be

No matter what I do, I can't seem to change the active background in CSS. It keeps defaulting to the btn-primary bootstrap style. <button id="home" type="button" class="btn btn-primary active" href="#home">Home</button> .btn:active, .b ...

Issue with Hover behavior not being implemented on Android Webview

On my webpage, I have multiple CSS hover styles implemented using both the :hover pseudo selector and the cursor property. However, when loading this webpage in an embedded WebView on an Android device equipped with a mouse (such as Chromebooks), the CSS h ...

Using webpack to scope all SCSS styles under the selector of a Vue app

Currently, I am developing a Vue app that is embedded within a page on a more traditional server-rendered website. The app is contained within the following container: <div id="account-summary-container"></div> During local development, every ...

CSS - Adding a Distinctive "Line" to a Navigation Bar

I am attempting to design a unique navbar layout with two "lines". The first line should consist of several links, while the second line would include an HTML select field with a submit button. The following code will generate the desired navbar visual ou ...

Employing an odd/even toggle for assigning class names

I need each this.state.title to be aligned based on a different classname. I attempted using css flex boxes/nth-of-type/nth-child, but it didn't work well with React. I'm utilizing this.state to access my objects. My failed strategy render: f ...

CKEditor displays the HTML content as regular text

After using CK editor to store HTML data in the database successfully, I am encountering an issue where the saved HTML content appears as plain text when viewed. Here is an example: &lt;div class=&quot;testimg&quot;&gt; Legion of Honor Mu ...

Wide website design doubled in size

I'm struggling to understand why the width of our website is so large. Take a look at it here: https://85.25.242.165/lunatic/default/index You'll notice that there's a horizontal scroll bar at the bottom and the overall width seems to be do ...

Problem with Background-sizing in Mobile Webkit

After applying these CSS rules, everything looks great on desktop and Firefox mobile: body{ background: url(../img/home-background.jpg) no-repeat center center fixed; -webkit-background-size: cover; background-size: cover; } However, when vie ...

What is the best way to generate a dynamic HTML table using Angular 6?

I need to display an array of 100 items in an HTML table with 10 rows and 10 columns. How can I achieve this using Angular? tableIndexTR = []; tableIndexTD = []; constructor(private data: TransferService) {} ngOnInit() { for (let _i = 1; _i <= ...

Why isn't the right-clear property functioning correctly?

My understanding of `clear: left`, `clear: right`, and `clear: both` in CSS has always been a bit fuzzy. I know that `clear: both` means it prevents floating elements from appearing on both sides, but I recently did some testing here. I expected the layout ...