"Creating a distinctive CSS style for underlining titles without including the actual

Although I've searched on SO, I still haven't found a satisfactory solution to my question.

So here's the issue:

I want to underline an h3 tag with 100% width EXCEPT for the actual text part. It should look like this:

My super title ____________________________________________________

The underlined section needs to be 100% width, so simply adding spaces as in

h3:after {
        content:"\a0\a0\a0\a0\a0\a0\a0\a0\a0\a0\a0\a0\a0";
}

won't work since it requires a fixed number of whitespaces.

Additionally, the implementation must be purely CSS without any surrounding DIVs or spans (due to user-generated content from wysiwyg), just a standalone h3 tag.

Is achieving this effect possible using CSS3 alone? If not, I am open to incorporating some JavaScript to make it happen.

UPDATE:

Attached is a screenshot showing the desired outcome:

Answer №1

Here's a different approach to achieve the same result:

Code Snippet

<h3>Create a full-width title</h3>

CSS Styling

h3 {
  display: block;
  width: 100%;
  background: #fff;  
  white-space: nowrap;
  overflow: hidden;
}

h3:after {
  content: "";
  display: inline-block;
  width: 100%;
  margin-left: .5em;
  border-bottom: 1px #767676 solid;
}

See an example here:


Visual Outcome

Answer №2

Is this the style you're looking for? view demo

    h3:after {
    content:"";
    border-bottom: 1px solid black;
    overflow: hidden;
    width: 100%;
    display: inline-block;
    position: relative;
    left: 150px;
    top: -20px;
}

Answer №3

Give this a shot:

CSS

h3 {
    display:block;
    width:100%;
    overflow: hidden;
    position: relative;
}
h3:after {
    content:'';
    border-bottom:1px solid black;
    position: absolute;
    width: 100%;
}

JSFIDDLE

Answer №4

If you want to achieve this effect without using the :after pseudo element, you can try the following approach:

<div id="wraptitle"><h3>A Second Title</h3></div>

Here is the CSS code:

#wraptitle {
    border-bottom : 1px solid black;
    position : relative;
}

#wraptitle h3 {
    display : inline;
    position : relative;
    bottom : 0;
    border-bottom : 1px solid white; /* white represents the background color */
    padding-right : 10px;
}

Ensure that the margin of the h3 element is set to 0 so that its border extends over it properly.

You can view a live example by visiting: http://jsfiddle.net/JYNn5/

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

Trick for using :checked in CSS

Is it possible to change the color of a deep linking div using an input checkbox hack in the code below? <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /&g ...

Determine the number of visible li elements using jQuery

Currently, I am utilizing a jQuery script to count the number of li elements in my HTML code. Here is an example of the setup: HTML: <ul class="relatedelements"> <li style="display:none;" class="1">anything</li> <li style="disp ...

Is it feasible to swap out the cursor for a personalized image of my choice?

Can I replace the cursor icon with my own custom image that I created in Photoshop? I have seen websites with custom cursor images, so I know it is possible. But how do I do it and is it a standard approach? Will it work across all browsers? ...

Send the style description to the child component

Is there a way to define a style in a parent component and then pass it to a child component? <style> .teststyle { background-color: red; width: 100px; } </style> I initially thought that if I did not use scoped, the .teststyle ...

The most effective method for transferring settings from the server to the user interface within WordPress

I've been grappling with a question on my mind. I recently added options pages to the backend of my Wordpress site and now I'm unsure about the best way to pass their parameters to the frontend. For instance, if I have a color field in the backe ...

The controller is receiving NULL data from the AJAX POST request

Hello, I am facing an issue with my AJAX POST request that is returning null data to my Controller. Here is the AJAX code I am using: $(document).ready(function () { $("button").click(function () { $.ajax({ url: '@IGT.baseUrl/ ...

Spread out the items within an inline block

Is there a way to create space between icons that are in an inline block without them touching each other? One solution could be to add a container around each icon, center the icons within the containers, and then place the containers in the block. You c ...

Blending the widths of native elements with those of Bootstrap columns

Having trouble aligning spans in a Bootstrap 3 form to degrade into a stack on mobile: From [station1] to [station2] at [time] From [station1] to [station2] at [time] While this code works to an extent: <div class="row"> <div class="col ...

Utilizing box-sizing for the creation of an internal border

Looking to create an HTML table with clickable cells, each containing a div that adds a border upon clicking. The challenge is ensuring the border stays within the boundaries of the td without altering the size of the table or its cells. Struggling to achi ...

How can we show a React JS component when clicked, without using the App.js file for display?

How can I display a component onclick in React JS without using UseState in a file other than App.js? This code will be in App.js var [clicks, setClicks] = useState(false) return( <> {clicks && &l ...

What is the best way to align 3 divs next to each other with spacing and borders?

I'm having trouble aligning three divs side by side. When I try to add borders and a small gap between each div, the third div ends up on a new line. Is there a way to automatically resize the divs so they fit together? HTML: <div class="trendi ...

Attempting to choose everything with the exception of a singular element using the not() function in Jquery

Within the mosaic (div #mosaique) are various div elements. My goal is to make it so that when I click on a specific div, like #langages or #libraries, the other divs become opaque while the selected div undergoes a size change (which works correctly in t ...

A pair of inline divs (personal computer) set with vertical alignment in the center on media sources

Struggling to create a topbar for a webpage with 2 inline divs and having difficulty centering them vertically on media screens. (Paint) example of what I am trying to achieve Currently using float: left; to keep the divs inline along with display: inlin ...

What is preventing this jQuery from altering the opacity?

Currently, I have a piece of code that is intended to change the opacity of a div element from 0 to 1 as soon as the user initiates scrolling on the body. However, it appears to be malfunctioning for reasons unknown. $("bod").load(function(){ document ...

Struggling with aligning a div in the center

I've been struggling to get my "boxes" div centered on my page so that everything inside that div is centered instead of being pushed to the left. Unfortunately, my CSS vision didn't turn out as expected. If someone could take a look at my jsbi ...

Using React to organize content within a material-ui layout efficiently

Currently, I am developing a React page using material-ui integrated within Electron. The main requirement is to have an AppBar containing Toolbar and Drawer components. To achieve this, I have referred to the source code from https://material-ui.com/demo ...

The hamburger menu for mobile devices is not functioning properly on the website's mobile version, however it operates correctly when the screen is resized

Currently, I am facing an issue with the hamburger menu not responding on my mobile device. Oddly enough, it does work when I resize my browser window to mimic a mobile size. There seems to be a glitch happening, but I'm struggling to pinpoint the exa ...

Embed the website onto a webpage using ajax or an iframe without any need for navigation

I have a unique challenge ahead. Imagine there are two websites, one is a web page and the other is hosted within the same domain. My goal is to load the entire second website into a div or iframe of the first web page, similar to how a free proxy browser ...

IE compatibility with flexbox and columns

While everything is running smoothly on Chrome and Firefox, it seems that I have encountered a problem with IE (IE11). In my responsive layout, I am aiming for the menu to be horizontal in PC mode and vertical in tablet/mobile mode. It appears to be worki ...

The dropdown menu is not able to retrieve information from the secondary database

I have been encountering multiple challenges while working on a web-based dynamic form that I am developing. My current major issue is with populating the second #bodytype dropdown based on the selection made in the first, #bodyman, dropdown. Subsequently ...