Wrong Coding

Joined
Apr 18, 2023
Messages
4
Reaction score
0
Hello. I got my coding wrong. The font for the second sentence is supposed to be smaller and in the color green. The last two sentences are supposed to be the aligned to the left and in 12pt font. What did I do wrong?

<!DOCTYPE html>
<html>
<head>
<title>The Monk Diamond</title>
<style>
.header {
background-color: lightblue;
padding: 25px;
text-align: center;
font-size: 18pt;
width: 100%;
height: 25%;
}
.title {
font-size: 14 pt;
text-align: center;
color: gray;
}
.body {
margin: 20px;
}
</style>
</head>
<body>
<div class="header">
The Monk Diamond<br/>
An incredible discovery
<div/>
<br/>
<div class="title">
Stolen diamond found on expedition in Siberia!
<div class="body">
Professor Bairstone and Dr. Day were looking for fossils in Siberia.<br/>
They found the stolen diamond hidden inside a remote cave.
</div>
</body>
</html>
 
Joined
Sep 4, 2022
Messages
158
Reaction score
16
Hello,


you ask for 'html/css' in the 'c/c++' main thread : ask admin to move your question.


you have one missing closing tag 'div' , it's Html error. with a missing tag you have structure defaults, then display css defaults too.

you use native keywords ( header / body /title ) as classes Names, choose others name or you'll be lost quickly.
 
Joined
Apr 18, 2023
Messages
4
Reaction score
0
Thanks. I corrected one error. However, the third sentence is still not in 12pt font, the second sentence is still not in 14pt font and only the first sentence should be highlighted in blue. I checked the code dozens of times.
 
Joined
Mar 30, 2023
Messages
95
Reaction score
8
Here is the fix the code

PHP:
<!DOCTYPE html>
<html>
<head>
<title>The Monk Diamond</title>
<style>
.header {
background-color: lightblue;
padding: 25px;
text-align: center;
font-size: 18pt;
width: 100%;
height: 25%;
}
.title {
font-size: 14 pt;
text-align: center;
color: gray;
}
.body {
margin: 20px;
}
</style>
</head>
<body>
<div class="header">
The Monk Diamond<br/>
An incredible discovery
</div>
<br/>
<div class="title">
Stolen diamond found on expedition in Siberia!
</div>
<div class="body">
Professor Bairstone and Dr. Day were looking for fossils in Siberia.<br/>
They found the stolen diamond hidden inside a remote cave.
</div>
</body>
</html>
 
Joined
Aug 22, 2023
Messages
62
Reaction score
17
Here is your corrected code! 😉
By the way, if you are using Young Rewired State's "Get Coding!" book, the finished product is on the back of every chapter. As FResher already said, using native (and also erroneous: .body is not the entirety of the body) keywords can complicate things! I did not fix this!
Code:
<!DOCTYPE html>
<html>
<head>
<title>The Monk Diamond</title>
<style>
.header {
background-color: lightblue;
padding: 25px;
text-align: center;
font-size: 18pt;
width: 100%;
height: 25%;
}
.title {
font-size: 14 pt;
text-align: center;
color: green;
}
.body {
margin: 20px;
float: left;
font-size: 12 pt;
}
</style>
</head>
<body>
<div class="header">
The Monk Diamond<br>
An incredible discovery
</div>
<br>
<div class="title">
Stolen diamond found on expedition in Siberia!
</div>
<div class="body">
Professor Bairstone and Dr. Day were looking for fossils in Siberia.<br/>
They found the stolen diamond hidden inside a remote cave.
</div>
</body>
</html>
 
Joined
Jul 4, 2023
Messages
589
Reaction score
78
Try to avoid <br> tags between <div> tags in your code, use margin in css for that.
The <br> tag should only be used to "break" text.
HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>The Monk Diamond</title>

    <style>
      html,
      body {
        margin: 0;
        padding: 0;
        width: 100dvw;
      }
      .header {
        background-color: lightblue;
        padding: 25px;
        text-align: center;
        font-size: 18pt;     
        margin-bottom: 18pt;  /* Instead of <br> */
      }
      .title {
        font-size: 14pt;
        text-align: center;
        color: green;
      }
      .body {
        margin: 20px;
        text-align: left;
        font-size: 12pt;
      }
    </style>
  </head>
  <body>
    <div class="header">
      The Monk Diamond<br/>
      An incredible discovery
    </div>

    <div class="title">
      Stolen diamond found on expedition in Siberia!
    </div>

    <div class="body">
      Professor Bairstone and Dr. Day were looking for fossils in Siberia.<br/>
      They found the stolen diamond hidden inside a remote cave.
    </div>
  </body>
</html>
1731722074698.png
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,261
Messages
2,571,040
Members
48,769
Latest member
Clifft

Latest Threads

Top