I am currently in the process of designing a webpage, and I've encountered three distinct issues - two are related to pure .css, while one is related to less.
Firstly, I have set margin: auto
and padding: auto
on the body tag, but it's not centering as expected (see code snippet below). Secondly, I'm struggling with aligning a h1 tag vertically in the middle using css.
The main issue, however, is handling multiple divs each with a unique background color and shared properties. Is there a way to pass the background color name from the HTML when using handlebars as a templating engine?
Each div has a class of .item, and I would like to specify the color in the HTML code. My current CSS code looks something like this:
CSS:
html {
font-size: 12px;
font-family: Arial, sans-serif;
}
body {
margin: auto;
padding: auto; /* Why isn't the page centered? */
}
h1 {
background-color: red;
text-align: center;
height: 50px;
vertical-align: /* How can I vertically center it? */
}
.flex {
display: flex;
}
/* How can I avoid repetitive color styling for .item classes by passing variables from HTML to my mixin? */
.item(@fontColor) {
.item {
width: 30%;
h3 {
color: grey;
}
span {
font-style: italic;
}
}
}
This is what my HTML code looks like:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet/less" href="style.less" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/less.js/2.6.1/less.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>Hello Plunker!</h1>
<div class="flex">
<div class="item red">
<h3>Project 1</h3>
<span>Time: 10:30AM</span>
</div>
<div class="item green">
<h3>Project 2</h3>
<span>Time: 10:30AM</span>
</div>
<div class="item blue">
<h3>Project 3</h3>
<span>Time: 10:30AM</span>
</div>
<div class="item yellow">
<h3>Project 4</h3>
<span>Time: 10:30AM</span>
</div>
<div class="item navy">
<h3>Project 5</h3>
<span>Time: 10:30AM</span>
</div>
</div>
</body>
</html>
A live example of my code can be found here: https://plnkr.co/edit/ROp2tLBKeSNYJVBCYwUL?p=preview
Thank you for assisting me with these queries.