An effective method for centering text within a parent div using absolute positioning

Looking for some assistance with a coding challenge involving Bootstrap 4. I'm trying to overlap text with an image and align it to the center. Here is the code snippet, any help would be greatly appreciated!

HTML

<div class="container-fluid front_page">
<img src="images/front_page_img.jpg" alt="front_page_image" class="front_page_img">
<div class="front_page_brand">
  <h1>T.A.C.S.</h1>
</div>

CSS

.container-fluid {
  padding: 0;
}

/* FRONT PAGE */
.front_page {
  position: relative;
}
.front_page_img {
  max-width: 100%;
  position: absolute;
}
.front_page_brand {
  position: absolute;
  color: red;
}

Answer №1

To make the parent container flexible and center the content, simply use the CSS property justify-content: center;. Since the position is already set to absolute, the content will overlay on top of the image. Take a look at the code snippet provided below.

.container-fluid {
  padding: 0;
}

/* MAIN PAGE */
.main_page {
  position: relative;
  display: flex;
  justify-content: center;
}
.main_page_img {
  max-width: 100%;
  position: absolute;
}
.main_page_title {
  position: absolute;
  color: blue;
}
<div class="container-fluid main_page">
<img src="https://dummyimage.com/400/000/fff" alt="main_page_image" class="main_page_img">
<div class="main_page_title">
  <h1>Unique Title Here</h1>
</div>

Answer №2

.homepage_logo {
  position: fixed;
  color: crimson;
  left: 50%;
  transform: translateX(-50%);
}

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

Using React to Build Customized Navigation Bars with Bootstrap Styles

Is there a way to adjust the layout within the navigation bar? I would like to create three columns of equal size. https://i.sstatic.net/wH7yW.pngThis is how I envision it looking: https://i.sstatic.net/DNTUE.png Below is my code snippet: <Navbar fi ...

reduce opacity of specified div background

Objective / Purpose I am working with multiple div elements and I want to assign two distinct classes to each of them, each serving a different purpose within my application. One class should determine the level, influencing the color of the div. The oth ...

using dynamic CSS classes in a Vue app

I am currently in the process of developing a component with vuejs and tailwindcss. I have run into an issue where the colors for the background and text are not being applied properly. <template> <div :class="[isDark ? `bg-${color}-900 t ...

Revamping the Look: Refreshing Background of Div

I'm attempting to change the background image of the body element on a webpage when I hover over links with data-* attributes. It's working perfectly, but I can't seem to figure out how to create a smooth fade between the images when a link ...

Expanding the axes using Google Charts

Seeking to Expand Y-Axis I am attempting to stretch the Y-axis so that it counts up to 300 instead of just 100. The issue arises when I adjust the Y-axis to reach 300, as the values remain in the same position as they did when counting to 100. Fo ...

VueJS can manipulate an inline template by dynamically changing its content and reinitializing

this particular query shares similarities with the discussions on VueJS re-compiling HTML in an inline-template component as well as How to implement Vue js directive in an appended html element Regrettably, the approach suggested in those threads is no l ...

What is causing my HTML script tag to not recognize my JS file in Next.js?

Just starting out with Next.js and trying to access the web cam for a project I'm working on, but encountering an issue when writing in the "script" tag. Below is the simple code for page.js: export default function Live(){ return( <html> ...

Ways to connect to a minimized hidden tabindex component using the hashtag symbol

I have created a glossary with terms in columns and hidden texts using plain css/html. Each entry is structured like this: A term followed by a hidden explanation, revealed on focus without the use of Java or JS. Instead of using :hover, I utilize :focus ...

"Challenges with Full-Width Dropdowns in Multi-level Mega Menus

I am currently attempting to design a multi-level mega menu that spans the full width of the screen, while keeping the content within it restricted to a maximum width of 1240px. I have managed to set the content to the maximum width, but I am facing challe ...

Ensure that the tables are HTML5 compliant by setting the cellpadding attribute for only specific tables, without

Perhaps I'm being a bit fussy. I'm looking to add cell padding to certain tables but not others, without having to manually edit each individual td element. I prefer to keep it HTML5 compliant, which means avoiding the cellpadding property of the ...

integrating the WordPress header into the WHMCS client portal

While working on a project, I am facing the challenge of aligning the WHMCS client area with my WordPress site. Progress has been made, but I have hit a roadblock. My goal is to integrate the header of my WordPress site into WHMCS. I initially attempted t ...

Ways to reload the page following the submission of a form

I implemented a fade dialog to present a form, and successfully submitted the form using ajax to create a new record in the database. Now, I am facing an issue where I cannot refresh the page after the ajax call finishes. Despite attempting to use JavaScr ...

What is the best way to retrieve the initial <ul> element from a JavaScript document?

Just to clarify, I'm looking to target a specific div with a class and the first <ul> from a document (specifically in blogger). Currently, I have a JavaScript function that grabs the first image and generates a thumbnail as shown below: //< ...

Integrate buttons for increasing and decreasing with the `<select>` element in HTML

Apologies for what may seem like a trivial question, but I am truly stuck. Despite searching extensively, I cannot find how to create a basic HTML tag with increase and decrease buttons aligned to the right. Your assistance would be greatly appreciated. Th ...

Adjusting jQuery tab content heights to maintain consistent height across tabs and prevent varying heights

I am currently working on a tabbed view that is very similar to the demo found at the following link: http://jsfiddle.net/syahrasi/us8uc/ $(document).ready(function() { $(".tabs-menu a").click(function(event) { event.preventDefault(); $(this).pare ...

Having trouble with your custom accordion content in React JS not sliding open?

Check out my progress so far with the fully functioning view here This is the structure of the Accordion component: const Accordion = ({ data }) => { return ( <div className={"wrapper"}> <ul className={"accordionList ...

What is the best method for inserting CSS into a webpage using a Chrome extension?

I am seeking guidance on how to incorporate CSS into a webpage using a Chrome extension. The CSS code I am attempting to inject is as follows: body { background: #000 !important; } a { color: #777 !important; } Here is the content of my manifest.j ...

Which JQuery plugins can transform regular <select> dropdowns into more stylish options?

After an extensive search, I was only able to locate one solution at this link. I scoured the entire internet for alternatives. ...

Measuring Bootstrap's breakpoints using specific divs: A beginner's guide

Is it possible for Bootstrap 5 to create responsive layouts with draggable vertical borders between two columns? The answer is Yes, by adjusting Bootstrap to use container queries instead of media queries. Major browsers have supported container queries si ...

BOOTSTRAP Issue: The sticky footer in the template is not staying sticky

I am at the point where I am tempted to open my window and throw my computer out. I followed a tutorial on Bootstrap for the footer template. Everything looks good, but when my text extends beyond one page, the footer remains stuck in place and does not m ...