Center the input field both vertically and horizontally within an overlay

When the user clicks on the search icon, I want to display the search field as an overlay. Currently, the overlay is working but the search input field is appearing in the middle vertically.

Check out the Fiddle

<a href="#overlay" id="open-overlay">Search</a>

<div id="overlay"> <a href="#" class="close">X</a>
    <div class="s-wrapper"><input value="" placeholder="Search"/></div>
</div>

This overlay relies on a pure CSS solution since I am unable to use a script-based overlay in this scenario.

Answer №1

Try using the code below:

.s-wrapper{
    top: 50%;
    transform: translateY(-50%);
}

View the Updated Fiddle for reference.

Answer №2

Check out this link.

.s-container{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

Answer №3

One way to achieve this result is by using CSS:

.s-container{
  height: 500px;
  display: table-cell;
  width: 500px;
  vertical-align: middle;
  text-align: center;
}

For a live demonstration, you can view this Demo

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

Cease the continuous reloading of a particular div while navigating

Currently, I am designing my personal website and have integrated a music player. However, a major issue that I am encountering is that whenever I navigate to another page, the music stops playing and restarts from the beginning. This interruption is quite ...

Failure of Styling Inheritance in Angular 2 Child Components from Parent Components

My Parent Component utilizes a Child Component. I have defined the necessary styles in the Parent CSS file, and these styles change appropriately when hovering over the div. However, the Child Component does not inherit the styling classes of the Parent Co ...

Acquiring the value of an input box in VBA through HTML

Can someone provide guidance on how to retrieve the value from an input box on an Internet Explorer page using VBA? I have tried various solutions but none seem to work. Below is the HTML code I am working with. I specifically need the value of the bolded ...

Extremely efficient CSS utility classes for supreme performance

I've noticed the rise of CSS utility classes and I'm curious about their impact on performance. Is there a better approach? Option One - creating HTML elements with multiple utility classes like: <div class="padding flex justifyCenter align ...

Unable to apply styling to body element in style.css file when using Node.js

I recently launched a basic Node.js website but encountered an unusual issue. When trying to style the body using the default style.css stylesheet provided by Express, I found that it was not recognizing it. The only workaround was to add the class body di ...

Selecting Messages in a Scala Play Application

After running the sample code in play 2.2 "comuputer-database-jpa", I came across a specific part in the Conf/Messages file: # Messages computers.list.title={0,choice,0#No computers|1#One computer|1<{0,number,integer} computers} found I found this co ...

The pair of divs with distinct backgrounds

Looking to customize the navigation on my website by creating a separate background for the list links menu and making sure the left part of the navigation with the logo has its own distinct background that extends until the next div. I've experimente ...

What is the best way to disable the button hover effect after it has been clicked?

Many posts I've come across have similar issues to mine, but the suggested solutions are not working for me. I am struggling to remove the hover property of my button when it is clicked before triggering the removal event I have set up. Edit: Just t ...

Having trouble accessing the ID of a list item using jQuery?

Can you please help me figure out why the code below is not passing the list element ID to ajax correctly: Here's the HTML: <ul id="tree"> <li><a id="1">Finance</a></li> <li><a id="2">ACC& ...

Enhancing URLs with jQuery/AJAX: A Comprehensive Guide to Adding Parameters

Whenever I try to use the get method on an HTML form, the submitted data automatically appears in the URL. You can see what I mean here. Interestingly, when attempting to achieve the same result with JQuery and AJAX using the get method, the data doesn&apo ...

Is there a way I can link a variable to a URL for an image?

Creating v-chip objects with dynamic variable names and images is causing an issue. The image source string depends on the name provided, but when I bind the name to the source string, the image fails to load. Despite trying solutions from a similar questi ...

Issue with exporting data from Datatables

I followed the instructions, and the Datatables export function worked perfectly in localhost, but when I tried it in Google Apps script, it didn't work. For more information about the issue, you can visit this link: DataTables TableTools buttons not ...

When hovering over the main menu, the submenu appears hidden behind it

I am struggling with setting up a dropdown submenu on my website that uses a responsive Joomla template. The submenu always appears behind the main menu and slider, despite trying z-index and relative positioning. Can anyone help me figure out what I' ...

Generate a new array using a single value extracted from an existing array

I'm new to working with arrays. Before this, I used to manually code everything in HTML. My question is, can you create an array based on the values of another array? var pmmain =["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", ...

Why is there a thin line still visible on the other sides when a transparent background is used, but only on mobile devices, with a curved border on one side?

Recently, I've delved into the world of creating CSS art and stumbled upon a peculiar issue with CSS borders that has left me puzzled. When I apply a border to only one side of an element with a transparent background and rounded edges, I notice a fa ...

Overcoming Challenges with Ajax Success in Bootstrap DataTable Modal

Recently, I created a webpage featuring a top fixed navbar and a CRUD datatable with pagination supported by buttons that trigger modals. However, I'm encountering an issue where upon clicking the delete button in the modal to remove a record, the mod ...

Scraping Secrets: Unraveling the Art of Procuring User Links

I need assistance with extracting links from the group members' page on Meetup: response.css('.text--ellipsisOneLine::attr(href)').getall() Can you please help me understand why this code is not functioning correctly? This is the HTML stru ...

Adaptive design exhibits varying appearances across various screen sizes

Currently, I am working on a responsive design WordPress site and here is the markup: <div class="contact-wrap"> <div class="contact-number">123-456-7890</div><!--.contact-number--> <div class="user-login"><a href="#"& ...

Can a dynamic react component be inserted into a standalone HTML document without the need for file downloads or server support?

I am implementing React for a Single Page Application (SPA) project where users can customize a component's font size, color, etc., and then embed this customized component into their website. I'm looking for a way to bundle the component and pre ...

Can you explain the mechanics behind Angular Component CSS encapsulation?

Is it possible to avoid CSS conflicts when using multiple style sheets? Consider Style 1: .heading { color: green; } And Style 2: .heading { color: blue; } If these two styles are applied in different views and rendered on a layout as a Partial Vi ...