|
1 | 1 | # QR Code Generator _(HTML, CSS, and Js)_ <br> |
2 | 2 |  |
| 3 | +## _HTML_ |
| 4 | +```html |
| 5 | +<!DOCTYPE html> |
| 6 | +<html lang="en"> |
| 7 | + |
| 8 | +<head> |
| 9 | + <meta charset="UTF-8"> |
| 10 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 11 | + <title>Generate QR</title> |
| 12 | + <link rel="stylesheet" href="style.css"> |
| 13 | + <script src="script.js"></script> |
| 14 | +</head> |
| 15 | + |
| 16 | +<body> |
| 17 | + <div class="container"> |
| 18 | + <p>Enter your Text or URL</p> |
| 19 | + <input type="text" placeholder="Text or URL" id="userInput" /><br> |
| 20 | + <div id="qrBox"> |
| 21 | + <img id="qrImage" src="" /> |
| 22 | + </div> <!--to display the QR code --> |
| 23 | + <button class="generateBtn" id="generateBtn" onclick="generateQRCode()">Generate</button> |
| 24 | + </div> |
| 25 | +</body> |
| 26 | + |
| 27 | +</html> |
| 28 | +``` |
| 29 | +## _Javascript_ |
| 30 | +```js |
| 31 | +function generateQRCode() { |
| 32 | + let userInput = document.getElementById('userInput'); |
| 33 | + let qrBox = document.getElementById('qrBox'); |
| 34 | + let qrImage = document.getElementById('qrImage'); |
| 35 | + |
| 36 | + if(userInput.value ==""){ |
| 37 | + alert("Please enter a Text or URL"); |
| 38 | + }else{ |
| 39 | + |
| 40 | + qrImage.src = "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" + userInput.value; |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | +} |
| 45 | +``` |
| 46 | +## _CSS_ |
| 47 | +```css |
| 48 | +body { |
| 49 | + background-color: rgba(39, 105, 219, 0.693); |
| 50 | +} |
| 51 | + |
| 52 | +.container { |
| 53 | + position: absolute; |
| 54 | + top: 50%; |
| 55 | + left: 50%; |
| 56 | + transform: translate(-50%, -50%); |
| 57 | + background-color: rgba(255, 255, 255, 0.824); |
| 58 | + padding: 20px; |
| 59 | + border-radius: 20px; |
| 60 | + box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.5); |
| 61 | + text-align: center; |
| 62 | + |
| 63 | +} |
| 64 | + |
| 65 | +.container p { |
| 66 | + font-size: 20px; |
| 67 | + font-weight: bold; |
| 68 | + font-family: Georgia, 'Times New Roman', Times, serif; |
| 69 | +} |
| 70 | + |
| 71 | +.container input { |
| 72 | + padding: 5px; |
| 73 | + margin-top: 10px; |
| 74 | + margin-bottom: 10px; |
| 75 | + border-radius: 8px; |
| 76 | + border: 1px solid #000; |
| 77 | + font-size: 20px; |
| 78 | + font-family: Georgia, 'Times New Roman', Times, serif; |
| 79 | +} |
| 80 | + |
| 81 | +.container button { |
| 82 | + padding: 10px; |
| 83 | + margin-top: 10px; |
| 84 | + margin-bottom: 10px; |
| 85 | + border-radius: 8px ; |
| 86 | + border-color: transparent; |
| 87 | + /* border: 1px solid #000; */ |
| 88 | + font-size: 20px; |
| 89 | + font-family: Georgia; |
| 90 | + letter-spacing: 1px; |
| 91 | + background-color: #3e66f6ea; |
| 92 | + color: white; |
| 93 | + cursor: pointer; |
| 94 | +} |
| 95 | + |
| 96 | +.container button:hover { |
| 97 | + background-color: #1a3fc7; |
| 98 | +} |
| 99 | +body:hover{ |
| 100 | + background-color: rgb(10, 24, 66); |
| 101 | +} |
| 102 | +``` |
0 commit comments