What is the proper way to implement a divider in HTML5?

Looking for advice on how to effectively use dividers positioned at the center of a page? Specifically, I am interested in having two dividers: one measuring 200px wide and another measuring 500px wide, both with a 5px top margin. These dividers should be placed in the center of the page as depicted in the image below.

<section>
<article>
<p>texttext text </p>
<div id="divider">
<div id="divider-short"> </div>
<div id="divider-long"> </div>
</div>
</article>
</section>

    #divider{
float:right;
margin-right:35%
direction:rtl;
}
#divider-short{
width:150px;
border:2px solid gray;
margin-top:30px;
clear:both;
}
#divider-long{
margin-top:10px;
width:300px;
border:2px solid gray;
clear:both;
}

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

Answer №1

For a simple way to add dividers in your layout, you can create a common divider class and apply it wherever you need a divider.

.divider{
  padding-bottom:25px;
  position:relative;
}
.divider:before,.divider:after{
  width:300px;
  height:2px;
  background-color:red;
  display:inline-block;
  content:"";
  position:absolute;
  bottom:8px;
  margin-left:auto;
  margin-right:auto;
  left:0;
  right:0;
  
}
.divider:before{
  width:200px;
  bottom:14px;
}
<section class="divider">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</section>
<section class="divider">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</section>
<section >Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</section>

Answer №2

To enhance the overall design, I suggest replacing the divider HTML with this CSS code (make adjustments for colors, spacing, etc):

section {
  position: relative;
  padding-bottom: 30px;
}
section:before {
  content: '';
  position: absolute;
  width: 100px;
  background: grey;
  left: 50%;
  transform: translateX(-50%);
  height: 4px;
  bottom: 20px;
}
section:after {
  content: '';
  position: absolute;
  width: 200px;
  background: grey;
  left: 50%;
  transform: translateX(-50%);
  height: 4px;
  bottom: 10px;
}

Answer №3

My recommendation is to utilize the <hr/> element specifically designed for creating breaks in content. For instance, you can achieve a double line break of varying lengths by implementing the following code:

<hr style='width:35%'/>
<hr style='width:70%'/>

This is just a simple illustration of how to customize the appearance of the hr tag to match other styling on your webpage.

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

Troubleshooting the z-index issue with CSS checkbox hack

Using the css "checkbox hack" to trigger the display of a form when a label is clicked. The form is styled using a :before pseudo element to create a transparent background, but the z-index is not working as expected. Despite adjusting z-index values, the ...

Create personalized styles for each item within a stack with specific spacing using the @mui library

Is there a way to change both the background color and spacing area when hovering over each item in my list? https://i.stack.imgur.com/87TST.png <Stack spacing={4} divider={<Divider variant={`fullWidth`} orientation={`horizontal`} flexItem/>}> ...

Is there a way for me to extract the content from a table within an HTML document?

My goal is to extract data from , specifically focusing on the placement and points earned by a specific player. Upon inspecting the HTML code of the website, I located the details related to the player "Nickmercs" as follows: HTML Text The rank was displ ...

I Am unable to locate the '...' after applying the text-ellipsis style to a div

https://i.stack.imgur.com/Tsmf5.png The ellipsis '...' is not showing up even after I have applied text-ellipsis, overflow hidden, and nowrap to this div. Take a look at my code: import Image from "next/future/image"; import Link from ...

Master the art of directing your attention to a list element with ease using the tab function and jQuery

I've been tasked with creating a questionnaire for a client. They want the current active question to be displayed at 100% opacity, while the inactive questions should be at 20% opacity. Currently, when the page loads, all questions are dimmed to 20% ...

Changing the Displayed Content with a Simple Click of a Link

Layout Overview In the process of developing a tool to streamline work tasks, I want to ensure that I am following best practices. My goal is for the website to initially display only column A, with subsequent columns generated upon clicking links in the ...

Struggles with organizing tables in asp.net

My apologies for my lack of knowledge in this area, but I am struggling to make my table look correct on my webform. I begin by creating a table: <table> </table> And I want to add a border. The traditional way is to use the 'border&apo ...

Is there a way to make the iOS Safari address bar shrink when scrolling, all while having a flexbox sticky footer inside a container?

I have implemented a standard flexbox sticky footer solution in my code: <body> <div class="wrapper"> <div class="header">Page Header</div> <div class="body"> <div class="b ...

Could images be positioned in this manner without using the float property?

Looking to arrange images in a left-to-right flow while keeping them centered on the screen: https://i.stack.imgur.com/WHBv9.png However, I'm struggling to achieve this as the last image always ends up centered horizontally as shown below: https://i ...

How can I close the menu when a menu item is clicked in a React.js application?

I am facing an issue where I want to close the menu when clicking on any menu item in React JS. The functionality works fine with a button icon but not with individual menu items. How can I resolve this problem? I have been trying to implement it using CSS ...

What is the most effective method for determining the distance between two UK Postcodes?

Can you suggest a reliable method for calculating the distance between two UK postcodes in order to determine if they are within range? I do not intend to display a map, but instead provide a list of results for valid locations. For example, showing loca ...

Identify all anchor elements that contain image elements

I am on the hunt. I am looking for a CSS-Selector, but if that's not an option, a jQuery selector would work too. ...

The jquery UI button is displaying too wide even though the padding is set to zero

My goal is to decrease the width of certain jQuery buttons. Though I have attempted to eliminate padding using the code below, there remains a minimum of 5 pixels on either side of the text within my button. .button().css({ 'padding-left':' ...

Creating a seamless integration of header, content, and footer components within html2pdf

After creating an HTML page, I utilized the html2pdf library to convert it into a PDF format. Here is the code snippet: <?php require('../admin/html2pdf/html2pdf.class.php'); ob_start(); ?> <page> <page_head ...

What is the best way to incorporate an onmouseover event so that when the mouse hovers over an image, play/stop/pause buttons are displayed

Furthermore, each button should trigger an event on click. When the pause button is clicked, the button text should toggle between pause and continue, and the action should correspond to the displayed text. This is the HTML code I currently have: Includi ...

Make the width of a table column match the width of the header

I am currently using Primeng2 datatable and I am looking to adjust the column width to match the header size. This is my HTML code: <p-dataTable #dtselfcollectmonthly [exportFilename]="exportname" [rows]="10" [value]="rawdatatrucks"> <ng-con ...

What is the best way for me to automatically square a number by simply clicking a button?

How do I create a functionality that multiplies a number by itself when a specific button is clicked? I want this operation to only occur when the equals button is pressed. I have been attempting to set this up for over an hour without success. My current ...

Troubleshooting: How the Mozilla scrollbar is affecting the positioning of my elements (with jsfiddle

I need assistance with my code on both Chrome and Mozilla browsers. The layout looks perfect in Chrome, but in Mozilla, the scrollbar is affecting the positioning of my list elements. Could someone please help me figure out how to make it consistent acros ...

Tips for triggering jquery code when a variable containing a CSS attribute is modified

I have a specific requirement where I need to reset the scrollleft value to 0 on my wrapper whenever a particular CSS property changes. Although I am new to using jQuery and haven't worked with variables much, I believe I need to create a variable to ...

The issue of excessive vertical spacing occurring between two <div> elements, with one of them containing an <iframe> element, needs to be addressed

I am facing an issue with unwanted vertical spacing between two elements. One of them has a <p> element, and it seems like it's getting stuck there. The problem only arises on larger screens (> 15"), while it looks fine on smaller screens. Th ...