-
Notifications
You must be signed in to change notification settings - Fork 38
Asaf Axelrod HTML CSS Practice #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2b7ce12
a772b66
a190c0d
bb179c6
aeeb001
ef527ef
c8917b6
e61c77a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,52 +1,61 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- displays site properly based on user's device --> | ||
|
|
||
| <link rel="icon" type="image/png" sizes="32x32" href="./assets/images/favicon-32x32.png"> | ||
|
|
||
| <title>Frontend Mentor | Newsletter sign-up form with success message</title> | ||
|
|
||
| <!-- Feel free to remove these styles or customise in your own stylesheet 👍 --> | ||
| <style> | ||
| .attribution { font-size: 11px; text-align: center; } | ||
| .attribution a { color: hsl(228, 45%, 44%); } | ||
| </style> | ||
| </head> | ||
| <body> | ||
|
|
||
| <!-- Sign-up form start --> | ||
|
|
||
| Stay updated! | ||
|
|
||
| Join 60,000+ product managers receiving monthly updates on: | ||
|
|
||
| Product discovery and building what matters | ||
| Measuring to ensure updates are a success | ||
| And much more! | ||
|
|
||
| Email address | ||
| email@company.com | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <link rel="stylesheet" href="./styles/style.css" /> | ||
|
|
||
| Subscribe to monthly newsletter | ||
| <link rel="icon" type="image/png" sizes="32x32" href="./assets/images/favicon-32x32.png" /> | ||
|
|
||
| <!-- Sign-up form end --> | ||
| <title>Newsletter sign-up</title> | ||
| <script src="./script.js" defer></script> | ||
| </head> | ||
|
|
||
| <!-- Success message start --> | ||
| <body> | ||
| <div class="form-container"> | ||
| <div class="form-column" id="form-text"> | ||
| <h1 id="heading">Stay updated!</h1> | ||
|
|
||
| <p id="subheading"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, use a class |
||
| Join 60,000+ product managers receiving monthly updates on: | ||
| </p> | ||
| <ul> | ||
| <li>Product discovery and building what matters</li> | ||
| <li>Measuring to ensure updates are a success</li> | ||
| <li>And much more!</li> | ||
| </ul> | ||
|
|
||
| <label for="email" class="form-label">Email address</label> | ||
| <input type="email" id="email" name="email" placeholder="email@email.com" required /> | ||
|
|
||
| <button type="button" id="submit-button"> | ||
| Subscribe to monthly newsletter | ||
| </button> | ||
| </div> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. General note for "form-column" div: wrap the inner elements in individual divs for clearer structure and more consistent layout behavior |
||
|
|
||
| <div class="form-column"> | ||
| <div id="desktop-image"> | ||
| <img src="./assets/images/illustration-sign-up-desktop.svg" alt="Sign up illustration" /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| Thanks for subscribing! | ||
| <div id="success-card" class="hidden"> | ||
| <div class="success-content"> | ||
| <img src="./assets/images/icon-success.svg" alt="Success" id="success-icon" /> | ||
|
|
||
| A confirmation email has been sent to ash@loremcompany.com. | ||
| Please open it and click the button inside to confirm your subscription. | ||
| <h1>Thanks for subscribing!</h1> | ||
|
|
||
| Dismiss message | ||
| <p> | ||
| A confirmation email has been sent to | ||
| <strong id="user-email"></strong>. Please open it and click the button | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use when the text has importance, urgency, or semantic emphasis |
||
| inside to confirm your subscription. | ||
| </p> | ||
|
|
||
| <!-- Success message end --> | ||
|
|
||
| <div class="attribution"> | ||
| Challenge by <a href="https://www.frontendmentor.io?ref=challenge" target="_blank">Frontend Mentor</a>. | ||
| Coded by <a href="#">Your Name Here</a>. | ||
| <button type="button" id="dismiss-button">Dismiss message</button> | ||
| </div> | ||
| </div> | ||
| </body> | ||
|
|
||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| document.addEventListener("DOMContentLoaded", () => { | ||
| const formContainer = document.querySelector(".form-container"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of const. It’s a good idea to review why we use const/let instead of var in js |
||
| const successCard = document.getElementById("success-card"); | ||
|
|
||
| const emailInput = document.getElementById("email"); | ||
| const submitBtn = document.getElementById("submit-button"); | ||
| const dismissBtn = document.getElementById("dismiss-button"); | ||
| const userEmailSpot = document.getElementById("user-email"); | ||
|
|
||
| function isValidEmail(email) { | ||
| // simple email check – good enough for this challenge | ||
| return /\S+@\S+\.\S+/.test(email); | ||
| } | ||
|
|
||
| submitBtn.addEventListener("click", () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a lambda function, worth reading up on how and when to use them |
||
| const email = emailInput.value.trim(); | ||
|
|
||
| if (!isValidEmail(email)) { | ||
| emailInput.style.borderColor = "red"; | ||
| return; | ||
| } | ||
|
|
||
| emailInput.style.borderColor = ""; // reset if previously red | ||
|
|
||
| // Insert email into success message | ||
| userEmailSpot.textContent = email; | ||
|
|
||
| // Hide form & show success | ||
| formContainer.classList.add("hidden"); | ||
| successCard.classList.remove("hidden"); | ||
| }); | ||
|
|
||
| dismissBtn.addEventListener("click", () => { | ||
| successCard.classList.add("hidden"); | ||
| formContainer.classList.remove("hidden"); | ||
|
|
||
| // reset form input | ||
| emailInput.value = ""; | ||
| emailInput.style.borderColor = ""; | ||
| }); | ||
| }); | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| /* | ||
| - Mobile: 375px | ||
| - Desktop: 1440px | ||
| */ | ||
|
|
||
| :root { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of CSS variables, they help keep the styling consistent, maintainable, and easier to update |
||
| font-family: "Roboto", sans-serif; | ||
| font-size: 16px; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using responsive units instead of px where possible. rem, em, or viewport units often give you more flexibility - read about it |
||
| --originalBlue800: hsl(234, 29%, 20%); | ||
| --originalBlue700: hsl(235, 18%, 26%); | ||
| --originalGrey: hsl(0, 0%, 58%); | ||
| --originalWhite: hsl(0, 0%, 100%); | ||
| --primaryRed: hsl(4, 100%, 67%); | ||
| } | ||
|
|
||
| *, | ||
| *::before, | ||
| *::after { | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| body { | ||
| margin: 0; | ||
| background-color: var(--originalBlue800); | ||
| width: 100vw; | ||
| height: 100vh; | ||
| overflow: hidden; | ||
| color: var(--originalBlue800); | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| flex-direction: column; | ||
| } | ||
|
|
||
| .form-container { | ||
| background-color: var(--originalWhite); | ||
| width: 65%; | ||
| max-width: 900px; | ||
| border-radius: 25px; | ||
| display: flex; | ||
| flex-direction: row; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| .form-column { | ||
| flex: 1 1 0; | ||
| min-width: 0; | ||
|
|
||
| height: 100%; | ||
| padding: 2rem 1.5rem; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice usage of rem |
||
|
|
||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| #form-text { | ||
| width: 100%; | ||
| margin-left: 1.3rem; | ||
| } | ||
|
|
||
| #form-text h1 { | ||
| font-size: 2.5rem; | ||
| line-height: 1.1; | ||
| margin-bottom: 1rem; | ||
| color: var(--originalBlue800); | ||
| } | ||
|
|
||
| #form-text>p { | ||
| font-size: 0.95rem; | ||
| color: var(--originalBlue700); | ||
| } | ||
|
|
||
| #form-text ul { | ||
| list-style: none; | ||
| padding-left: 0; | ||
| margin-bottom: 2rem; | ||
| } | ||
|
|
||
| #form-text ul li { | ||
| background-image: url("/newsletter-sign-up-with-success-message-main/assets/images/icon-list.svg"); | ||
| background-repeat: no-repeat; | ||
| background-position: 0 0.25rem; | ||
| background-size: 18px 18px; | ||
|
|
||
| padding-left: 1.6rem; | ||
| margin-bottom: 0.75rem; | ||
|
|
||
| font-size: 0.95rem; | ||
| line-height: 1.75; | ||
| color: var(--originalBlue800); | ||
| } | ||
|
|
||
| #form-text label { | ||
| display: block; | ||
| font-size: 0.75rem; | ||
| font-weight: 700; | ||
| margin-bottom: 0.4rem; | ||
| color: var(--originalBlue800); | ||
| } | ||
|
|
||
| #form-text input[type="email"] { | ||
| width: 100%; | ||
| padding: 0.9rem 1rem; | ||
| border-radius: 8px; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why sometimes rem and sometimes px? be consistant |
||
| border: 1px solid hsl(231, 7%, 85%); | ||
| font-size: 0.9rem; | ||
| color: var(--originalBlue800); | ||
| margin-bottom: 1rem; | ||
| } | ||
|
|
||
| #form-text input[type="email"]::placeholder { | ||
| color: var(--originalGrey); | ||
| } | ||
|
|
||
| #form-text input[type="email"]:focus { | ||
| outline: none; | ||
| border-color: var(--originalBlue800); | ||
| } | ||
|
|
||
| button { | ||
| width: 100%; | ||
| padding: 0.9rem 1rem; | ||
| background: var(--originalBlue800); | ||
| color: var(--originalWhite); | ||
| border: none; | ||
| border-radius: 8px; | ||
| font: inherit; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| button:hover { | ||
| background: linear-gradient(to right, #ff5379, #fe693e); | ||
| box-shadow: inset 0 0 5px rgba(255, 255, 255, 0.3); | ||
| } | ||
|
|
||
| #desktop-image { | ||
| width: 100%; | ||
| height: 100%; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| overflow: hidden; | ||
| } | ||
|
|
||
| #desktop-image img { | ||
| max-width: 100%; | ||
| object-fit: contain; | ||
| display: block; | ||
| } | ||
|
|
||
| .hidden { | ||
| display: none; | ||
| } | ||
|
|
||
| #success-card.hidden { | ||
| display: none; | ||
| } | ||
|
|
||
| #success-card { | ||
| background: var(--originalWhite); | ||
| width: 420px; | ||
| padding: 2.5rem; | ||
| border-radius: 25px; | ||
| box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15); | ||
|
|
||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .success-content h1 { | ||
| color: var(--originalBlue800); | ||
| margin: 1.5rem 0 1rem; | ||
| font-size: 2rem; | ||
| } | ||
|
|
||
| .success-content p { | ||
| font-size: 0.95rem; | ||
| line-height: 1.4; | ||
| color: var(--originalBlue700); | ||
| margin-bottom: 1.5rem; | ||
| } | ||
|
|
||
| #success-icon { | ||
| width: 48px; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s generally better practice to apply styles using classes rather than relying solely on IDs. Classes are reusable, make the CSS more scalable, and avoid overly specific selectors