Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

autocomplete function an initial line when loading the page

So when I first load my index.html page, there’s a gray line, I assume it has to do with the added border to do.

/* Styles for the autocomplete dropdown */
.autocomplete-items {
    position: relative;
    max-height: 150px;
    overflow-y: auto;
    list-style-type: none; /* Remove the list icon */
    width: 200px; /* Match the width of the input field */
    border: 1px solid #ccc; /* Add a border */
    border-radius: 5px; /* Add some border radius for a rounded appearance */
    box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1); /* Add a subtle box shadow for depth */
    background-color: #fff; /* Set a background color */
}

/* Styles for each autocomplete item */
.autocomplete-item {
    padding: 5px;
    cursor: pointer;
}

/* Highlight the selected item */
.autocomplete-item:hover {
    background-color: #f2f2f2;
}

/* Highlight the selected item */
.autocomplete-item.active {
    background-color: #ccc; /* Customize the highlight color */
}

/* Styles for the input field */
input[type="text"] {
    width: 200px;
    padding: 5px;
    border: 1px solid transparent; /* Set initial border to transparent */
    transition: border 0.3s; /* Add a transition for a smooth effect */
    margin: 0; /* Reset margin to zero */
    padding: 0; /* Reset padding to zero */
}

/* Add border only when the input is focused (clicked) */
input[type="text"]:focus, input[type="text"]:not(:placeholder-shown) {
    border: 1px solid #ccc; /* Show border when focused (clicked) or not empty */
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Story Fetcher</title>
    <link rel="stylesheet" href="CSS/index.css">
    <link rel="stylesheet" href="CSS/autocomplete.css"> <!-- Include the new CSS file for autocomplete -->
    <script type="module" src="autocomplete.js"></script>
    <script src="country.js"></script> <!-- Include your country.js script here -->
</head>
<body>
    <header>
        <h1>Select a country</h1>
    </header>
    <main>
        <div id="content-wrapper">
            <div id="get-container">
                <input type="text" id="country-name" placeholder="Enter a country" autocomplete="off">
                <div id="suggestion-list" class="autocomplete-items"></div>
                
                <div id="error-message"></div>
            </div>
            <div id="story-container">
                <div id="generated-text"></div>
                <button id="clear">Clear</button>
            </div>
        </div>
    </main>
</body>
</html>

I’m not sure how to remove the line that’s initially appearing. This is the last thing I have to do for the design before I start adding in more content. So if someone could tell me how that would be great, because I’m literally clueless.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The line is caused by the border attribute on the autocomplete-items.

You could apply that border styling only if the element isn’t empty so the line will only appear if the <div> has a child element.

So when your autocomplete.js script adds an element in the autocomplete-list, the CSS rule below will aply and the border will be shown.

.autocomplete-items:not(:empty) {
   border: 1px solid #ccc; /* Add a border */
}

/* Styles for the autocomplete dropdown */
.autocomplete-items {
    position: relative;
    max-height: 150px;
    overflow-y: auto;
    list-style-type: none; /* Remove the list icon */
    width: 200px; /* Match the width of the input field */
   
    border-radius: 5px; /* Add some border radius for a rounded appearance */
    box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1); /* Add a subtle box shadow for depth */
    background-color: #fff; /* Set a background color */
}

.autocomplete-items:not(:empty) {
   border: 1px solid #ccc; /* Add a border */
 }

/* Styles for each autocomplete item */
.autocomplete-item {
    padding: 5px;
    cursor: pointer;
}

/* Highlight the selected item */
.autocomplete-item:hover {
    background-color: #f2f2f2;
}

/* Highlight the selected item */
.autocomplete-item.active {
    background-color: #ccc; /* Customize the highlight color */
}

/* Styles for the input field */
input[type="text"] {
    width: 200px;
    padding: 5px;
    border: 1px solid transparent; /* Set initial border to transparent */
    transition: border 0.3s; /* Add a transition for a smooth effect */
    margin: 0; /* Reset margin to zero */
    padding: 0; /* Reset padding to zero */
}

/* Add border only when the input is focused (clicked) */
input[type="text"]:focus, input[type="text"]:not(:placeholder-shown) {
    border: 1px solid #ccc; /* Show border when focused (clicked) or not empty */
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Story Fetcher</title>
    <link rel="stylesheet" href="CSS/index.css">
    <link rel="stylesheet" href="CSS/autocomplete.css"> <!-- Include the new CSS file for autocomplete -->
    <script type="module" src="autocomplete.js"></script>
    <script src="country.js"></script> <!-- Include your country.js script here -->
</head>
<body>
    <header>
        <h1>Select a country</h1>
    </header>
    <main>
        <div id="content-wrapper">
            <div id="get-container">
                <input type="text" id="country-name" placeholder="Enter a country" autocomplete="off">
                <div id="suggestion-list" class="autocomplete-items"></div>
                
                <div id="error-message"></div>
            </div>
            <div id="story-container">
                <div id="generated-text"></div>
                <button id="clear">Clear</button>
            </div>
        </div>
    </main>
</body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading