What is causing the title element to occupy the entire vertical space within the container?

The main title in the header is taking up all the vertical space and shifting the h2 to the right when it should be centered below it. They are supposed to be in the same container but not connected.

https://codepen.io/ychalfari/pen/JVYoNW

https://codepen.io/ychalfari/pen/mgVdLr

I have attempted a few things, like putting the title in a <p> tag, but it still occupies all the vertical space.

div class ="header-wrap">
    <header>
      <div class="span-wrap">
        <span id="my">My</span> 
        <span id="journey">Journey</span> 
        <span id="of">of </span>
        <span id="learning">Learning</span></div>
      <h2>Documenting the Learning Process in a Fun Interactive way! </h2>
    </header></div>  

This is the CSS:

 header-wrap, header{

  display:flex;
  color:white;  
  background-color:red;
  height: 100vh;
  width:100vw;}

h2 {

  font-size:25px;
  letter-spacing:2px;
  font-family:'Raleway';
  align-self:flex-end;}

.span-wrap{

  display:flex;
  justify-content:center;}


#my{
  font-size:55px;
  position:relative;
  top:30px;
}
span{
  max-height: 65px;
  display:block;
}
#journey{
  top:80px;
  font-size:55px;
  position:relative;
}
#of{
   top:120px;
  font-size:45px;
  position:relative;
  margin: 0 35px;
  border: solid;
  padding: 1px 15px;
  max-height:60px;}
#learning {
   top:185px;
  font-size:55px;
  position:relative;  
}

I expect

<h2>Documenting the Learning Process in a Fun Interactive way! </h2>
to be centered at the bottom of the div, unaffected by the "Journey of Learning" part.

Answer №1

To achieve the desired layout, make sure to utilize a column flexbox by including flex-direction: column in your header, along with the following adjustments:

  • Apply flex: 1 to the span-wrap (this will fill up the available space after positioning the h2 at the bottom)
  • Update the align-self: center property for the h2 element

Take a look at the demo provided below:

html body {
  font-family: 'Raleway';
  margin: 0;
  padding: 0;
  min-height: 100%;
  width: 100%;
}

ul li {
  display: none;
}

header-wrap,
header {
  display: flex;
  color: white;
  background-color: red;
  height: 100vh;
  width: 100vw;
  flex-direction:column; /* added */
}

h2 {
  font-size: 25px;
  letter-spacing: 2px;
  font-family: 'Raleway';
  align-self: center; /* changed */
}

.span-wrap {
  display: flex;
  justify-content: center;
  flex: 1; /* added */
}

#my {
  font-size: 55px;
  position: relative;
  top: 30px;
}

span {
  max-height: 65px;
  display: block;
}

#journey {
  top: 80px;
  font-size: 55px;
  position: relative;
}

#of {
  top: 120px;
  font-size: 45px;
  position: relative;
  margin: 0 35px;
  border: solid;
  padding: 1px 15px;
  max-height: 60px;
}

#learning {
  top: 185px;
  font-size: 55px;
  position: relative;
}
<div class="header-wrap">
  <header>
    <div class="span-wrap">
      <span id="my">My</span> <span id="journey">Journey</span> <span id="of">of </span><span id="learning">Learning</span></div>
    <h2>Documenting the Learning Process in a Fun Interactive way! </h2>
  </header>
</div>
<nav>
  <ul>
    <li>Arrays</li>
    <li>Objects</li>
    <li>Apps</li>
    <li>Design</li>
  </ul>
</nav>
<section>
</section>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unleash the power of drag-and-drop functionality with cdkDrop

I am currently tackling a project that requires the implementation of a drop zone functionality where elements can be dragged from a list and dropped in a zone for free movement. I intend to utilize a cdkDropList for the zone due to its comprehensive list ...

Is there a way to detect if JavaScript is disabled using a unique CSS selector?

Does anyone know of a CSS selector that can be used when JavaScript is disabled? I'm not referring to the noscript tag, but specifically in CSS. ...

Issues with Laravel 5.8 and Bootstrap not functioning properly in Jquery

Check out this link for using Bootstrap Select. The code works perfectly in the view, but when I try to implement it with jQuery below, it doesn't work. Can someone help me fix this issue? View Code: <table id="tableAppointment" style=&q ...

The issue with the sticky menu not functioning properly may be due to the use

Hey there, I'm facing an issue with the Navbar Menu (White Bar) on my website. It is working perfectly fine and sticking to the top as expected. However, the problem arises when I click on the Menu - the Sticky class stops working. Upon investigating, ...

React Alert: Please be advised that whitespace text nodes are not allowed as children of <tr> elements

Currently, I am encountering an error message regarding the spaces left in . Despite my efforts to search for a solution on Stack Overflow, I have been unable to find one because my project does not contain any or table elements due to it being built with ...

Assigning the CSS class "active" to the navigation menu in ASP Classic

Seeking assistance with setting a CSS class for the current page in an include file that contains the primary navigation menu. Here is my current progress: public function GetFileName() Dim files, url, segments, current 'obtain c ...

Balancing columns with active elements to ensure equal resizing

I am working on coding an image that requires specific resizing capabilities: https://i.sstatic.net/7hLwL.png The objective is to ensure that when the browser window is resized, the center notch remains proportional and both columns scale uniformly. Bel ...

The display of data in Datatables is malfunctioning

I have already included the provided CDN on the website but I am still unable to display any results even after copying and pasting every line of code. Here is the CDN <link rel="stylesheet" type="text/css" href="https://cdn.d ...

ASP.NET Core MVC: Issue with Passing C# Razor Variable to HTML Tag

GitHub Repo: https://github.com/shadowwolf123987/Gun-Identification-App I'm currently facing an issue in passing the values of two C# variables from the code block defined in my view to the corresponding html tags within the same view. Unfortunately, ...

Creating a uniform layout with Flexbox: Equal-height columns with aligned tops

In the application, I have implemented a flexbox layout similar to the code snippet below, containing a group of li elements with three divs in each. .container { width: 500px; } ul { list-style: none; margin: 0; padding: 0; display: flex; } l ...

Exploring Bootstrap and its focus on creating responsive designs

The query I recently completed a website for a local sports community using bootstrap v4. While most of the website is finished, I am currently focusing on adjusting the media breakpoints to ensure responsiveness. However, I have encountered a few issues: ...

Flexbox causing spacing problems in HTML/CSS navigation bar

I have encountered a unique issue that I cannot seem to find a solution for, so here goes: I am in the process of designing a navigation bar with the heading positioned on the left-hand side and the navigation items on the right. My goal is to center the ...

What is the best .scss file to use for updating the site?

Currently in the process of learning SASS and Bootstrap 4, I have set up some .scss partial files and imported them into my site.scss file as required. Making changes to Bootstrap involved modifying my _my-theme.scss file. But now, I'm wondering about ...

What is the best way to eliminate the "#" symbol from a URL?

I'm currently updating a website that features a hash symbol in every link when switching pages. This causes the page to not refresh everytime I switch, instead it stays on the last position of the site. Where can I locate the code responsible for th ...

Tips on adjusting the font size of headers in a Vuetify v-data-table?

I've been struggling to change the font size of the headers in my v-data-table. No matter what I try, the font doesn't seem to update. I even experimented with the Chrome developer tool and managed to make it work there. However, when I attempt t ...

Upgrade the old website by incorporating some components of the Framework CSS

Having experience with bootstrap, semanticUI, foundation, and other frameworks, my new project involves adding features to an existing website without rebuilding it entirely. I am looking to implement a partial view using a framework's CSS. How can I ...

Arranging divs beneath other elements using CSS positioning without needing to modify the HTML code

i need to align the list elements under the menu items, but the layout crashes when the fourth item is displayed. I can't change the HTML code without affecting the layout of my app. Is there a way to dynamically hide and show the elements on the page ...

What is the reason behind the HTML button producing the 'ul' node just once even after being clicked multiple times?

Just to clarify, the code below is successfully doing what I intended. I am currently developing a basic todo application. Each time the button on the page is clicked, it triggers the createListElem() function. The initial line of code in this function ap ...

Is it possible to host three separate web pages within a single Firebase project on Firebase Hosting?

Imagine I have set up a project called ExampleApp on Firebase. I've designed a page with a form for users to submit data, hosted by Firebase. The Cloud Firestore database is storing this submitted data when the user completes the form and hits submit ...

Customizing the navigation bar color upon page load in Ionic

Hey there! I'm looking to switch up the color of my nav-bar every time a page loads. So, I gave this a shot in menu.html: <ion-side-menus enable-menu-with-back-views="false"> <ion-side-menu-content> <ion-nav-bar class="{{headerCl ...