How to position an element to the left and another to the center of the screen while vertically aligning both using CSS

I have a single list and an h1 header. My goal is to position the list on the left side of the screen and center the h1 vertically in relation to the list. The size of the list is variable, so I want the height and width to adjust accordingly without overlapping the header. If viewed on a smaller screen, the list should appear below the header. The h1 will consist of just one word, therefore the height of the container will be determined by the list.

HTML

<header>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
  </ul>
  <h1>BLOG</h1>
</header>

CSS

header{
   width: 100%;
}
ul{
  padding: 0;
  margin: 0;
  list-style: none;
}

ul, h1{
  display: inline-block;
  vertical-align:middle;
}

I have attempted various techniques, including pseudo-elements, but struggled with understanding them and spent many hours trying to solve this issue.

Apologies for any language errors.

Reference :

http://css-tricks.com/centering-in-the-unknown/

http://tympanus.net/codrops/2013/07/14/justified-and-vertically-centered-header-elements/

Thank you in advance.

UPDATE

Layout Photo Provided

Answer №1

Let's enhance the structure of your markup by introducing additional wrappers:

<header>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
  </ul>
  <div id="h1-outer-wrapper">
    <div id="h1-inner-wrapper"> 
      <h1>BLOG</h1>
    <div>
  </div>
</header>

Style it with the following CSS rules:

header {
  width: 100%;
}
ul {
  padding: 0;
  margin: 0;
  list-style: none;
}
ul, #h1-outer-wrapper {
  display: inline-block;
  vertical-align: middle;
}
#h1-inner-wrapper {
  position: absolute; 
  width: 100%;
  left: 0;
}
h1 {
  text-align: center;
  padding: 0;
  margin: -.6em 0 0 0;
}

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

Ways to eliminate a css class with jquery based on a specific screen dimension

There is a div element that includes a specific class. My goal is to remove this class when the window is resized to fit a mobile view-port. <div class="box"></div> ...

What is the best way to horizontally align my div content while ensuring it is responsive, alongside a sidebar and top menu on the same

I am facing an issue trying to center my div content responsively with a sidebar menu and a top menu using Bootstrap. However, when I require the side-menu file, my div content gets placed at the bottom of the page unexpectedly. I am only using Bootstrap 5 ...

CSS - stacking containers vertically with scrollbars

I am in need of a vertical stack of blocks, which may include scrolls, contained within a fixed-sized container without scrolls. The number of visible blocks is dynamically managed by JavaScript code. Some blocks can be hidden or shown, and when a block is ...

The <ul> tag is not receiving the correct styles and is not displaying properly

I have successfully integrated an input control and button into my table within the Angular 7 application. When a user inputs text in the control and clicks the add button, the text is appended to the <ul> list. However, the layout of the <ul> ...

Scrolling container embedded within a parent with absolute positioning

I have encountered a tricky situation with an absolute positioned div and its nested div having overflowing content. My goal is to enable vertical scrolling for the child div, however, my attempts so far have been unsuccessful. The challenge here is that I ...

In Less.js, an action will be taken if the @color equals a specific value

Imagine I have a variable: @title: blue; I want to know if there is a way to use the iscolor function to perform an action if the value is blue. For instance, if @title = blue, import a @mixin into a class named "mytitle". I'm having difficulty gras ...

Run JavaScript code before finalizing the "submit" action within a Ruby on Rails application

Having trouble with utilizing old JS scripts found on Stack Overflow. <div class="form-actions"> <%= f.button :submit, class:"btn btn-success create-campaign" %> </div> The submit button is causing an issue for me. <div clas ...

Struggling to accurately capture the values from checkboxes and dropdown selections to ensure the correct data is displayed. Assistance is needed in this

I am facing challenges in retrieving the accurate data for display from Mat-Select and Mat-Checkbox components. My goal is to capture the selected values from users and perform if-else statements to validate conditions, displaying the correct data view if ...

Is it possible to obtain an image that is responsive while maintaining a specific height?

Currently, I am working on a page builder to create a shop. It's great that I have the ability to change the CSS on this project. However, I am facing a challenge with the responsive resizing of images in a 4 column row. Since the images have differe ...

Stop scrolling on the body of the webpage

I am struggling to find a solution to completely disable scrolling on the HTML body. I have experimented with different options, but none seem to work as desired: overflow: hidden; did not disable scrolling, only hid the scrollbar. position: fixed; w ...

Inaccurate sizing of popup dialogs on SharePoint 2010

Currently, I am in the process of revamping a SharePoint 2007 web application to SharePoint 2010. I was surprised to find that the popup dialog boxes for new items, edit, etc. have inline styles for fixed width and height. Below is an example where div.ms ...

Combining various functions into a single button

I am currently working on creating a full-screen menu that functions like a modal. Everything seems to be working fine, except for the fadeOut animation. Can someone please help me understand what is causing issues with my scripts/codes? I want the content ...

Unable to retrieve the desired information

Being new to development, I recently attempted an AJAX search and encountered the following issues. Upon running it, I received an "undefined" error message. How can this be resolved? This is where you enter text. <input id="word" type="text" placehol ...

Clearing Time Field Input in Safari

Recently, I've been utilizing the following HTML input element: <input type="time"> While testing it in both Chrome and Safari, I noticed that the clear field (cross button) is absent when using Safari. How can I make the cross button appear i ...

Steps to conceal a <select> element and reveal it by clicking a button

I'm currently working with Bootstrap 3 and I am attempting to replicate jQueryMobile's select option feature. This would involve replacing the standard select textbar and arrows with a single button that can toggle the opening of the select. Ins ...

What is the proper way to apply a background color to the entire body using CSS?

I'm facing an issue with getting the background color to cover the entire body of my webpage. Currently, it only captures a certain size and when there is scrolling on the window, two shades of colors appear. I want the background color to span the en ...

The SetInterval notifications remain stagnant without any alterations

I am currently working on designing a loading screen for a game using HTML and JavaScript. My goal is to have different messages displayed every three seconds. Despite using the setInterval function successfully for other tasks (like triggering an alert ...

unusual problems with absolute positioning in CSS

I've run into a problem with absolute positioning in my CSS. Oddly, IE 10+ displays correctly, but Chrome gets distorted. See the images below: Any advice would be appreciated. (This distortion seems to have started after the Chrome 52 update) IE ...

Setting the height to 100% will not maintain the aspect ratio of the image

Having trouble with Blogger once again as I try to style the homepage. I am aiming to feature snippets and titles in tiles with a fixed height of 200px but a dynamic width for responsive design. My goal is to display the first image and a "read more" butt ...

What is the best way to retrieve the parent element quickly using Jquery?

html: <span class="ui-spinner ui-widget ui-widget-content ui-corner-all"><input class="spinner1 ui-spinner-input" id="q1" name="value" value="1" min="1" aria-valuemin="1" aria-valuenow="2" autocomplete="off" role="spinbutton"><a class="ui ...