The pseudo-element ::after will not be positioned below the specified element

https://i.sstatic.net/Dd7mO.pngI am trying to position the grey vertical line below the text "latest work". However, when I set the z-index to negative, it disappears. I believe it is going under the body. Is there a simple solution to this? Attached is an image of my mockup for reference. I have a div with a background color of #212121 so that the text "latest work" has padding above and below, giving the illusion that the line goes underneath.

body {
font-size: 16px;
background: #f9f9f9;
}
.container {
max-width: 1600px;
}

#dt-lpStatic {
height:60px;
width: 100%;
padding:6px 0;
font-family: 'Montserrat', sans-serif;
font-size: 0.875em;
text-transform: uppercase;
}
#dt-lpStatic ul {
float: left;
margin-top: 3px;
}
#dt-lpStatic ul li {
display: inline;
color:#545454;
margin-left:40px;
}
#dt-lpStatic ul li:nth-child(1) {
margin-left:0;
}
.subscribe-btn-muted {
padding:12px 50px;
border:2px solid #555;
border-radius: 13%/50%;
-webkit-border-radius: 13%/50%;
-moz-border-radius: 13%/50%;
float:right;
color:#555;
}
#hero {
width:100%;
background: #212121;
height:100vh;
}
#hero-content {
margin:30vh auto;
text-align: center;
}
#hero .secTitle-bg-dark {
width:200px;
padding: 15px 0;
font-family: 'Open Sans', sans-serif;
font-style: italic;
color: #555;
font-size: 1.5em;
font-weight: 300;
margin:30vh auto;
background: #212121;
}
.secTitle-bg-dark:after {
    content:"";
    position: absolute;
    z-index: 0;
    top: 65vh;
    bottom: 0;
    left: 50%;
    border-left: 2px solid #313131;
}
<body>
<section id="hero">
<header id="dt-lpStatic">
<div class="container">
<ul>
<li><img src="imgs/logo-muted.png" alt="RH logo"></li>
<li>Home</li>
<li>Blog</li>
<li>About</li>
<li>Get In Touch</li>
</ul>
<div class="subscribe-btn-muted">Subscribe</div>
</div>
</header>
<div id="hero-content">
<img src="imgs/logo-full-big.png" alt="RH Visual Design logo">
<div class="secTitle-bg-dark">latest work</div>
</div>
</section>
</body>

Answer №1

Using flexbox is a fantastic option for this situation. By simply making a few adjustments to the code, you can greatly streamline it:

Note: Quick tip - When using Psuedo-elements, make sure to use double colons (::) like ::before and ::after. Psuedo-selectors only require one colon, such as a:hover and input:focus.

body {
  background-color: #333;
}

.latest-work {
  color: #999;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.latest-work span {
  display: block;
  padding: 10px 0;
}

.latest-work::before,
.latest-work::after {
  width: 1px;
  height: 100px;
  content: '';
  background-color: #999;
}
<div class="latest-work">
    <span>latest work</span>
</div>

Answer №2

To achieve a block layout, ensure that you include display: block; in the :after element as pseudo elements require this declaration.

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

Removing the pound sign from the URL in location hash

function updateView(category) { console.log( window.location.hash ); if (location.hash !== ""){ //convert #3 to 3. //load video based on id //myArray[sanitizedHash]; } else { updateCategoryLabel(category); currentList = updateVi ...

Flexbox does not support sub-columns

I'm having trouble integrating these two columns along with their sub-columns. I have to resort to using this structure instead: <div class="custom_classes"> <div class="custom_classes">col1</div> <div class=&q ...

download image using React map method

I am trying to transfer an image from one useState variable to another when it is clicked const [photos, setPhotos] = useState([]); useEffect(() => { setPhotos(PhotoArray); }, []); This is the source image that I am using: export const PhotoArr ...

When CSS width:auto expands beyond its intended length

I'm experiencing an issue when I set the width to auto, the div expands to full length rather than adjusting to the width of the inner divs. Here is the HTML code: <div class="vidswraper"> <div> <div class="videoimage"> <img src ...

Styling tables with borders in CSS

If a table is set to have a border at a high level, how can I ensure that classes inheriting from it do not have any borders set? table,td,th { border: 1px solid #0B6121; } How can I make sure that my other table has no borders at all? table.menu { ...

Using jQuery to modify CSS properties in the propertyName

With jQuery v1.6.4, I am attempting to dynamically format some objects. Take a look at my code snippet: <html> <head> <script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script> <script type="text ...

JQuery Scroll Spy Implementation

I have structured the page with a header at the top and 3 columns below. The left column contains a menu, the middle column is a text container, and the right column is another section. As the page scrolls up, the menu becomes fixed in position which func ...

Switching between play and pause for the video element using a component for the child

Trying to toggle the play/pause of a child video by clicking on a parent div can be challenging, especially when dealing with multiple instances of the same div and video. A normal function may only work for one specific video, as mentioned by @ken. I hav ...

Present Images and Text Alongside Each Other in a Grid Layout

My goal is to have an image and text displayed side by side, but for some reason they are appearing stacked on top of each other. https://i.stack.imgur.com/F8OXL.png If you want to take a look at the code I am using, here is the link to my CodePen: https: ...

The astonishing font-icon animation feature is exclusively functional on code-pen

I have a problem with a font-icon animation code. When I run it on my local server, the animation doesn't work. It only works on http://codepen.io/TimPietrusky/pen/ELuiG I even tried running it on http://jsfiddle.net/qjo7cf3j/ @import url(http: ...

What causes my paragraph textContent to vanish after briefly displaying its value?

As a beginner in JavaScript and HTML, I am taking on the challenge of learning these languages from scratch independently. I have encountered an issue with my code where the word "Hi!" briefly flashes below the "Click Me!" button before disappearing compl ...

Enhance your web form with the Bootstrap 4 tags input feature that allows users to add tags exclusively

I'm currently utilizing Bootstrap 4 along with Bootstrap Tags Input to create a multiple category selection feature. My goal is to enable users to choose multiple items exclusively from the predefined categories listed in the predefined_list. At pres ...

What are my choices for showcasing hierarchical information?

I'm currently working on organizing hierarchical data using HTML, JS, and jQuery. My chosen method involves utilizing a left-floated div container system in place of a grid system for easier recursive code generation. One challenge I've encounter ...

How can one effectively manage a dynamic web element ID and xpath as they evolve?

After generating an XPath for a dynamic web element, I came across two nodes that are strikingly similar. The XPath used is: //*[contains(@id, "gwt-uid-")]/span[2]. Despite my best efforts to distinguish between the two nodes, I have not been successful. A ...

Using Selenium to scroll down to an element until its 'style' changes

I'm in the process of scraping a review page similar to this one. While this specific page has only a few reviews, there are others with a larger volume that require extensive scrolling. Upon observation, I noticed that when the page is not complete ...

The initial website design only occupies half of the webpage with HTML

My code is only filling up half the screen, specifically the left half but not the right. I attempted to set the html height and width to 100%, but unfortunately, it did not resolve the issue. Additionally, after this adjustment, I encountered problems wit ...

Guide to concealing pop-up with animation when clicking outside

My question is: Clicking on OPEN should open the popup. Clicking on BACK should close the popup. Clicking outside the popup should also close it. Note: Clicking inside the popup when it is open should not close it. The popup should only close on an outs ...

Tips on customizing styles for Material UI components using CSS override techniques

Currently, I am tackling a project that requires the use of Material UI components. To simplify things, let's focus on a basic functional component that includes two Material UI elements: a Button and a Text Field. import React from 'react'; ...

Is the Piecemaker flash slider being obstructed by its container?

I am currently integrating the Piecemaker flash slider into my new project for the very first time. Unfortunately, I'm facing an issue where the animation is getting cut off by the dimensions of its container. I've been struggling to figure out h ...

Menu collapse button failing to Show content

My navigation menu button is not functioning correctly. I am currently working on this project using CodePen, so Bootstrap is already integrated into the code. <div class="navbar-header"> <button type="button" class="btn navbar-toggl ...