Div containing text above a horizontal line

Is there a way to achieve this effect using the <hr> tag? I want the content of a div to appear over the <hr>. Any suggestions on how to accomplish this?

I've created a jsfiddle here: http://jsfiddle.net/fnaYs/. I'm struggling to figure out how to place this text inside an image box. Any ideas?

Furthermore, once I achieve the desired layout, I plan to integrate it into Wordpress. Therefore, I want to ensure that the text is contained within a <div> or another element, rather than solely in the css file.

Answer №1

By assigning the position attribute of a variable to relative, you are essentially stating that the element's position is relative to the browser.

Therefore, when specifying top:-5px;, you are instructing the browser to place your element 5 pixels above its intended location.

To achieve this effect, simply set the top attribute for the div in CSS to a negative value, like so:

<hr />
<div style="position:relative;top:-5px;">DIV CONTENT</div>

Feel free to replace the -5px with your desired adjustment.

Answer №2

After some coding, I managed to come up with a solution (although there may be other approaches).

If you want to see it in action, check out this JSFiddle: http://jsfiddle.net/fnaYs/6/

CSS

.line {
    padding: 0;
    border: 1px solid;
    color: #333;
    text-align: center;
}

.box {
    background-color:teal;
    width:100px;
    height:30px;
    position:absolute;
    left: 40%;
    bottom:90%;
    padding-top:20px;

}

HTML

<hr class="line"/>
<div class="box"> Text </div>

Answer №3

Check out this helpful jsFiddle link for the solution: http://jsfiddle.net/8AbCd/

<hr class="divider" />
<div class="content">Content inside div</div>

Here is the corresponding CSS code:

    hr.divider {
    padding: 0;
    border: 1px solid;
    color: #333;
    text-align: center;
}

    .content {
background: blue;
    border: 2px dashed blue;
    width: 150px;
    position: relative;
    top: 50px;
}

This code will give you the desired output as shown in the example.

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

The Bootstrap card becomes compressed when conducting a search within the card grid

After inserting a new image into a card, I noticed that the card gets distorted when I perform a search. I'm unsure if this issue is related to Bootstrap's grid or the image size itself. Any suggestions on how to rectify this would be greatly app ...

Is there a way to extract the properties of a CSS class from a stylesheet and convert them into a hash using JavaScript or jQuery?

I am exploring a way to extract key value pairs from a CSS stylesheet related to a specific class or id into a JavaScript object for data accessibility. It is important to mention that I do not intend to apply this class directly to any DOM elements. In ...

How can I ensure that my HTML page remains live at all times?

I've been scouring the internet trying to find a solution to my problem: What I'm looking to do is create a method for keeping an HTML page on a live production site constantly updated. I have a SilverStripe Application that is part of a graphic ...

Ensure that clicking on various links will result in them opening in a new pop-up window consistently

I am facing an issue with my HTML page where I have Four Links that are supposed to open in separate new windows, each displaying unique content. For instance: Link1 should open in Window 1, Link2 in Window 2, and so on... The problem I'm encounter ...

What steps do I need to take in order to change an HTML div's background to a black

My current project involves dynamically loading HTML content stored on disk into a specific div element. This is achieved by using the following code: $('#FictionContent').load('Content/HuckFinn.html'); Just to provide some background ...

Can nested divs in an HTML document be styled using Flexbox?

I'm currently attempting to design a layout with two columns, displaying only two items per row. I came across a solution on StackOverflow that aligns child elements of different blocks, but unfortunately, it doesn't apply to my HTML structure. ...

Having trouble setting the background of a div in CSS

How can I apply the background-color: #f8f8f8 class to the step class without interfering with the display of the horizontal lines after 1, 2? What could be causing this issue? .main-progress { text-align: center; position: relative; margin- ...

Tips on removing pesky favicons

Not too long ago, I purchased a domain and configured it with Wordpress. Eventually, I decided to switch to a static landing page so I uninstalled Wordpress. But now there's an unfamiliar favicon that has appeared on my site. Even after deleting all ...

Centered content appears smaller than the surrounding div

After spending an hour trying to troubleshoot and searching for solutions, I am turning here for help. I am attempting to insert a Bootstrap Nav-Bar into a Div. I successfully centered the Nav-Bar, but now my Div is taller than the content inside it. This ...

Engage the PROTRACTOR refresh function

I'm just getting started with automation and Protractor. I successfully automated the login page, but now I'm facing a challenge with accessing a menu that I need in order to navigate to a different page. Within the menu, there is an href="#/dom ...

Tips for adding a cache to a basic website

After completing the development of a frontend website that includes several images, I am concerned about potential slower load times. I have not yet tackled backend coding tasks and am now looking to implement a caching system on the frontend. Are there ...

Issue with Rendering Rapheal Pie Chart in Internet Explorer 9

I encountered an issue in IE9 where I received the error message "SVG4601: SVG Path data has incorrect format and could not be completely parsed" while trying to draw a pie chart on an HTML5 page using Raphael JS and SVG. The problem arose when the "d" att ...

Unraveling the mysteries of Google web application parameters

I am currently in the process of gaining a better understanding of the Google web applications. The HTML source I am looking at contains JSON data that has been encoded in a way that is unfamiliar to me and I am seeking to decode it. The HTML source includ ...

The media query targeting a specific max-width and below appears to be malfunctioning

So, I'm experiencing an issue where the browser I'm using doesn't seem to be picking up the styles I've set for a max-width of 960px and below. Can anyone provide insights into what might be causing this? Any assistance would be highly ...

Ways to modify CSS rules by adding or removing the !important declaration in new CSS

For my project, I am using the `bootstrap-next-table` table in various places and have customized a CSS class to fit my needs. The issue I am currently encountering is that one component requires the default CSS class which I had overridden: .table > t ...

What is the best way to hide the select arrow in an input-group using Bootstrap 4?

Is there a way to get rid of the unsightly double arrow in the select element? I have tried various solutions I found online, but none seem to be effective. <div class="form-group"> <label for="date">Date</label> <d ...

"Title, background hue 3, and color lined up in a single

.title { background-color: #FFC20E; font-size: 23px; font-weight: 600; padding: 5px 0px 5px 22px; font-family: "Open Sans"; } <h3 class="title">Title</h3> I need to create a title with a unique background color, can you ple ...

Inserting data into a JavaScript database

When attempting to add a new row to a datatable and submit it to a JSP for database insertion, an error is encountered. The error message reads: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the r ...

Clicking on a marker in Google Maps will display the address

I have a map that contains several markers, each designated by their latitude and longitude coordinates. I would like to be able to see the address associated with each marker when I click on it. However, I am currently experiencing an issue where nothing ...

Having trouble with elFinder? Encountering an error stating "Undefined is not a function" when attempting to

I am currently in the process of integrating the elFinder file manager into my project. Here is a summary of what I have accomplished so far. I have included the following files: $arr_css = array( "main.css", "jquery-ui.cs ...