<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Cool box</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p class="original">This is a cool box</p>
<p class="optimised">This is a cool box</p>
<p class="alternative">This is a cool box</p>
<p class="multiple-line-1">[aligning with padding] This shows that vertically aligning texts by using line-height doesn't work for multiple-line text!</p>
<p class="multiple-line-2">[box height undefined] This shows that vertically aligning texts by using line-height doesn't work for multiple-line text!</p>
<p class="multiple-line-3">[box height fixed] This shows that vertically aligning texts by using line-height doesn't work for multiple-line text!</p>
</body>
</html>
html {
font-family: sans-serif;
}
/* Your CSS below here */
p.original, p.multiple-line-3 {
/* Note: The assessment page told me to style given <div>,
but since there is no <div> given, I styled <p> instead. */
width: 200px;
height: 160px;
line-height: 9.1;
/* Question: I calculated the line-height
but is this the right way to vertically align the text in the box?*/
display: block;
margin: 3em auto;
/* Note: At first I couldn't remember how to centre the box horizontally... */
text-align: center;
font-size: 1.1em;
/* How I worked out font-size (as asked in assessment to comment out):
I used dev tool to see that the <html> element's font size was 16px.
In order to increase it to 17-18px; 16px * 1.1 = 17.6px */
color: rgb(251, 251, 163);
text-shadow: 2px 2px 1px black;
border-radius: 5px;
border: 1px solid rgb(33, 81, 119);
background: linear-gradient(to bottom right, transparent, rgba(0, 0, 0, 0.2) 30%), rgba(91, 168, 226,1);
box-shadow: 3px 3px 5px black, inset 2px 2px 3px rgba(255, 255, 255,0.7), inset -2px -2px 3px rgba(0, 0, 0, 0.4);
/* Note: I didn't know how to add box-shadow so I had to look up. */
}
p.optimised, p.multiple-line-2 {
width: 200px;
/* height: 160px;*/
/* Removing height makes the box's height dependent on the line height,
meaning that I don't have to calculate the line height to vertically centre the text.
The text will be vertically centred no whatever the line height will be!*/
line-height: 5;
display: block;
margin: 3em auto;
text-align: center;
font-size: 1.1em;
color: rgb(251, 251, 163);
text-shadow: 2px 2px 1px black;
border-radius: 5px;
border: 1px solid rgb(33, 81, 119);
background: linear-gradient(to bottom right, transparent, rgba(0, 0, 0, 0.2) 30%), rgba(17, 46, 119,1);
box-shadow: 3px 3px 5px black, inset 2px 2px 3px rgba(255, 255, 255,0.7), inset -2px -2px 3px rgba(0, 0, 0, 0.4);
}
p.alternative, p.multiple-line-1 {
width: 200px;
display: block;
padding: 3rem 0;
/* Adding equal padding on top and bottom of the text will also vertically centre the text in a box.
This approach will be effective also for multiple-line texts too! */
margin: 3em auto;
text-align: center;
font-size: 1.1em;
color: rgb(251, 251, 163);
text-shadow: 2px 2px 1px black;
border-radius: 5px;
border: 1px solid rgb(33, 81, 119);
background: linear-gradient(to bottom right, transparent, rgba(0, 0, 0, 0.2) 30%), rgba(17, 46, 119,1);
box-shadow: 3px 3px 5px black, inset 2px 2px 3px rgba(255, 255, 255,0.7), inset -2px -2px 3px rgba(0, 0, 0, 0.4);
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.