What is the best way to add a space line after a word in a sentence using HTML and CSS?

Inquiry: Sentence that needs completion

This question pertains to HTML/CSS.

I am looking to replicate the image provided, where I need to insert a line to fill the empty space after certain words.

The length of the words may vary.

For instance, if the total width is 1000px and the word is 100px long, the half-line should be 900px in length.

If the word is 350px, then the half-line should be 650px long.

Is there a CSS solution for achieving this effect?

Please provide guidance on how to accomplish this task.

Answer №1

Here's a helpful solution :)

h2 {
    overflow: hidden;
}

h2:after {
    content:"";
    display: inline-block;
    height: 0.5em;
    vertical-align: bottom;
    width: 100%;
    margin-right: -100%;
    margin-left: 10px;
    border-top: 1px solid black;
}
<h2>Featured products</h2>

Answer №2

If you are looking to create a grid layout, the following CSS code can help you achieve that:

.parent {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
}

 .line{
    background:black;
    height:1px
}
<div class="parent">
  <div>My some text</div>
  <div  class="line"></div>
</div>

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

Tips for positioning Bootstrap thumbnail elements

I have a query regarding my implementation of the thumbnail feature in Bootstrap. My goal is to ensure that three thumbnails are aligned per row. Refer to the image linked below for clarification: This is the desired layout: (Click Here) The image illust ...

Saving information to a hidden div using jStorage

Currently, I am utilizing jStorage for storing data in local storage. When I store the data using console.log() and later retrieve it using $.jStorage.get(), I found that the values are not being assigned to the hidden div. Can someone provide guidance o ...

I have noticed that the Javascript code is being loaded prior to the completion of my HTML/CSS page for some unknown

I am completely new to the world of web development. I'm encountering an issue where my JavaScript code (specifically alerts) is loading before my HTML/CSS page has fully loaded. I've been using sample alerts to test this out, and ideally, they s ...

How can I use CSS to transform a "+" symbol to an "x"?

When I created an accordion using HTML, JS, and CSS, I encountered a problem. The "+" sign in the accordion does not rotate correctly as it should. Instead of rotating from the middle of the "+" sign, it rotates from the top. This is my HTML code: <di ...

The issue with the sticky table header functionality is that it is not functioning properly within the Angular Materials mat

Hi there, I'm currently facing some challenges with html/css tables and sticky headers in combination with Angular Material. Within my project, I am utilizing Angular Material's sidenav components such as <mat-sidenav-container>, <mat- ...

substitute tags

Is there a way to change the tagName of a tag using jQuery? For example, if I have an HTML document and I want to replace all 'fieldset' with 'div'. Any suggestions would be appreciated! ...

The embedment of wmv videos does not include the option for a fullscreen button

I am currently attempting to insert a wmv video into an HTML code. The file plays without any issues, however, I would like the website's users to have the option to view the video in fullscreen mode by clicking on a fullscreen button. Unfortunately, ...

Using JavaScript and Regular Expressions for Performing Multiple Replacements

One issue that arises is that although the replacement functions as expected, all occurrences are replaced with the first find. (For example, see code below). The variable target represents the input field that contains the string to be highlighted, while ...

Mobile Iframe in Full View

Currently, I am working on a small project using Angular and Twitter Bootstrap. However, I have encountered a problem. I am trying to create a template that displays content in full screen upon clicking a button. The issue is that the iframe I am using wor ...

When using $http get, it returns a "not found" error, but the direct request

While attempting to utilize a webAPI built in ASP.net, I encountered an issue. When I try to retrieve data from the API using angular $http.get in the browser console, I receive an error message saying GET <--URL--> Not found. However, when I make re ...

Creating sleek mobile apps with AngularJS

As I work on developing a complex app using AngularJS, I have come across numerous discussions on how to best structure an application. However, I am still seeking clarity. A typical app generally includes: 1) Login page/Index page 2) Home page with hea ...

Trouble with displaying theme modifications in Liferay

Having recently delved into CSS and just starting out with Liferay, I am in the process of creating a custom theme. As an experiment, I attempted to modify the title text color for portlets on the page. In my custom.css file, I have included the following: ...

Low-quality CSS Gradient Design

Hey everyone, Feel free to take a look at my preloader on this link: (Hit ESC as soon as the page loads to pause the website and focus on the loader) Upon closer inspection, you'll notice that there is an issue with the quality of the background l ...

Is there a way for me to dynamically retrieve the input value produced by the Query?

Is there a way to retrieve the value of a dynamically created input field? $('#inputArea').append(" <input id = "arrivalTime1" type = 'number' placeholder='Arrival Time' style = 'display: none;'> " ...

Generating Dynamic Widgets Within the Document Object Model

Currently, I am working with jQuery Mobile 1 alpha 1. In order to create a text input field using jQuery Mobile, you need to include the following HTML code: <div data-role='fieldcontain'> <label for='name'>Text Input:</ ...

Assistance required in filling out a table solely through JavaScript with input from an HTML form

Hello, I am currently pursuing a second career and have just started learning HTML & JavaScript. For a simple assignment, I need to take user input in the form of numShares and numYears through HTML. My goal is to use JavaScript to populate a 3-column tabl ...

What is the process for setting up a "Highlight tab" feature in Next.Js?

I am currently working on implementing a selected tab feature in Next.Js. Users will have the ability to search for either Users or Posts by clicking on corresponding buttons. https://i.sstatic.net/mRBgQ.png Once the user clicks on a button, it should ch ...

What is the best way to include an arrow in a dropdown menu?

I've been working on restyling a Select box and I want to add a CSS arrow that rotates as the Select box expands. However, I'm struggling to align the arrow properly with the Select box. I've tried using code from the internet, but it hasn&a ...

Tips for optimizing Angular source code to render HTML for better SEO performance

Our web platform utilizes Angular JS for the front-end and node js for the backend, creating dynamic pages. When inspecting the code by viewing the source, it appears like this: For our business to succeed, our website needs to be SEO-friendly in order to ...

Adjusting the visibility of a div as you scroll

I'm trying to achieve a fade-in and fade-out effect on div elements when scrolling over them by adjusting their opacity. However, I'm facing difficulties in getting it to work properly. The issue lies in the fact that my div elements are positio ...