Adjusting the space between horizontal rule lines

After following an online tutorial, I managed to put together the following HTML template:

body {
  font-weight: 200;
  font-size: 14px;
}

.header {
  font-size: 20px;
  font-weight: 100;
  text-align: center;
  color: #007cae;
}

.title {
  font-size: 22px;
  font-weight: 100;
  /* text-align: right;*/
  padding: 10px 20px 0px 20px;  
}

.title span {
  color: #007cae;
}

.details {
  padding: 10px 20px 0px 20px;
  text-align: left !important;
  /*margin-left: 40%;*/
}

.hrItem {
  border: none;
  height: 1px;
  /* Set the hr color */
  color: #333; /* old IE */
  background-color: #fff; /* Modern Browsers */
 }
 <div class='wrapper'>
     <div class='header'>
       <p class='title'>Invoice #<hr class='hrItem' /> </p>
     </div>
   <div>
   <div class='details'>
       Bill to: <br/>
       Amount:  <br/>
       Date: 
   </div>
</div>

Encountering an issue, I found that there was a substantial white space between 'Invoice #' and the horizontal rule which I struggled to remove. I experimented with adjusting the padding and margin within various CSS classes such as .hrItem, .title, and .header, but the problem persisted. As such, I am unsure if it is possible to eliminate this white space or if I need to explore alternative methods of incorporating the horizontal line.

Answer №1

To ensure valid HTML, make sure to place the <hr> outside of the <p> tag. Placing it inside can create an empty <p></p>:

https://i.sstatic.net/fc8OF.png

Here is the correct structure:

<div class='header'>
    <p class='title'>Invoice #</p>
    <hr class='hrItem' />
</div>

Once you make this adjustment, you can control the spacing between the .hrItem and .title by adjusting their margin properties to your liking:

body {
  font-weight: 200;
  font-size: 14px;
}
.header {
  font-size: 20px;
  font-weight: 100;
  text-align: center;
  color: #007cae;
}
.title {
  font-size: 22px;
  font-weight: 100;
  padding: 10px 20px 0px 20px;  
  margin: 0;
}
.title span {
  color: #007cae;
}
.details {
  padding: 10px 20px 0px 20px;
  text-align: left !important;
}
.hrItem {
  border: none;
  height: 1px;
  color: #333; 
  background-color: #fff;
  margin: 0;
}
<div class='wrapper'>
  <div class='header'>
    <p class='title'>Invoice #</p>
    <hr class='hrItem' /> 
  </div>
         
  <div class='details'>
    Bill to: <br/>
    Amount:  <br/>
    Date: 
  </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

Creating a secondary title for a Bootstrap Navigation Bar

I have a unique Bootstrap 4 website that features a navbar. The navbar consists of a special brand section with an image and title text, followed by the rest of the navbar elements. You can view it here: https://jsfiddle.net/zmbq/aq9Laaew/218793/ Now, I a ...

"Enhanced Bootstrap 4 table featuring a single column that stands out in size compared

I have set up a Bootstrap4 table with multiple columns, but I need one of them to be larger in order to accommodate more text. I want to specify the minimum width for this larger column and let Bootstrap4 adjust the sizes of the other columns accordingly. ...

Is the table not displaying properly in the print preview with a messy

I have a large table with multiple rows. Due to its length, I have provided a link to the jsfiddle where you can view it: jsfiddle. The table is structured in HTML and contains many rows with various attributes. <table> <thead>text here!</t ...

Ways to shorten text on mobile screens using CSS

Is it possible to use CSS to truncate text based on the current screen size or media queries? For example, consider this paragraph: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam porta tortor vitae nisl tincidunt varius. Lorem ipsum dolor ...

What is the best way to prevent the child elements from inheriting the hover effect of the main container?

Looking to spice up the appearance of the div element that holds the product's image, SKU, and price. Adding a hover effect to the main container causes the child divs to inherit it, resulting in separate hover effects on each child div. Sample HTML ...

Mobile devices not displaying background images correctly

My Wordpress website has a section with the code below, but the image is not adjusting properly on mobile phones. Can you provide some advice? .one_half_bg { width: 50%; float: left; background-position: 50% 50% !important; backgroun ...

Adding Components Dynamically to Angular Parent Dashboard: A Step-by-Step Guide

I have a dynamic dashboard of cards that I created using the ng generate @angular/material:material-dashboard command. The cards in the dashboard are structured like this: <div class="grid-container"> <h1 class="mat-h1">Dashboard</h1> ...

When implementing flex-grow 1 on a flex box, the remaining space is not being filled as expected

I am struggling to make the green div fill the remaining space of a flex box container. My goal is to have the top row (blue) adjust its height based on content, and then have the row below (green) take up the rest of the space. However, it seems like the ...

Connecting static CSS files to Django

I am fairly new to working with Django and I am having trouble linking CSS to my project. I have included the necessary static settings in my app's configuration, which allows me to access images in the static folder without any issues. However, when ...

With jQuery's .text() method, it is possible to modify the first span's Bootstrap class, but not the

As someone who is new to javascript, html, and jquery, I have been trying to change the text of 2 span elements in the same div using jquery's .text() command. Despite going through various solutions provided by different questions, none seem to work ...

Tips for concealing a div when clicking on an element solely with CSS

I am currently working on creating a CSS Main Menu in Vue. The functionality is such that it pops up when the mouse hovers over it, and hides when the mouse moves out. However, I am facing an issue with hiding the menu when clicking on a hyperlink a. Any s ...

Gather information using HTMLParser

<tr> <td style="color: #0000FF;text-align: center"><p>Sam<br/>John<br/></p></td> </tr> Utilizing the python's HTMLParser module, I am attempting to retrieve the entries Sam and John from the provided ...

What is the best way to choose a random number using jQuery?

<div class="yyy"></div> <p>...</p> <pre><code>let content = $(".xxx").text(); $(".yyy").html(content); http://jsfiddle.net/tQeCv/ I just require this specific input : Number is {1|2|3|4}, and {one|two|three|four} ...

When it comes to using brackets and HTML, I keep receiving an error message indicating that there is no index file

I'm having trouble with this code - it works fine in Code Academy, but I am new to HTML and trying to practice outside of the platform. Every time I try to live preview in Brackets, I get an error message saying "make sure there is an html file or tha ...

What is the best way to split a semicircular border radius in two equal parts?

Is there a way to halve the yellow line or remove it from above the red box, while keeping it below? Can this be achieved using just HTML and CSS, or is JavaScript necessary? * { margin: 0; padding: 0; box-sizing: border-box; } body { height: 1 ...

Is there a way to dynamically alter the heading color in Shopify liquid code?

After utilizing ChatGPT to review the code, I am uncertain if it is related to the color schemes. I am unsure of what I may be missing or doing incorrectly. While I can successfully alter the heading text, I am unable to change the color. Below is the code ...

What is the best way to divide a string into an array containing both linked and non-linked elements?

I'm struggling to find the right solution to my problem. I need to create a view that is enclosed in a clickable div. The content will consist of plain text mixed with clickable URLs - the issue arises when clicking on a link also triggers the method ...

Displaying information from a database in HTML dropdown menus and tables

Recently, I started learning PHP and I am facing a challenge with my database that has 5 columns: "id", "fldName", "fldPrice", "fldSupplier", and "fldPackage". In my HTML table, I have select options where I display "fldName" based on a specific value of ...

The automated test locator in Angular using Protractor is failing to function

I am facing a challenge with my angular web application as there are some elements that are difficult to interact with. One specific element is a checkbox that needs to be checked during testing: ` <div class="row form-group approval_label"> < ...

Ways to adjust the size of an HTML fieldset?

Is there a way to decrease the space between the paragraph and the border of this fieldset? I attempted to adjust the margins in the following manner: fieldset { margin: 1px; margin-top: 2px; border-top-right-radius: 1px; } <fieldset> < ...