screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> </head> <body> <div id="app"> <div class="input-wrapper"> <h3>Vue Clear Input Field on Click</h3> <div class="input-container"> <input type="text" v-model="inputValue" @input="handleInput" /> <button v-if="inputValue" class="clear-button" @click="clearInput"> X </button> </div> </div> </div> <script> const app = Vue.createApp({ data() { return { inputValue: "", }; }, methods: { clearInput() { this.inputValue = ""; }, }, }); app.mount("#app"); </script> <style> /* Style for input wrapper */ .input-wrapper { display: flex; align-items: center; justify-content: center; margin: 0 auto; width: 300px; flex-direction: column; } /* Style for input container */ .input-container { position: relative; display: inline-block; } /* Style for input */ input[type="text"] { padding: 10px; width: 300px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; transition: border-color 0.3s ease; padding: 10px 30px 10px 10px; } input[type="text"]:focus { outline: none; border-color: dodgerblue; } /* Style for clear button */ .clear-button { position: absolute; right: 0; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border: none; background: transparent; cursor: pointer; font-size: 16px; color: #555; } .clear-button:hover { color: gray; } </style> </body> </html>