What is the best way to make a vertical line using the CSS code provided in the link?

Check out this cool horizontal line design I found on stackoverflow:

Click here for CSS code to create the line

I really like the look of the line. Here's how I implemented it on my website:

hr.fancy-line { 
    border: 0; 
    height: 5px;

}
hr.fancy-line:before {
    top: -0.5em;
    height: 1em;
}
hr.fancy-line:after {
    content:'';
    height: 0.5em;
    top: 1px;
}

hr.fancy-line:before, hr.fancy-line:after {
    content: '';
    position: absolute;
    width: 100%;
}

hr.fancy-line, hr.fancy-line:before {
    background: radial-gradient(ellipse at center, rgba(0,0,0,0.1) 0%,rgba(0,0,0,0) 75%);
}

body, hr.fancy-line:after {
    background: #f4f4f4;
}
-Some Text-
<hr class="fancy-line"></hr>

Now, I'm curious about creating vertical lines using a similar concept. If you're interested in seeing how I used the horizontal lines on my site, check out this link.

Answer №1

My approach was to style the element with a slim width and an elongated height.

Yet, crafting a vertical line using an <hr> tag may lack semantic meaning, so it could be more appropriate to utilize a <span> or another suitable element.

body {
  background: #f4f4f4;
}
hr.fancy-line {
  border: 0;
  height: 180px;
  width: 5px;
  margin: 0 auto;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 75%);
}
<hr class="fancy-line"></hr>


The method for creating these lines should align with the specific context in which they are used. For instance, if the lines are intended to separate elements on a page, a possible solution is to generate them as pseudo-elements, as shown below:

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
ul li {
  position: relative;
  display: inline-block;
  width: 180px;
  height: 180px;
  background-color: #CCC;
}
ul li:not(:last-child) {
  margin: 0 1em 0 0;
}
ul li:not(:last-child):after {
  content: "";
  position: absolute;
  left: 100%;
  margin-left: .5em;
  height: 100%;
  width: 4px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 75%);
}
<ul>
  <li></li>
  <li></li>
  <li></li>
</ul>

Answer №2

The horizontal line you are observing is displayed because web browsers interpret the <hr> (horizontal ruler) elements in this way as defined by the HTML specification.

Unfortunately, there is no <vr> element or equivalent in HTML, so an alternative approach would need to be devised for that specific function.

Answer №3

To enhance the design of your website, consider adding a stylish border to the left or right side of a division element that encompasses all content within your webpage (or adjust the height property to 100%).

Answer №4

To achieve a 90-degree rotation of the hr, you can use the following CSS:

hr.fancy-line {
  transform: rotate(90deg);
}

hr.fancy-line { 
    border: 0; 
    height: 5px;

}
hr.fancy-line:before {
    top: -0.5em;
    height: 1em;
}
hr.fancy-line:after {
    content:'';
    height: 0.5em;
    top: 1px;
}

hr.fancy-line:before, hr.fancy-line:after {
    content: '';
    position: absolute;
    width: 100%;
}

hr.fancy-line, hr.fancy-line:before {
    background: radial-gradient(ellipse at center, rgba(0,0,0,0.1) 0%,rgba(0,0,0,0) 75%);
}

hr.fancy-line {
  transform: rotate(90deg);
}

body, hr.fancy-line:after {
    background: #f4f4f4;
}
-Modified Content-
<hr class="fancy-line"></hr>

Answer №5

To create a vertical divider in HTML, you have three choices:

If you want to ensure compatibility with older browsers, use the following CSS code:

 hr {
    display: inline-block;
 }

For modern browsers, you can simply rotate the divider using the transform property:

hr {
    transform: rotate(90deg);
 }

Alternatively, you can set a small width and large height for the horizontal ruler:

hr {
   width: 5px;
   height: 200px;
}

Answer №6

Shoutout to @showdev and @Cayce K.

I finally found what I've been searching for.

For those interested in something similar in the future, here's the code:

body {
  background: #f4f4f4;
}
hr.fancy-line {
  border: 0;
  margin: 0 auto;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0) 75%);
}
<hr class="fancy-line" style="height: 100px; width: 5px;"></hr>

I adjusted the height and width in the html line to create vertical lines of varying dimensions on different pages.

Big thanks to everyone else who helped out. This was my very first question on stackoverflow, and I'm thrilled with the responses. Cheers!

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

Enlarge the image to fill the entire screen

Currently, I am working on a webpage where I am displaying data fetched from a database using Laravel framework. The code snippet is shown below: Here is how the webpage looks like - image1 What I aim to achieve is to make the div go fullscreen upon clic ...

Navigating Through the DOM with Selenium using XPath Axes

Currently, I am developing Selenium tests for a dynamic web page. Within this section of code, I am extracting data from an Excel sheet and verifying if a specific element exists on the webpage. I have annotated the critical part of the code with comments ...

What is the process of converting the string 'dd/mm/yy hh:MM:ss' into a Date format using javascript?

I successfully completed this task. var date = 'dd/mm/yy hh:MM:ss'; var dateArray = date.split(" "); var splitDate = dateArray[0].split("/"); var splitTime = dateArray[1].split(":"); var day = splitDate[0]; var month = sp ...

Identify the moment a dialogue box appears using jQuery

I'm facing a situation where multiple dialogs are opened in a similar manner: $("#dialog").load(URL); $("#dialog").dialog( attributes, here, close: function(e,u) { cleanup } The chall ...

The peculiar behavior of Google Maps markers refreshing inconsistently upon bounds adjustment

I recently completed a project involving a restaurant app using Vue and Google Maps. While everything is functional, I have encountered a persistent bug with the markers. When navigating on the map and the bounds change, some markers seem to disappear. Ev ...

Error: "Access-Control-Allow-Origin" header is missing in Firebase Function

I have encountered an issue with my firebase functions GET request. While I am able to receive data using Postman, I am facing difficulties when trying to fetch data from my front-end application. Upon accessing the endpoints, I am seeing the following er ...

Having trouble with Angular2's Maximum Call Stack Exceeded error when trying to display images?

I am facing an issue in my Angular2 application where I am trying to display an image in Uint8Array format. The problem arises when the image size exceeds ~300Kb, resulting in a 'Maximum Call Stack Exceeded' error. Currently, I have been able to ...

Javascript is not fetching the value

Here is the code snippet I am working with: var categoryDetailId = $("#createEventForm-categoryDetail-idCategory").val(); and this link from my rendered page: After clicking the button, it returns NaN Update: I tried setting it manually, but it still ...

What is causing the error message stating that the DateTime class object cannot be converted to a string?

I found this code snippet on a programming forum function increaseDate($date_str, ${ $date = new DateTime($date_str); $start_day = $date->format('j'); $date->modify("+{$months} month"); $end_day = $date->format(&apo ...

Unable to locate the value property of a null object

I'm currently working on creating a Shopping Cart using HTML, CSS, JavaScript, and JQuery. The idea is that when you click "Add to Cart" for the orange item, most of the HTML elements will disappear, leaving only the table displaying the Shopping Cart ...

Static response is the way to go! Asynchronous responses just don't cut it

Currently in the process of developing an angular directive for displaying real-time charts. Below is the code snippet that encompasses everything, including link: function() { }, within the directive. Here's the code for a static directive that func ...

Is fs-extra the best tool for working with a .bundle file?

I am attempting to determine whether a specific folder in my project includes a .bundle file and, if it does, relocate it to another location. If the file is not found, I will use a default option instead. The problem I'm encountering is that I am una ...

Selected Angular Radio Button

Back in the good ole days of basic HTML and CSS, I was able to achieve the following: input:checked+label { background-color: #f00; } <div class="col-xs-6"> <input type="radio" id="template-1" name="template" value="template1" checked> ...

Decrease the gap between rows in CSS Grid

I'm struggling to minimize the space between the rows. I've attempted adjusting margins and paddings to 0, but nothing seems to be working effectively. Displaying desktop view on the left and mobile view on the right side. https://i.sstatic.net ...

Advanced Techniques: Leveraging Master Layouts, Partial Rendering, and JavaScript Function

Trying to understand the sequence of events when a master page, partials, and JavaScript code are involved. Imagine having a Master page with scripts: <%@ Master Language="C#" ... %> <head> <asp:ContentPlaceHolder ID="HeadContent" run ...

What is causing the error message 'undefined is not a function' to appear in my code?

Struggling to send a file in response to a GET request with express.js. I created a basic FileManager class to manage file requests, yet encountering an error of 'undefined is not a function' when calling new FileManager() Here's my approac ...

Using varied colors to style list items

Is there a way to apply three different colors to my list items? What is the best method for achieving this? This is what I have in my code: li { width: 33.333%; float: left; padding: 15px; list-style: none; } .light { background-color: #0 ...

The scale line on the OpenLayers map displays the same metrics twice, even when the zoom level is different

When using the Openlayers Map scale line in Metric units, a specific zoom rate may be repeated twice during the zoom event, even though the actual zoom-in resolution varies on the map. In the provided link, you can observe that the zoom rates of 5km and ...

Customizing the Zoom Control Style in Vue Leaflet

I'm currently working on developing a Map App in Dark Mode using Vue, but I've encountered an issue with changing the style of the Zoom Control. Here's what I have tried so far: template> <div class="main-map"> <l ...