Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-mini-2024-07-18· OpenAIHugging Face LMArena Human Preference 140K

In a single html file give me a component with custom context menu dropdown. I want it…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Googlegemma-3-27b-it’s answer.
  1. User

    In a single html file give me a component with custom context menu dropdown. I want it to be beautiful and modern, with an icon on the most left leading with the label text and the shortcut on the most right.

  2. Assistant

    Certainly! Below is a simple HTML file that includes a custom context menu dropdown. The menu is styled to look modern and beautiful, featuring an icon on the left, label text in the center, and a shortcut on the right. You can customize the icon, labels, and shortcuts as needed.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Custom Context Menu</title>
        <style>
            body {
                font-family: Arial, sans-serif;
                margin: 0;
                padding: 20px;
                background-color: #f4f4f4;
                height: 100vh;
                display: flex;
                justify-content: center;
                align-items: center;
            }
    
            .context-menu {
                display: none;
                position: absolute;
                background-color: white;
                border: 1px solid #ccc;
                border-radius: 5px;
                box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
                z-index: 1000;
                width: 200px;
            }
    
            .context-menu-item {
                display: flex;
                align-items: center;
                padding: 10px 15px;
                cursor: pointer;
                transition: background-color 0.2s;
            }
    
            .context-menu-item:hover {
                background-color: #f0f0f0;
            }
    
            .context-menu-item img {
                width: 20px;
                height: 20px;
                margin-right: 10px;
            }
    
            .shortcut {
                margin-left: auto;
                color: #888;
                font-size: 0.9em;
            }
        </style>
    </head>
    <body>
    
    <div id="target" style="width: 300px; height: 300px; background-color: #fff; border: 1px solid #ccc; display: flex; justify-content: center; align-items: center;">
        Right-click here for options
    </div>
    
    <div class="context-menu" id="contextMenu">
        <div class="context-menu-item" onclick="alert('Option 1 selected')">
            <img src="https://via.placeholder.com/20" alt="Icon 1">
            <span>Option 1</span>
            <span class="shortcut">Ctrl + O</span>
        </div>
        <div class="context-menu-item" onclick="alert('Option 2 selected')">
            <img src="https://via.placeholder.com/20" alt="Icon 2">
            <span>Option 2</span>
            <span class="shortcut">Ctrl + N</span>
        </div>
        <div class="context-menu-item" onclick="alert('Option 3 selected')">
            <img src="https://via.placeholder.com/20" alt="Icon 3">
            <span>Option 3</span>
            <span class="shortcut">Ctrl + S</span>
        </div>
    </div>
    
    <script>
        const target = document.getElementById('target');
        const contextMenu = document.getElementById('contextMenu');
    
        target.addEventListener('contextmenu', function(e) {
            e.preventDefault();
            contextMenu.style.display = 'block';
            contextMenu.style.left = `${e.pageX}px`;
            contextMenu.style.top = `${e.pageY}px`;
        });
    
        window.addEventListener('click', function() {
            contextMenu.style.display = 'none';
        });
    </script>
    
    </body>
    </html>
    

    Explanation:

    • HTML Structure: The context menu is created as a div with class context-menu, containing several context-menu-item divs for each menu option.
    • Styling: The CSS styles give the menu a modern look with hover effects and a clean layout.
    • JavaScript: The script handles the right-click event to show the context menu at the cursor's position and hides it when clicking elsewhere.

    Customization:

    • Replace the placeholder image URLs with your own icons.
    • Change the option labels and shortcuts as needed.
    • Adjust the styles in the CSS section to fit your design preferences.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.