The container size is not being recognized by the Pseudo Element with 100% width

I am currently using a pseudo element (before) to add a border on top of a container within a two column layout. My goal is to have the border only appear on one specific container.

Since I have set the width of the pseudo element to 100%, shouldn't it automatically adjust to match the width of the container that it resides in?

#singleWrapper {
  margin: auto;
  max-width: 1100px;

}
.single #singleWrapper {
  margin: auto;
  max-width: 1100px;
  /*box-shadow: inset 0 650px rgba(0,0,0,0.30);*/
  position: relative;
  overflow: hidden;
}
#leftColumn .content-area {
  padding-right: 310px;
  width: 100%;
}
.articleWrapper:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  background: #009cff;
  background: linear-gradient(to right, #1d0027, #935cd2, #1d0027);
  height: 2px;
  width: 100%;
}
#leftColumn .content-area #main {
  background: #000;
  background: rgba(0, 0, 0, 0.30);
  padding-left: 20px;
  padding-right: 20px;
}
#singleWrapper .contentHolder {
  margin-right: -310px;
  width: 100%;
  float: left;
  position: relative;
}
#rightColumn {
  float: right;
  position: relative;
  display: block;
  width: 290px;
}
#leftColumn,
#rightColumn {
  display: inline-block;
  vertical-align: top;
  margin-top: 1.1em;
}
<div id="singleWrapper">
  <div id="leftColumn" class="contentHolder">
    <div id="primary" class="content-area">
      <main id="main" class="site-main" role="main">
        <div class="articleWrapper">
          <h1>Title</h1>
          <div class="articleBody">
            Article Body
          </div>
        </div>
      </main>
    </div>
  </div>
  <div id="rightColumn">
    Side Bar Area
  </div>
</div>

Answer №1

the issue lies in your usage of position:absolute

Refer to MDN

Absolute positioning

Elements with relative positioning are still part of the normal flow of elements within the document. Conversely, an element with absolute positioning is removed from the flow and does not occupy space when positioning other elements. The absolutely positioned element is placed relative to the closest positioned ancestor. If there is no such ancestor, it defaults to the initial container.

To resolve this, include the following in your CSS:

.articleWrapper {
  position:relative;
}

and modify top:0; in .articleWrapper:before to a negative value of your choice.

below is a code snippet for reference

#singleWrapper {
  margin: auto;
  max-width: 1100px;
}
.single #singleWrapper {
  margin: auto;
  max-width: 1100px;
  /*box-shadow: inset 0 650px rgba(0,0,0,0.30);*/
  position: relative;
  overflow: hidden;
}
#leftColumn .content-area {
  padding-right: 310px;
  width: 100%;
}
.articleWrapper {
  position:relative;
}
.articleWrapper:before {
  content: "";
  position: absolute;
  top: -30%;
  left: 0;
  background: #009cff;
  background: linear-gradient(to right, #1d0027, #935cd2, #1d0027);
  height: 2px;
  width: 100%;
}
#leftColumn .content-area #main {
  background: #000;
  background: rgba(0, 0, 0, 0.30);
  padding-left: 20px;
  padding-right: 20px;
}
#singleWrapper .contentHolder {
  margin-right: -310px;
  width: 100%;
  float: left;
  position: relative;
}
#rightColumn {
  float: right;
  position: relative;
  display: block;
  width: 290px;
}
#leftColumn,
#rightColumn {
  display: inline-block;
  vertical-align: top;
  margin-top: 1.1em;
}
<div id="singleWrapper">
  <div id="leftColumn" class="contentHolder">
    <div id="primary" class="content-area">
      <main id="main" class="site-main" role="main">
        <div class="articleWrapper">
          <h1>Title</h1>
          <div class="articleBody">
            Article Body
          </div>
        </div>
      </main>
    </div>
  </div>
  <div id="rightColumn">
    Side Bar Area
  </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 notification for specific choices in a dropdown menu

I am working on a form that includes a select element with multiple options. Depending on the option selected, a different form will be displayed. My concern is if a user starts filling out one form and then decides to select another option, I want to add ...

How can a div fill the remaining vertical space, despite the dynamic height of the div above it?

Check out my code snippet on JSFiddle: http://jsfiddle.net/nom4mxLt/ <div id="wrapper"> <div id="yellow">variable height (I put 200px but can change in realtime)</div> <div id="red">This one should fill all remaining space ...

Design a unique border for a div element that extends a top-border all the way through the header and a bottom-border that

I am trying to achieve the design displayed in this mockup: https://i.sstatic.net/sYEPu.png Here is my current progress: https://codepen.io/raney24/pen/VOmjBY .header-border { width: 100%; margin-bottom: 10px; border-left: red solid 1px; border ...

Setting up the Bootstrap grid structure

Struggling to find the right configuration for this Bootstrap 3 setup... https://i.stack.imgur.com/ZsTdI.png I have an input field, but I'm having trouble placing the image in that position. <div class="row"> <div class="col-sm-4 col-m ...

Utilizing HTML Entities in jQuery

Is there a way to update the text of a submit button to display "Loading..." instead of "…" when clicked? Currently, I am encountering an issue where clicking the button still shows "…" instead of three dots. Below is the code snippet in qu ...

Invoke functions within a separate function

I am facing an issue when it comes to invoking functions within another function. Below is a snippet of the code I am working with: <script> function saveInfo() { function returnEmail() { var _e = document.getElementById("em ...

A guide on toggling the visibility of a div based on media query conditions

This div should only be visible on mobile and tablet screens, not above 992px. <div class="nav-button but-hol"> <span class="nos"></span> <span class="ncs"></span& ...

When a user chooses an item, the ui-select dropdown appears hidden behind additional fields on the screen

In my AngularJS application, I am utilizing ui-select within a table that repeats rows using ng-repeat. The following code snippet displays how ui-select is implemented: <ui-select name="{{'selProperty' + $index}}" ng-model="thing.property" ...

Increasing Taxes and Boosting the Overall Cost

How can we set up a system where taxes are bypassed by default unless otherwise specified when placing an order? Let's take a look at the following text box: <input class="txt1" type="text" name="subtotal" value="" id="subtotal" size="16" ta ...

Ways to retrieve attribute value in Selenium python without the use of .get_attribute() method

I am new to posting questions, so please let me know if I need to provide more clarification. I am also a beginner in Python, so I hope that I am using the right terms to phrase my question. Essentially, I have developed a customizable web scraper that re ...

Swapping out the video in real-time using an on-demand script

Recently, I encountered an issue with my blog's YouTube video switcher. It seems that the videos won't play once they are changed, and it is related to a light YouTube embed script that I found here: . I believe this script was implemented to imp ...

Presenting data in various formats

I've got a JSON file with a list of data that includes months and years. I want to display all the months, but have the year only appear once in a big block area. Here's an image example: https://i.stack.imgur.com/Ps3OF.png The image demonstrates ...

Ensuring that a header one remains on a single line

Within this div, I have set the width and height to be 250px. Specifically, the h1 element inside the div has a height of 50px. Users who are updating content on my website can input any text they desire within this box. However, when the text within the ...

Preserve menu settings by utilizing local storage

I have been working on saving the state of my menu using localstorage. The jQuery code below is what I am currently using to toggle my menu: <nav id="sidebar" class="active"> <ul class="menu"> <li> <a href="#">Customer ...

I am experiencing issues with my button not responding when I click on the top few pixels

I've created a StackBlitz version to illustrate the issue I'm facing. It seems like the problem might be related to my CSS for buttons... Essentially, when you click on the button at the very top few pixels, it doesn't register the click an ...

Create a dynamic jQuery gallery with generated content

Currently I am working on a personal project and facing challenges in creating the correct markup using jQuery. I have an operation that provides a list of images to be displayed in this JSON format: [{ "Id": imageid, "imagePath": path to image, ...

Utilizing the active tab feature within CSS

I am currently working with a detailed structure of bootstrap theme classes. Currently, I am in the process of designing a menu. This is the code snippet for the navigation bar design in Bootstrap- <div class="navbar navbar-fixed-top navbar-invers ...

Check to see if the date selected from the HTML5 date picker is in the past compared to the current date

When working with HTML, I have a task where I need to input a date (mm/dd/yyyy) using the new HTML 5 date picker: <input name="date" type="date"> My goal is to validate whether the date entered is older than today's date. $this_date = $_POST ...

Using single-line ellipsis with the Material-UI select and option components

I have a TableHead Component with multiple columns. Among them is a <Select> element that allows users to filter the table content based on one of four statuses. I am trying to implement an ellipsis at the end of the option string if it exceeds its c ...

Unable to change background-image as intended

Here is an example of my HTML code with an initial background image: <div id="ffff" style="width: 200px; height: 200px; background-image: url('/uploads/backroundDefault.jpg')">sddsadsdsa<br>dffdsdfs</div> Everything seems to b ...