Inconsistent Responsiveness of CSS Search Bar

I'm currently in the process of developing a mobile-friendly GitHub Homepage Clone using HTML and CSS, with plans to integrate JS at a later stage. My main focus right now is on refining the search bar functionality. However, I've encountered an issue where, upon resizing the screen from the left side, the search bar width remains unchanged, causing it to overlap with the entire left navigation bar. Any suggestions or guidance on resolving this matter would be highly appreciated :) P.S. Kindly take a look at the complete code snippet in full-page view

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: #f6f8fa;
    font-family: Helvetica, sans-serif;
}

#left-menu {
    background-color: white;
    width: 25%;
    display: flex;
    flex-direction: column;    
}

#left-menu-items {
    margin: 40px 15px 300px 25px;
    width: 85%;
}

#left-menu input {
    background-color: transparent;
    border: solid 1px #e1e4e8;
    border-radius: 5px;
    outline: none;
    margin-bottom: 20px;
    padding: 8px 113px 8px 10px;
}

#left-menu input::placeholder {
    color: #d2d5d8;
    font-size: 15px;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://kit.fontawesome.com/735c9ee1fa.js" crossorigin="anonymous"></script>
    <link rel="stylesheet" type="text/css" href="stylesheet.css">
    <title>GitHub Homepage</title>
</head>
<body>
    <section id="left-menu">
        <div id="left-menu-items">
            <input type="search" placeholder="Find a repository...">
        </div>
    </section>
</body>
</html>

Answer №1

I have been focusing on enhancing the search bar functionality which displays the text "Locate a repository..." To ensure the flexibility of the box to expand towards the right, I have incorporated ample padding.

Hello, Joshua.

Dealing with a question containing multiple components can be quite challenging. It might be beneficial if you could provide a more concise example.

<aside class="sidebar">
  <input type="search" placeholder="Locate a repository">
</aside>

.

.sidebar {
  border: 1px solid blue;
  padding: 10px;
}

input[type='search'] {
  padding: 5px 10px;
  font-style: inherit;
}

https://jsfiddle.net/sheriffderek/smnovwqj/

After reviewing this, we will be able to assist you further. Alternatively, feel free to inquire within the CSS Discord.

HERE: maintaining the integrity of the sidebar: https://jsfiddle.net/sheriffderek/e6k8gydu/

Answer №2

It appears that you desire the search input to adjust its size based on the page dimensions.

In order to achieve this, it is recommended to utilize max-width: 300px in conjunction with flex-grow: 1 on the <input>.

The flex-grow property dictates how space should be distributed along the main axis of the flex-box (in this case, the X axis). By setting it to flex-grow: 1, the input will expand to occupy available space until it encounters a fixed width element or another element with a non-zero flex-grow value.

Meanwhile, max-width sets an upper limit for the element's size. The value can be adjusted as needed, with 300px serving as a suitable default size.

By combining these two properties, there is no longer a need for excessive padding around the input field. It will shrink when necessary and expand up to 300px in width.

Additionally, consider replacing the <p> tag next to the input with a more appropriate container like a <div>. Paragraph styling could interfere with the intended layout.

Furthermore, removing relative positioning from nav div p{} and relying on flex-box for alignment is advisable. If positioning adjustments are required, using margin is preferable over explicit positioning.

I apologize for the lack of specificity in my response, but your query is quite broad in nature.

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

Ordering columns inside columns with responsive design in Bootstrap 5

Could the layout be rearranged for md+ devices to this configuration on xs, sm devices? <head> <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="294b46465d5a5d5d5b4859691c07 ...

Is there a way to align the line under the hyperlinks to match the text size using CSS?

<div className={styles.container}> <ul className={styles.links}> <li className={styles.link}> <a href="/">Home</a> </li> <li className={styles.link}> <a href="/portfolio& ...

The issue arises when trying to use qtip2 in JavaScript upon page initialization

I successfully created a heatmap using JavaScript, utilizing a table with varying colors based on the displayed values' thresholds. To enhance user experience, I wanted to implement a popup window that shows additional information when hovering over a ...

Guide on customizing webpack to incorporate SCSS in a React application

After creating my React app using create-react-app (with React ver. 16.6.3), I decided to incorporate SCSS into my components. To begin, I ran the eject script and made necessary adjustments in webpack.config.dev.js: { test: cssRegex, exclude: cssMo ...

What is the best way to create a unique shadow effect for a container in Flutter?

I am facing a challenge with my screen layout that uses GridView.builder with crossAxisCount: 3. In the itemBuilder, I am returning a Container with shadows on the left, right, and bottom, but so far, I have not been able to achieve the desired outcome. H ...

Choosing Only the Visible Element with CSS

Within my program, there exists a text element that appears in two distinct sections: section A and section B (in the form of a popup). My intention was to create one object using CSS that could be utilized in both areas. By doing so, I would be able to em ...

Determine the total quantity of colored cells within a row of an HTML table and display the count in its own

I need assistance with a table that has 32 columns. From columns 1 to 31, I am able to fill in colors by clicking on the cells. However, I now want to calculate and display the number of cells that are not colored in the last column. This task must be co ...

Unable to make a request to the localhost node server via fetch API from an HTML page

Description: I am attempting to transmit JSON data from an HTML page to a Node.js server running locally on port 5000 using the Fetch API. Error Encountered: The request to 'http://localhost:5000/attend' from origin 'http://127.0.0.1:5501 ...

Mobile-exclusive carousel feature

I am currently working on a project where I need to create a carousel specifically designed for mobile devices. I want the carousel to display only one image at a time on screens with a resolution lower than 650px, while on larger screens, a standard grid ...

Transforming a Multi-Dimensional Array into an HTML Table

Experimenting with a new idea. I hope the solution is straightforward; I just can't seem to figure it out. Imagine I have an array like this: var items = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]; My goal is to rearrange the data so that it looks like t ...

Phonegap - Retaining text data in a checklist app beyond app shutdown

This is my first time developing an app with Phonegap. I am looking to create a checklist feature where users can input items into an input field. However, I am struggling with figuring out how to save these items so that they remain in the checklist even ...

Employ the v-model directive in conjunction with a checkbox in scenarios where v-for is implemented with the properties of an object

When utilizing v-model with a checkbox in conjunction with an array of objects, it functions correctly: new Vue({ el: '#example', data: { names: [ { name: 'jack', checked: true }, { name: 'john', checked ...

Tips for preventing the collapse of a table row using a button?

I have implemented a Bootstrap collapse feature on my table row. Currently, the collapse can be triggered by clicking anywhere on the row, which is working as intended. However, I would like to make one exception - if the user clicks on the desktop icon i ...

Is there a way to eliminate the transform style from a draggable element?

I am looking to enhance the CDK drag and drop example by adding a preview of the dragged element with specific left and top positions, without utilizing the transform style. HTML <div class="example-boundary"> <div class="example- ...

Update the jQuery Mobile components on the page by refreshing them after dynamically adding them using AJAX and PHP

I have developed a PHP script that dynamically renders three form elements for each entry in a database. The script generates HTML output similar to the following example: <!-- Entry 1 --> <div data-role="fieldcontain"> < ...

Transforming color images into black and white using JavaScript

     I have implemented this code to convert colored images to grayscale. function applyGrayscaleEffect() {         var imageData = contextSrc.getImageData(0, 0, width, height);         var data = imageData.data;         var p1 = 0.99;   ...

What are the steps to ensure that the content within the <pre><code></code></pre> tags displays correctly in Internet Explorer 7?

When using JQuery to make an AJAX pull with JSON to an ASP.net Web Service, the following code is used: $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "TestWebService.asmx/Foo", data: "{}", dataType: "json", success: function( ...

Organizing knockout data outcomes into two separate columns

Is there a way to split up this code into two columns using Knockout and HTML? I can do it easily in CSS, but the goal is to divide the results into segments 1-5 and 6-9. Here is the code snippet. Also attached is a screenshot for reference. Thank youhtt ...

Include the url of the html file in your JavaScript code

I have a piece of code that I want to include in my JavaScript instead of HTML. The code is as follows: <script async src="https://www.googletagmanager.com/gtag/js?id=ID"></script> Since all my functions are written in JavaScript, I ...

Combining multiple PNG images onto a base image in PHP

I need assistance in merging 24 images with single dashes highlighted into a base circle image using PHP GD, JS or CSS. All images are in PNG format. Your help would be greatly appreciated. ...