Mobile & Tablet Search Icon with Dropdown Search Container

  • Posted in : Fuud
  • lucky
    Participant

    Hello Fuud Theme Support Team,

    I would like to request assistance with adding or enabling a search feature specifically for mobile and tablet devices on my website, The Isha’s Recipe.

    Currently, the desktop search functionality is working fine, and I would like to keep the desktop layout and search functionality exactly as they are.

    However, I would like to have a dedicated search icon in the top-right corner of the header, next to the logo, on mobile and tablet devices only.

    Here is exactly what I would like to achieve:

    1. Mobile & Tablet Search Icon

    Display a search (magnifying glass) icon in the top-right corner of the header.

    Position it beside the website logo, preferably on the right side.

    Make sure it is visible on both mobile phones and tablets.

    Keep the current desktop header and search layout unchanged.

    2. Search Dropdown / Expandable Container

    When a visitor clicks the search icon, a search box or dropdown container should open.

    The search box should include a text input field and a search button.

    Visitors should be able to type a recipe name, such as “Chicken Marsala”, “Blueberry Pie”, or “Lemon Cheesecake”, and submit the search.

    Pressing Enter after typing should also trigger the search.

    Ideally, the search container should close after submission or when the visitor clicks outside it.

    3. Responsive Design

    The search icon and dropdown should work smoothly on mobile phones and tablets.

    The search box should be properly positioned and should not overlap the logo, navigation menu, or other header elements.

    The design should match the existing Fuud theme styling.

    4. Desktop Compatibility

    Please do not change or remove the existing desktop search icon or search functionality.

    This new feature should be enabled only for mobile and tablet screen sizes.

    I would appreciate your guidance and the exact settings or code required to implement this functionality.

    Thank you for your support!

    Mehmet S.
    Keymaster

    Hi,

    Thank you for the detailed description.

    1) Is this already available in the theme settings?

    Not as a separate icon. On desktop the header has the search icon, but on screens narrower than 992px (phones and tablets in portrait) the theme places the search field inside the mobile menu: tap the menu icon and you will find it right below the menu links. There is no theme option to show a search icon next to the logo on small screens.

    2) How to add it

    It can be done with CSS only. No JavaScript or PHP is needed and no theme file has to be edited, because the theme’s own script already opens and closes the header search. The code below just shows the icon on small screens and turns the search form into a dropdown box.

    Go to “WP Admin > Appearance > Customize > Additional CSS”, paste the code below under your existing code and click “Publish”:

    /* Search icon + dropdown search box on mobile & tablet (screens below 992px) */
    @keyframes fuud-search-dropdown {
        from { opacity: 0; transform: translateY(-8px); }
        to { opacity: 1; transform: translateY(0); }
    }
    @media screen and (max-width: 991px) {
        /* 1. Search icon at the top right of the header */
        .site-header .search-toggle {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 50px;
            z-index: 1;
            overflow: visible;
        }
        /* close (x) icon while the search box is open */
        .is-search-toggled-on .site-header .search-toggle:before {
            content: '\e898';
        }
        /* the opened mobile menu has its own search box */
        .is-menu-toggled-on .site-header .search-toggle {
            display: none;
        }
        /* 2. Dropdown search box */
        html.is-search-toggled-on:not(.is-menu-toggled-on) .site-header .search-container {
            display: block;
            position: absolute;
            top: 100%;
            right: 0;
            z-index: 2;
            width: 100%;
            max-width: 440px;
            margin-top: 8px;
            padding: 12px;
            color: #111;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
            box-sizing: border-box;
            animation: fuud-search-dropdown 0.2s ease-out;
        }
        .site-header .search-form {
            display: flex;
            align-items: center;
        }
        .site-header .search-box label {
            flex: 1;
            min-width: 0;
        }
        .site-header .search-box label span {
            display: none;
        }
        .site-header .search-box #search-field {
            height: 46px;
            padding: 0 14px;
            font-size: 16px;
            text-align: left;
            border: 2px solid rgba(128, 128, 128, 0.3);
            border-radius: 4px;
            box-sizing: border-box;
        }
        .site-header .search-container .search-submit {
            display: inline-block !important;
            flex: none;
            height: 46px;
            line-height: 46px;
            padding: 0 18px;
            margin: 0 0 0 8px;
        }
        /* 3. Tapping anywhere outside the search box closes it */
        .is-search-toggled-on .site-header .search-toggle:after {
            content: "";
            position: fixed;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
        }
    }
    

    What you get:

    – A search icon at the top right of the header on phones and tablets.
    – Tapping it opens a dropdown box under the header with a text field and a “Search” button.
    – Pressing Enter or tapping “Search” runs the search.
    – Tapping the icon again (it turns into an X) or anywhere outside the box closes it.
    – It works in the sticky header too, and nothing overlaps the logo or the menu icon.
    – While the mobile menu is open the icon is hidden, since the menu shows the same search box itself.
    – Desktop is not affected: all of the code is inside a “max-width: 991px” rule. From 992px up (for example an iPad in landscape) your current header and search icon stay exactly as they are.

    Please keep “Appearance > Customize > Header > General > Header Search” set to “Yes”.

    3) Will it survive theme updates?

    Yes. Additional CSS is stored by WordPress in the database, not in the theme files, so theme updates do not touch it. More info: https://www.pixelwars.org/forums/topic/how-to-use-custom-css-for-wordpress-themes/

    One note: your site uses LiteSpeed Cache, so after publishing please use “Purge All” in LiteSpeed Cache and check the result in a private/incognito window.

    I tested the code against your site’s header at phone and tablet widths. Let me know if you would like any detail adjusted (colors, width of the box, etc.).

    Best regards,
    Mehmet
    Pixelwars Team

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in and have valid license to reply to this topic.

License required for the following item
Login and Registration Log in · Register