My teacher demand to modify my CSS and HTML to support mobile view if it is necessary. I have to follow as below:
If the page is viewed on mobile:
o The viewport should be set to zoom-level 100%, and the width should be the device-width
• If the device screen size is less than 700px wide:
o The width of the page content should be 95% instead of 700px
• If the device screen size is less than 500px wide:
o The yellow circles in the page header should not appear( it is the "MERN" displayed in the right top corner)
I don't know how to code it. Thank you so much
body { font-family: "Proxima Nova", Arial, Helvetica, sans-serif; font-size: 18px; color: #222222; display: flex; justify-content: space-around; align-items: center; flex-direction: column; } header { border-bottom: 1px solid #ccc; display: flex; justify-content: space-between; align-items: center; flex-direction: row; width: 700px; height: 80px; } #coursename { font-family: Helvetica, sans-serif; font-size: 32px; font-weight: bold; color: #ee3322; } header span { display: flex; justify-content: space-around; align-items: center; flex-direction: row; } #MRN { height: 50px; display: flex; justify-content: space-around; flex-direction: row; align-items: center; } #MRN span { background-color: #ffee00; border-radius: 100%; height: 50px; width: 50px; margin: 3px; text-align: center; transform: rotate(-30deg); font-weight: bold; } #MRN div { background-color: #ffee00; border-radius: 100%; width: 50px; height: 50px; text-align: center; transform: rotate(-30deg); padding: 10px; } article { display: flex; justify-content: center; align-items: center; flex-direction: column; } #quiz-name { background-image: url(../starter_pack/images/background.jpg); background-repeat: no-repeat; background-size: cover; background-position: middle; width: 700px; height: 425px; display: flex; flex-direction: column; justify-content: center; align-items: center; } h1 { background-color: rgba(255, 255, 255, 0.9); font-family: Pangolin, "Trebuchet MS", cursive; font-size: 60px; color: black; padding: 10px; max-width: 75%; text-align: center; display: flex; justify-content: center; align-items: center; } #author { font-size: 14px; text-align: center; margin-top: 18px; } #introduction { width: 700px; } #introduction h2, #introduction p { margin: 18px 0 18px 0; } #startquiz, #tryagain { display: flex; flex-direction: column; justify-content: center; align-items: center; border: 1px solid #f1f1f1; background-color: #f1f1f1; padding: 18px; } button { border: none; color: white; background-color: #2196f3; padding: 18px; } button:hover { background-color: #0d8bf2; } #attempt-quiz, #review-quiz { width: 700px; display: flex; justify-content: center; align-items: flex-start; flex-direction: column; } #attempt-quiz p, #review-quiz p { margin: 30px 0 30px 0; } form { cursor: pointer; width: 700px; margin: 30px 0 30px 0; }.option, .review-answer { border-top: 1px solid white; border-bottom: 1px solid white; display: flex; justify-content: flex-start; align-items: center; flex-direction: row; width: auto; padding: 15px; background-color: #f1f1f1; position: relative; }.option:hover { background-color: #ddd; } label { margin-left: 15px; }.correct { position: absolute; right: 0; margin: 10px; background-color: rgba(0, 0, 0, 0.2); padding: 3px; color: white; }.incorrect { position: absolute; right: 0; margin: 10px; background-color: rgba(0, 0, 0, 0.2); padding: 3px; color: white; } #submit { display: flex; flex-direction: column; justify-content: center; align-items: center; margin-top: 18px; border: 1px solid #f1f1f1; background-color: #f1f1f1; padding: 18px; } #submit button { border: none; color: white; background-color: #4caf50; padding: 18px; } #submit button:hover { background-color: #46a049; }.hidden { display: none; } #tryagain { background-color: #f1f1f1; border: 1px solid #dcdcdc; } #tryagain h3 { font-size: 24px; font-weight: lighter; }.option { position: relative; padding: 0; }.option input[type="radio"] { position: absolute; left: 10px; top: 15px; }.option label { flex-grow: 1; padding: 15px 40px; margin: 0; }.option input[type="radio"]:checked+label { background: #ddd; }
<,DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width. initial-scale=1"> <title>HTML Quiz</title> <link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" /> <link rel="icon" type="image/png" href="images/favicon-16x16:png" sizes="16x16" /> <link href="https.//fonts.googleapis?com/css:family=Pangolin,400.700|Proxima+Nova" rel="stylesheet" type="text/css"> <link rel="stylesheet" href="style.css" /> <script src="script.js" defer="true"></script> </head> <body> <header> <p id="coursename"><strong> WPR </strong> </p> <div id="MRN"> <span>M</span> <span>E</span> <span>R</span> <span>N</span> </div> </header> <article> <section id="quiz-name"> <h1 id="hello">HTML Quiz</h1> <br> </section> <p id="author"> By Minh Duc Nguyen </p> <section id="introduction"> <h2> The Test </h2> <p>The test contains 10 questions and there is no time limit,</p> <p>The test is not official, it's just a nice way to see how much you know, or don't know. about HTML.</p> <h2>Count Your Score</h2> <p> You will get 1 point for each correct answer, At the end of the Quiz. your total score will be displayed. Maximum score is 10 points. </p> <div id="startquiz"> <h2>Start the quiz</h2> <p> Good luck!</p> <button name="button" type="button">Start the HTML quiz ❯ </button> </div> </section> <section id="attempt-quiz"> <div id="quiz"> <p><strong> Question 1 of 10</strong></p> <p>Question 1</p> <form name="ques01" id='ques01'> <div class="option"> <input type="radio" name="question1" value="option 1"> <label><div >option 1 </div></label><br> </div> <div class="option"> <input type="radio" name="question1" value="option 2"> <label>option 2</label><br> </div> <div class="option"> <input type="radio" name="question1" value="option 3"> <label>option 3</label><br> </div> <div class="option"> <input type="radio" name="question1" value="option 4"> <label>option 4</label><br> </div> </form> <p><strong> Question 2 of 10</strong></p> <p>Question 2</p> <form name="ques02" id='ques02'> <div class="option"> <input type="radio" name="question2" value="option 1"> <label><div >option 1 </div></label><br> </div> <div class="option"> <input type="radio" name="question2" value="option 2"> <label>option 2</label><br> </div> <div class="option"> <input type="radio" name="question2" value="option 3"> <label>option 3</label><br> </div> <div class="option"> <input type="radio" name="question2" value="option 4"> <label>option 4</label><br> </div> </form> <p><strong> Question 3 of 10</strong></p> <p>Question 3</p> <form name="ques03" id='ques03'> <div class="option"> <input type="radio" name="question3" value="option 1"> <label><div >option 1 </div></label><br> </div> <div class="option"> <input type="radio" name="question3" value="option 2"> <label>option 2</label><br> </div> <div class="option"> <input type="radio" name="question3" value="option 3"> <label>option 3</label><br> </div> <div class="option"> <input type="radio" name="question3" value="option 4"> <label>option 4</label><br> </div> </form> <p><strong> Question 4 of 10</strong></p> <p>Question 4</p> <form name="ques04" id='ques04'> <div class="option"> <input type="radio" name="question4" value="option 1"> <label><div >option 1 </div></label><br> </div> <div class="option"> <input type="radio" name="question4" value="option 2"> <label>option 2</label><br> </div> <div class="option"> <input type="radio" name="question4" value="option 3"> <label>option 3</label><br> </div> <div class="option"> <input type="radio" name="question4" value="option 4"> <label>option 4</label><br> </div> </form> <p><strong> Question 5 of 10</strong></p> <p>Question 5</p> <form name="ques05" id='ques05'> <div class="option"> <input type="radio" name="question5" value="option 1"> <label><div >option 1 </div></label><br> </div> <div class="option"> <input type="radio" name="question5" value="option 2"> <label>option 2</label><br> </div> <div class="option"> <input type="radio" name="question5" value="option 3"> <label>option 3</label><br> </div> <div class="option"> <input type="radio" name="question5" value="option 4"> <label>option 4</label><br> </div> </form> <p><strong> Question 6 of 10</strong></p> <p>Question 6</p> <form name="ques06" id='ques06'> <div class="option"> <input type="radio" name="question6" value="option 1"> <label><div >option 1 </div></label><br> </div> <div class="option"> <input type="radio" name="question6" value="option 2"> <label>option 2</label><br> </div> <div class="option"> <input type="radio" name="question6" value="option 3"> <label>option 3</label><br> </div> <div class="option"> <input type="radio" name="question6" value="option 4"> <label>option 4</label><br> </div> </form> <p><strong> Question 7 of 10</strong></p> <p>Question 7 </p> <form name="ques07" id='ques07'> <div class="option"> <input type="radio" name="question7" value="option 1"> <label><div >option 1 </div></label><br> </div> <div class="option"> <input type="radio" name="question7" value="option 2"> <label>option 2</label><br> </div> <div class="option"> <input type="radio" name="question7" value="option 3"> <label>option 3</label><br> </div> <div class="option"> <input type="radio" name="question7" value="option 4"> <label>option 4</label><br> </div> </form> <p><strong> Question 8 of 10</strong></p> <p>Question 8</p> <form name="ques08" id='ques08'> <div class="option"> <input type="radio" name="question8" value="option 1"> <label><div >option 1 </div></label><br> </div> <div class="option"> <input type="radio" name="question8" value="option 2"> <label>option 2</label><br> </div> <div class="option"> <input type="radio" name="question8" value="option 3"> <label>option 3</label><br> </div> <div class="option"> <input type="radio" name="question8" value="option 4"> <label>option 4</label><br> </div> </form> <p><strong> Question 9 of 10</strong></p> <p>Question 9</p> <form name="ques09" id='ques09'> <div class="option"> <input type="radio" name="question9" value="option 1"> <label><div >option 1 </div></label><br> </div> <div class="option"> <input type="radio" name="question9" value="option 2"> <label>option 2</label><br> </div> <div class="option"> <input type="radio" name="question9" value="option 3"> <label>option 3</label><br> </div> <div class="option"> <input type="radio" name="question9" value="option 4"> <label>option 4</label><br> </div> </form> <p><strong> Question 10 of 10</strong></p> <p>Question 10</p> <form name="ques10" id='ques10'> <div class="option"> <input type="radio" name="question10" value="option 1"> <label><div >option 1 </div></label><br> </div> <div class="option"> <input type="radio" name="question10" value="option 2"> <label>option 2</label><br> </div> <div class="option"> <input type="radio" name="question10" value="option 3"> <label>option 3</label><br> </div> <div class="option"> <input type="radio" name="question10" value="option 4"> <label>option 4</label><br> </div> </form> <div id="submit"> <button type="submit" value="submit" onclick="totalscore()">Submit your answer</button> </div> </form> </div> </section> </article> </body> </html>
You should use CSS media queries. These is the updated CSS file.
body {
font-family: "Proxima Nova", Arial, Helvetica, sans-serif;
font-size: 18px;
color: #222222;
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: column;
width:100%
}
header {
border-bottom: 1px solid #ccc;
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: row;
width: 700px;
height: 80px;
}
#coursename {
font-family: Helvetica, sans-serif;
font-size: 32px;
font-weight: bold;
color: #ee3322;
}
header span {
display: flex;
justify-content: space-around;
align-items: center;
flex-direction: row;
}
#MRN {
height: 50px;
display: flex;
justify-content: space-around;
flex-direction: row;
align-items: center;
}
#MRN span {
background-color: #ffee00;
border-radius: 100%;
height: 50px;
width: 50px;
margin: 3px;
text-align: center;
transform: rotate(-30deg);
font-weight: bold;
}
@media all and (max-width :500px){
#MRN span{
display:none;
}
}
#MRN div {
background-color: #ffee00;
border-radius: 100%;
width: 50px;
height: 50px;
text-align: center;
transform: rotate(-30deg);
padding: 10px;
}
article {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
#quiz-name {
background-image: url(../starter_pack/images/background.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: middle;
width: 700px;
height: 425px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
h1 {
background-color: rgba(255, 255, 255, 0.9);
font-family: Pangolin, "Trebuchet MS", cursive;
font-size: 60px;
color: black;
padding: 10px;
max-width: 75%;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
#author {
font-size: 14px;
text-align: center;
margin-top: 18px;
}
#introduction {
width: 700px;
}
#introduction h2,
#introduction p {
margin: 18px 0 18px 0;
}
#startquiz,
#tryagain {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border: 1px solid #f1f1f1;
background-color: #f1f1f1;
padding: 18px;
}
button {
border: none;
color: white;
background-color: #2196f3;
padding: 18px;
}
button:hover {
background-color: #0d8bf2;
}
#attempt-quiz,
#review-quiz {
width: 700px;
display: flex;
justify-content: center;
align-items: flex-start;
flex-direction: column;
}
#attempt-quiz p,
#review-quiz p {
margin: 30px 0 30px 0;
}
form {
cursor: pointer;
width: 700px;
margin: 30px 0 30px 0;
}
.option,
.review-answer {
border-top: 1px solid white;
border-bottom: 1px solid white;
display: flex;
justify-content: flex-start;
align-items: center;
flex-direction: row;
width: auto;
padding: 15px;
background-color: #f1f1f1;
position: relative;
}
.option:hover {
background-color: #ddd;
}
label {
margin-left: 15px;
}
.correct {
position: absolute;
right: 0;
margin: 10px;
background-color: rgba(0, 0, 0, 0.2);
padding: 3px;
color: white;
}
.incorrect {
position: absolute;
right: 0;
margin: 10px;
background-color: rgba(0, 0, 0, 0.2);
padding: 3px;
color: white;
}
#submit {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin-top: 18px;
border: 1px solid #f1f1f1;
background-color: #f1f1f1;
padding: 18px;
}
#submit button {
border: none;
color: white;
background-color: #4caf50;
padding: 18px;
}
#submit button:hover {
background-color: #46a049;
}
.hidden {
display: none;
}
#tryagain {
background-color: #f1f1f1;
border: 1px solid #dcdcdc;
}
#tryagain h3 {
font-size: 24px;
font-weight: lighter;
}
.option {
position: relative;
padding: 0;
}
.option input[type="radio"] {
position: absolute;
left: 10px;
top: 15px;
}
.option label {
flex-grow: 1;
padding: 15px 40px;
margin: 0;
}
.option input[type="radio"]:checked+label {
background: #ddd;
}
@media all and (max-width:700px){
header, form, #attempt-quiz, #review-quiz, #url, #introduction, header{
width:95% !important;
font-size:1rem;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.