Generate a Line that is positioned absolutely and does not line up with the center of the

Whenever I apply 'text-center', the text does not align horizontally and instead lines up vertically. You can see an example in this js fiddle: I am aiming for something like this: https://i.sstatic.net/oueEr.png

https://jsfiddle.net/dungvd/ey4fj6nv/2/.

test.html:

"<div>Question</div>
<div class="container">
    <div class="row  ">
        <div class="col-sm-6 mx-auto text-center">
                <h2 class="green-line">
                        Welcome to course bs2wp
                </h2>
        </div>
    </div>
</div> "

test.css:

* {
    margin: 0;
    padding: 0;
}

h2.green-line {
    position: relative;
}

h2.green-line:after {
    content: "";position: absolute;
    width: 65px;height: 5px;
    background: green;
    top: 0px;left: 0px;
}

Answer №1

Modify the CSS code for h2.green-line:after to include top:50% and transform:translatey(-50%);

 h2.green-line {
    position: relative;
    display:inline;
}

h2.green-line:after {
    content: "";
    position: absolute;
    width: 65px;
    height: 5px;
    background: green;
    top: 0;
    left: 0px;
}

Check out the updated code on JSFiddle

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

Is there a way to set up a saving path using xhtml2pdf and provide a download link

I am currently using xhtml2pdf to convert my form into a PDF file. By default, it saves the PDF in the same location as my manage.py file. My question is how can I change the saving path to send the PDF to my Desktop, for example (running MacOSX). Below ...

Guidelines for effectively adjusting Saas variables in Next.js using React-Bootstrap

Currently, I am tackling a fresh project in Next.js, and I'm encountering difficulties in personalizing the bootstrap sass variables within my project. I came across a reference on how to customize bootstrap at this link: . However, I encountered the ...

Switching between different apps on a Django website

There are currently 2 applications on my website: users base The main url configuration always generates URLs with the appname of base/index.html. When a URL action like href="login" is provided from base/index.html, it automatically looks for "base/log ...

Issues with the use of overflow:hidden

I need to create 5 divs aligned horizontally next to each other, spanning the width and height of the window. Each div should occupy 20% of the window width, and any overflow content should be hidden. Below is the CSS code for two of the divs: #container1 ...

Utilizing Bootstrap for creating responsive CSS regulations

Is there a way for specific parts of my website to automatically resize on a mobile device without having to manually input responsive CSS rules based on page width? Can Bootstrap be used to trigger these changes instead? For instance, I noticed that Boot ...

Creating gaps between buttons in Bootstrap using the ml-auto class

I find myself facing an issue with two buttons that I created. They are closely packed together without any spacing in between, even after attempting to use ml-auto. The lack of space is impacting the user interface and I am seeking assistance to address ...

Gitbook is facing a unique challenge with the Chinese language in its HTML code - an issue with excessive spacing

Currently, I am utilizing gitbook and github pages to construct my personal webpage with the main language being Chinese. However, I have noticed that gitbook is adding an extra space in some places where it is unnecessary. Below is the text found in the m ...

AngularJS self-invoking function

Encountering an issue with AngularJS. My HTML code looks like this: <tbody ng-repeat="show in pastShows"> <tr> <td><input value="{{show.address}}" type="text" id="addressUp" class="form-control" placeholder="address">&l ...

What could be causing this Angular dependency to go unnoticed?

I am currently developing an angular application and organizing my logic into separate files. I have created stub modules in app.js, services.js, and controllers.js with the intention of implementing them in individual files. However, I am facing difficul ...

Experiencing problems with CSS and other scripts failing to load following navigation with nodeJs

Currently, I'm trying to extract data from a MongoDb database and then proceed to view, modify, and delete it. The process of extracting the data is going smoothly, however, I am encountering difficulties with editing. To address this issue, I created ...

Is it necessary to remove every letter before moving on to the following array position?

I've been working on a script to create an animated "self-writing text" effect. However, I'm encountering an issue where each word jumps to the next one instead of smoothly transitioning by deleting each letter before moving on to the next word i ...

Is it possible to remove certain 'css-' class names that MUI automatically applies to its components? (Using Next JS and MUI)

After successfully migrating my create-react-app project to Next JS using the latest version (12.1.0) and following the migration guide at https://nextjs.org/docs/migrating/from-create-react-app, I encountered an unexpected issue. Despite still using MUI a ...

The sorting icon cannot be substituted with jQuery, AJAX, or PHP

Currently, I am working on implementing "sort tables" using ajax, jquery, and PHP. The sorting function is functioning correctly; however, I need to show/hide the "sorting images". At the moment, only one-sided (descending) sorting is operational because I ...

Adding CSS styles to an HTML page using JavaScript

Unfortunately, I do not have the ability to access the HTML directly as it is generated dynamically by a program. However, I do have access to the JS page that is linked to it. As an example, I am able to manipulate elements using JavaScript like so: ...

How to style a modal window with a scrollbar using CSS

When my website loads, I am using reveal.js to display some terms and conditions. However, the text is quite lengthy and causes the main scrollbar of the website to extend. What I would like to do is add a scrollbar to the modal window so that users can s ...

What is the best way to place a p-growl element in the bottom right corner of the page?

I've been struggling to fix the positioning of my growl message at the bottom right corner by overriding the CSS classes of p-growl. Initially, I attempted to override the .ui-growl class like this: ::ng-deep .ui-growl { position: fixed; b ...

Utilizing Node.js Express to connect an EJS template to a JavaScript file

Currently, I am working on a Nodejs/Express project where my view is constructed using an ejs file. A few JavaScript functions are being utilized in the project and when they are placed inside the script tag within the ejs file, everything seems to run smo ...

Trouble displaying certain HTML code and its output on the browser?

I am in the process of developing a user profile page. I have designed a form with various fields, but the code within the section is not displaying correctly in the browser. I attempted to inspect the elements, but the code within that section remains inv ...

Attempting to create a slider utilizing jQuery

I'm currently working on creating a slider using jquery. I have downloaded the cycle plugin for the slider and included it in my file. The slider consists of 7 pictures. Below is the code I am using, can someone please help me identify any issues? &l ...

Guide to activating form elements using a JQuery function

I need help setting up a form with 11 rows and 11 columns. By default, the form fields should be disabled, but when I click on an "EDIT" button, they should become enabled. Any assistance would be greatly appreciated. Thank you in advance. Here is my edit ...