CSS Grid - Align-self just above the center - html

I have the following HTML code
<header>
<nav>
<ul>
<li>Childhood</li>
<li>Early years</li>
<li>End</li>
<li>About this</li>
</ul>
</nav>
<div id="header-content">
<div id="info-title">
<h1 id="title">Henry Charles Bukowski Jr.</h1>
<h2>"Find what you love and let it kill you."</h2>
</div>
<figure>
<img src="images/charles-img1-2x.png" alt="Charles Bukowski's picture">
</figure>
</div>
<div id="tribute-info">
<p>8/16/1920</p>
<p>3/09/1994</p>
</div>
<span class="next">next section</span>
</header>
Which presents this page with the CSS:
https://prnt.sc/qx4qim
CSS:
/* Montserrat font import */
#import url('https://fonts.googleapis.com/css?family=Montserrat:100,300,400,600,700&display=swap');
* {
margin: 0;
padding: 0;
}
body {
background-color: #2F2E2E;
}
#main {
font-family: 'Montserrat', sans-serif;
color: #E0E1DD;
}
header,
section {
padding: 40px 60px;
height: calc(100vh - 80px);
}
#childhood,
#end {
background: #31303B;
}
ul {
list-style: none;
}
/* text style */
h1 {
font-weight: bold;
font-size: 80px;
}
h2 {
font-weight: 100;
font-size: 60px;
}
h3 {
font-weight: 600;
font-size: 60px
}
h4 {
font-weight: 600;
font-size: 50px;
}
p {
font-weight: 400;
font-size: 45px;
}
/* text style end */
/* nav link */
nav ul {
display: flex;
justify-content: space-between;
font-weight: 300;
font-size: 50px;
}
nav ul li a {
text-decoration: none;
color: #E0E1DD;
transition: .3s color;
}
nav ul li a:hover {
color: rgb(138, 128, 128);
}
/* nav links end */
#header-content {
display: flex;
}
#info-title{
align-self: center;
}
header figure img {
height: auto;
max-height: 850px;
max-width: 630px;
}
I align the texts on the page with the align-self: center property; but if I want to upload these texts a bit to look like this: https://prnt.sc/qx4qol
Is there a property that allows me to enter numeric values for vertical alignment?
The top property does not work since the display is set to flex

I think if you move:
<div id="tribute-info">
<p>8/16/1920</p>
<p>3/09/1994</p>
</div>
into the header-content element then modify the css to this, should do the trick:
.header { position: relative; }
.tribute-info { position: absolute; bottom: 15px; left: 15px; }

add display: flex; and flex-direction: column; to header
add margin: auto 0; to #header-content
/* Montserrat font import */
#import url('https://fonts.googleapis.com/css?family=Montserrat:100,300,400,600,700&display=swap');
* {
margin: 0;
padding: 0;
}
body {
background-color: #2F2E2E;
}
#main {
font-family: 'Montserrat', sans-serif;
color: #E0E1DD;
}
header,
section {
padding: 40px 60px;
height: calc(100vh - 80px);
}
#childhood,
#end {
background: #31303B;
}
ul {
list-style: none;
}
/* text style */
h1 {
font-weight: bold;
font-size: 80px;
}
h2 {
font-weight: 100;
font-size: 60px;
}
h3 {
font-weight: 600;
font-size: 60px
}
h4 {
font-weight: 600;
font-size: 50px;
}
p {
font-weight: 400;
font-size: 45px;
}
/* text style end */
/* nav link */
nav ul {
display: flex;
justify-content: space-between;
font-weight: 300;
font-size: 50px;
}
nav ul li a {
text-decoration: none;
color: #E0E1DD;
transition: .3s color;
}
nav ul li a:hover {
color: rgb(138, 128, 128);
}
/* nav links end */
#header-content {
display: flex;
margin: auto 0; /*add this*/
}
#info-title{
align-self: center;
}
header figure img {
height: auto;
max-height: 850px;
max-width: 630px;
}
/* add flex*/
header {
display: flex;
flex-direction: column;
}
<header>
<nav>
<ul>
<li>Childhood</li>
<li>Early years</li>
<li>End</li>
<li>About this</li>
</ul>
</nav>
<div id="header-content">
<div id="info-title">
<h1 id="title">Henry Charles Bukowski Jr.</h1>
<h2>"Find what you love and let it kill you."</h2>
</div>
<figure>
<img src="images/charles-img1-2x.png" alt="Charles Bukowski's picture">
</figure>
</div>
<div id="tribute-info">
<p>8/16/1920</p>
<p>3/09/1994</p>
</div>
<span class="next">next section</span>
</header>

Related

Why is the content rendered under the navigation menu?

There is a navigation menu that I developed in <header>. However, the <p> element I use after the <header> element and the <header> components overlap. Why does this issue occur and how do I fix this issue?
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: cabin, sans-serif;
}
header {
display: block;
}
.primary {
color: blue;
font-weight: bold;
}
.navbar {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
height: 70px;
position: fixed;
top:0px;
padding: 0 30px;
background: transparent;
}
.navbar ul {
display: flex;
}
.navbar li {
list-style: none;
}
.navbar a {
text-decoration: none;
margin: 0 5px;
padding: 10px 20px;
font-weight: bolder;
}
.navbar a:hover{
border-bottom: 2px blue solid;
}
.navbar a:visited{
color: blue;
}
<body>
<!-- Navigation Menu -->
<header>
<div class="navbar">
<h1 class="logo"><span class="primary">benj</span>.codes</h1>
<ul>
<li>Home</li>
<li>About</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</div>
</header>
<!-- Content -->
<p>test</p>
</body>
This issue occurs in the .navbar class style position: fixed; caused by its use. In this case, the navigation menu remains fixed when the scrollbar is opened. So you can enclose other elements after the <header> element in a <div> element; apply a margin-top style to this element and you will see all other content scroll.
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: cabin, sans-serif;
}
header {
display: block;
}
.primary {
color: blue;
font-weight: bold;
}
.navbar {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
height: 70px;
/* This style applied causes the <p> element to render above. */
position: fixed;
top:0px;
padding: 0 30px;
background: yellow;
}
.navbar ul {
display: flex;
}
.navbar li {
list-style: none;
}
.navbar a {
text-decoration: none;
margin: 0 5px;
padding: 10px 20px;
font-weight: bolder;
}
.navbar a:hover{
border-bottom: 2px blue solid;
}
.navbar a:visited{
color: blue;
}
/* The following style has been applied to the <div> element that encloses other elements. */
.container {
margin-top: 70px; /* To avoid shifting caused by the "position: fixed" class style */
height: 1500px; /* To make the scrollbar pop up */
}
p {
height: 200px;
border: 1px solid red;
background-color: lightgray;
}
<body>
<header>
<div class="navbar">
<h1 class="logo"><span class="primary">benj</span>.codes</h1>
<ul>
<li>Home</li>
<li>About</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</div>
</header>
<div class="container">
<p>Content</p>
</div>
</body>

Cannot scroll to rest of the content (CSS)

I have a header in the beginning of my webpage with a background image covering 100% of the width and 100vh. I want to add a different section in my page for the story section which is one of my nav
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,body {
font-family: 'Lato','sans-serif','arial';
color: #fff;
font-size: 15px;
font-weight: 300;
text-transform: uppercase;
text-rendering: optimizeLegibility;
}
.wrapper {
width: 100%;
height: 100vh;
padding: 0;
}
.flex {
display: flex;
justify-content: space-between;
background-image: linear-gradient(rgba(0,0,0,0.6),rgba(0,0,0,0.6)),url("img/truck.jpg");
background-size: cover;
background-position: center;
height: 100vh;
}
.flex-item {
padding-top: 15px;
}
.item1 {
padding-top: 0;
padding-left: 30px;
}
.logo {
height: 90px;
}
.main-nav ul {
display: flex;
margin: 0;
padding: 0;
list-style: none;
}
.main-nav a {
color: white;
padding: 1rem;
text-decoration: none;
}
.main-nav a:hover {
color:orange;
}
.hero {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.hero a {
text-decoration: none;
color: white;
display: block;
margin: 10px;
}
.btn {
background-color: orange;
border-radius: 50px;
}
/*---------------------------------*/
/*Story Section*/
/*---------------------------------*/
section .flex2 {
display: flex;
flex-direction: column;
color: black;
height: 100vh;
}
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="Resources/css/styles.css">
</head>
<body class="wrapper">
<header class="flex">
<div class="flex-item item1">
<img src="Resources/img/moBurgerzLogo.png" class="logo">
</div>
<nav class="flex-item main-nav">
<ul>
<li>Our Story</li>
<li>Locations</li>
<li>Menu</li>
<li>Order now</li>
</ul>
</nav>
<div class="hero">
<h2>Best Burgers <br> In DA City(D.C)</h2>
<a href="#" class="btn" btn-full>Order now!</a>
<a href="#" class="btn" btn-ghost>View Menu!</a>
</div>
</header>
<section class="flex-2">
<div class="flex-item-2">
<h2>Established in 2017 in D.M.V</h2>
<p class="story"> founded in 2017 by owner Med.<br> Since then we have been serving the best hand crafted burgers in the D.M.V.<br>All our meat is halal and all of our ingridients are organic.</p>
</div>
</section>
</body>
</html>
elements. However I can not scroll to view the content in the story section consisting of an h2 element and paragraph tag inside a flex container.
html,
body {
font-family: "Lato", "sans-serif", "arial";
color: #fff;
font-size: 15px;
font-weight: 300;
text-transform: uppercase;
text-rendering: optimizeLegibility;
}
I think because your font color is white

HTML content filling page, but able to scroll past to other content

I am trying to make it so that on the homepage of my site, when I load into the site, you can only see the nav, title, image and some text underneath, the red div elements should not be shown, and you would have to scroll down to see it. How do I do this while still making the page responsive?
h2 {
font-family: 'Raleway', sans-serif;
font-weight: 400;
}
h3 {
font-family: 'Raleway', sans-serif;
font-weight: 300;
}
p {
font-family: 'Raleway', sans-serif;
font-weight: 200;
}
body {}
img {
height: 10%;
width: 50%;
display: block;
margin-left: auto;
margin-right: auto;
}
ul {
list-style-type: none;
margin: 10px;
padding: 0px;
overflow: hidden;
}
li {
float: left;
padding: 1%;
font-family: 'Raleway', sans-serif;
}
li a {
text-decoration: none;
color: black;
}
li a.active {
text-decoration: underline;
}
.nav {
position: -webkit-sticky;
position: sticky;
top: 0;
background-color: white;
}
/*text that needs to stay on home page under image*/
.text {
text-align: center;
}
/*what needs to be hidden*/
.container1 {
padding: 40px;
background-color: red;
text-align: center;
}
/*Area with title and image*/
.header {
padding: 30px;
font-size: 40px;
text-align: center;
grid-area: banner;
width: 100%;
color: black;
}
#media screen and (max-width: 800px) {
.leftcolumn,
.rightcolumn {
width: 100%;
padding: 0;
}
}
<link href="https://fonts.googleapis.com/css?family=Raleway:200,400" rel="stylesheet">
<div class="nav">
<ul>
<li>Learning Journal</li>
<li>Tutorial</li>
<li>Contact Me</li>
</ul>
</div>
<div class="header">
<h2> CI435 - INTRODUCTION TO WEB DEVELEPMONT</h2>
<img src="images/htmlcode.jpg" alt="">
</div>
<div class="text">
<h2>PLACEHOLDER</h2>
</div>
<div class="container1">
<h3>Weeek x</h3>
<p> PLACEHOLDER</p>
</div>
<div class="container1">
<h3>Weeek x</h3>
<p> PLACEHOLDER</p>
</div>
<div class="container1">
<h3>Weeek x</h3>
<p> PLACEHOLDER</p>
</div>
You're looking for height: 100vh (the viewport unit).
You'll also need to wrap your .header and .text placeholder into a parent element so you can control the height. I've wrapped it into the <main class="full-height" element and styled the class .full-height { height: 100vh; }
Now the user is forced to scroll to the red no matter how big/small there device is.
h2 {
font-family: 'Raleway', sans-serif;
font-weight: 400;
}
h3 {
font-family: 'Raleway', sans-serif;
font-weight: 300;
}
p {
font-family: 'Raleway', sans-serif;
font-weight: 200;
}
body {}
img {
height: 10%;
width: 50%;
display: block;
margin-left: auto;
margin-right: auto;
}
ul {
list-style-type: none;
margin: 10px;
padding: 0px;
overflow: hidden;
}
li {
float: left;
padding: 1%;
font-family: 'Raleway', sans-serif;
}
li a {
text-decoration: none;
color: black;
}
li a.active {
text-decoration: underline;
}
.nav {
position: -webkit-sticky;
position: sticky;
top: 0;
background-color: white;
}
.text {
text-align: center;
}
.container1 {
padding: 40px;
background-color: brown;
text-align: center;
}
.header {
padding: 30px;
font-size: 40px;
text-align: center;
grid-area: banner;
width: 100%;
color: black;
}
.full-height { height: 100vh; }
#media screen and (max-width: 800px) {
.leftcolumn,
.rightcolumn {
width: 100%;
padding: 0;
}
}
<div class="nav">
<ul>
<li>Learning Journal</li>
<li>Tutorial</li>
<li>Contact Me</li>
</ul>
</div>
<main class="full-height">
<div class="header">
<h2> CI435 - INTRODUCTION TO WEB DEVELEPMONT</h2>
<img src="images/htmlcode.jpg" alt="">
</div>
<div class="text">
<h2>PLACEHOLDER</h2>
</div>
</main>
<div class="container1">
<h3>Weeek x</h3>
<p> PLACEHOLDER</p>
</div>
<div class="container1">
<h3>Weeek x</h3>
<p> PLACEHOLDER</p>
</div>
<div class="container1">
<h3>Weeek x</h3>
<p> PLACEHOLDER</p>
</div>

Circle around inline number

I'm trying to create a circle border around a number like so:
But so far all my attempts have resulted in an oval:
Codepen to see it live
SCSS code so far
$browser-context: 16;
#function em($pixels, $context: $browser-context) {
#return #{$pixels/$context}em;
}
body {
line-height: 1.6;
display: flex;
flex-direction: column;
min-height: 100vh;
font-family: 'PT Sans', sans-serif;
background: #e5dde1;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
.header-nav {
background-color: #ff4c61;
color: white;
font-family: 'Oswald', sans-serif;
}
.category-nav ul {
background-color: #212d5b;
color: #ff4c61;
display: flex;
justify-content: space-evenly;
}
.category-nav a {
font-size: em(34);
text-decoration: none;
}
.category-nav .circled {
border-radius: 50%;
width: em(12);
height: em(12);
padding: em(4);
border: em(1) solid #ff4c61;
}
HTML:
<header class="header-nav">
<h1> APP</h1>
</header>
<nav class="category-nav">
<ul>
<li>A</li>
<li>B</li>
<li>C <span class="circled">3</span></li>
</ul>
</nav>
I been experimenting different solutions so far and I think the problem comes mostly from the fact that container of the number is an inline element (span). Whenever I switch the class .circled to a div instead or set the display to block, I get a perfect circle but then the number is pushed out and it breaks the flex layout. I wonder if there's any way to get the circle to work with a span?
For your .circled class you need to add the following styles:
.category-nav .circled {
...
line-height: em(12); /* needs to match the height */
display: inline-block; /* needs to not be an inline element */
text-align: center; /* center the character*/
}
You could make it an inline-block. Adding this to your example worked for me:
display: inline-block;
line-height: em(12);
text-align: center;
Check this answer for more information
$browser-context: 16;
#function em($pixels, $context: $browser-context) {
#return #{$pixels/$context}em;
}
body {
line-height: 1.6;
display: flex;
flex-direction: column;
min-height: 100vh;
font-family: 'PT Sans', sans-serif;
background: #e5dde1;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
.header-nav {
background-color: #ff4c61;
color: white;
font-family: 'Oswald', sans-serif;
}
.category-nav ul {
background-color: #212d5b;
display: flex;
justify-content: space-evenly;
}
.category-nav a {
color: #ff4c61;
font-size: em(34);
text-decoration: none;
}
.category-nav .circled {
border-radius: 50%;
width: em(12);
height: em(12);
padding: em(4);
border: em(1) solid #ff4c61;
}
.numberCircle {
display: inline-block;
border-radius: 50%;
behavior: url(PIE.htc);
/* remove if you don't care about IE8 */
width: 1em;
height: 1em;
padding: auto;
background: transparent;
border: 2px solid red;
color: red;
text-align: center;
font: 20px Arial, sans-serif;
}
<header class="header-nav">
<h1> APP</h1>
</header>
<nav class="category-nav">
<ul>
<li>A</li>
<li>B</li>
<li>C <div class="numberCircle">3</div></li>
</ul>
</nav>

A white gap between two div elements [duplicate]

This question already has answers here:
How to disable margin-collapsing?
(12 answers)
Closed 5 years ago.
Here is the HTML code (the white gap started appearing as soon as I added h3 to the last div):
body {
margin: 0;
font-family: sans-serif;
font-weight: 400;
background-image: url("../images/rooms.jpg");
}
.container {
width: 80%;
margin: 0 auto;
}
header {
background: #343434;
}
header::after {
content: '';
display: table;
clear: both;
}
.logo {
float: left;
padding: 10px;
}
nav {
float: right;
}
nav ul {
margin: 0;
padding: 0;
list-style-type: none;
}
nav li {
padding: 0;
display: inline-block;
margin-left: 60px;
padding-top: 19px;
position: relative;
}
nav a {
text-decoration: none;
color: white;
font-size: 13px;
text-transform: uppercase;
padding: 1em 0.5em;
}
nav a:hover {
color: yellow;
}
.welcome {
width: 100%;
height: 250px;
background: #406295;
}
.welcome h3 {
text-align: center;
}
<header>
<div class="container">
<img src="images/logo.png" alt="">
<nav>
<ul>
<li>Room Types</li>
<li>Services</li>
<li>About Us</li>
</ul>
</nav>
</div>
</header>
<div class="welcome">
<h3>Welcome to</h3>
</div>
I am fairly new to web development and stackoverflow. So I am sorry for any inconveniences. Any help is appreciated. Thank you.
Set margin: 0px; on h3 tag to resolve this issue. Check updated Snippet below..
body{
margin:0;
font-family: sans-serif;
font-weight: 400;
background-image: url("../images/rooms.jpg");
}
.container{
width: 80%;
margin : 0 auto;
}
header{
background: #343434;
}
header::after{
content: '';
display: table;
clear:both;
}
.logo{
float: left;
padding:10px;
}
nav{
float:right;
}
nav ul{
margin: 0;
padding: 0;
list-style-type: none;
}
nav li{
padding: 0;
display: inline-block;
margin-left: 60px;
padding-top: 19px;
position: relative;
}
nav a{
text-decoration: none;
color:white;
font-size: 13px;
text-transform: uppercase;
padding: 1em 0.5em;
}
nav a:hover{
color:yellow;
}
.welcome{
width: 100%;
height: 250px;
background: #406295;
}
.welcome h3{
text-align: center;
margin: 0px;
}
<header>
<div class="container">
<img src="images/logo.png" alt="">
<nav>
<ul>
<li>Room Types</li>
<li>Services</li>
<li>About Us</li>
</ul>
</nav>
</div>
</header>
<div class="welcome">
<h3>Welcome to</h3>
</div>
Just remove the margin from h3 like
.welcome h3 {
text-align: center;
margin:0;
}
body {
margin: 0;
font-family: sans-serif;
font-weight: 400;
background-image: url("../images/rooms.jpg");
}
.container {
width: 80%;
margin: 0 auto;
}
header {
background: #343434;
}
header::after {
content: '';
display: table;
clear: both;
}
.logo {
float: left;
padding: 10px;
}
nav {
float: right;
}
nav ul {
margin: 0;
padding: 0;
list-style-type: none;
}
nav li {
padding: 0;
display: inline-block;
margin-left: 60px;
padding-top: 19px;
position: relative;
}
nav a {
text-decoration: none;
color: white;
font-size: 13px;
text-transform: uppercase;
padding: 1em 0.5em;
}
nav a:hover {
color: yellow;
}
.welcome {
width: 100%;
height: 250px;
background: #406295;
}
.welcome h3 {
text-align: center;
margin:0;
}
<header>
<div class="container">
<img src="images/logo.png" alt="">
<nav>
<ul>
<li>Room Types</li>
<li>Services</li>
<li>About Us</li>
</ul>
</nav>
</div>
</header>
<div class="welcome">
<h3>Welcome to</h3>
</div>
This is due to collapsing margins
Remove the margin on the h3. Replace it with padding if you want to create space between the header and maintain the background colour.
body {
margin: 0;
font-family: sans-serif;
font-weight: 400;
background-image: url("../images/rooms.jpg");
}
.container {
width: 80%;
margin: 0 auto;
}
header {
background: #343434;
}
header::after {
content: '';
display: table;
clear: both;
}
.logo {
float: left;
padding: 10px;
}
nav {
float: right;
}
nav ul {
margin: 0;
padding: 0;
list-style-type: none;
}
nav li {
padding: 0;
display: inline-block;
margin-left: 60px;
padding-top: 19px;
position: relative;
}
nav a {
text-decoration: none;
color: white;
font-size: 13px;
text-transform: uppercase;
padding: 1em 0.5em;
}
nav a:hover {
color: yellow;
}
.welcome {
width: 100%;
height: 250px;
background: #406295;
}
.welcome h3 {
text-align: center;
margin-top: 0;
}
<header>
<div class="container">
<img src="images/logo.png" alt="">
<nav>
<ul>
<li>Room Types</li>
<li>Services</li>
<li>About Us</li>
</ul>
</nav>
</div>
</header>
<div class="welcome">
<h3>Welcome to</h3>
</div>
You can try adding style="display: inline; margin:0px; padding:0px;" to your <h3> Tag.
Another way is to apply a rule of overflow: auto to the .welcome div... thus creating a new block formatting context and avoiding the collapsing margins.
Edit: Let's add a little more context. In the spec, you can read that adjoining margins will collapse under certain circumstances. In particular, the margins need to belong to block-level boxes participating in the same block formatting context.
Even though .welcome and h3 are block-level boxes in your example, neither automatically establishes a new block formatting context (meaning they participate in the same block formatting context, meaning their margins collapse). Looking at the spec again, we see that some of the ways to establish a new block formatting context is to have a float, an absolutely positioned element, or a block box with the property of overflow set to something else than visible.
That's why the suggestions regarding overflow: auto or floating one of the elements work. My understanding is that if we make .welcome establish a new block formatting context, the context it participates in is different from the one it establishes itself. Removing the margin (possibly replacing it with padding) is another way to get around the problem.
Either apply margin-top:0 for H3-Tag
or
apply a float:left for .welcome
Both will fix your issue