Can anyone provide guidance on how to center a pseudo-element specifically on an element that utilizes display: table-cell
? I have tried various methods but it keeps getting centered only to the parent element with display: table
.
Can anyone provide guidance on how to center a pseudo-element specifically on an element that utilizes display: table-cell
? I have tried various methods but it keeps getting centered only to the parent element with display: table
.
Understanding your intention becomes challenging without any code provided. Is this the kind of result you are aiming for? You can simply copy and paste this into an HTML document:
<style>
#table-container {
display: table;
padding: 5px;
}
.tr {
display: table-row;
padding: 10px;
}
.td {
display: table-cell;
padding: 10px;
width: 100px;
border: #000000 solid 1px;
margin: 10px;
}
</style>
<div id="container">
<div class="tr">
<div class="td"></div>
<div class="td"></div>
<div class="td"></div>
</div>
<div class="tr">
<div class="td"></div>
<div class="td"></div>
<div class="td"></div>
</div>
</div>
To ensure a pseudo element inherits values like its dimensions and positioning from its 'owning' element, you need to define their positions.
If the owning element's position is not specified, the system will backtrack through the document until it locates an ancestor with a set position, and the values will be determined in relation to that ancestor.
In the following example, the pseudo element is placed absolutely while the table-cell itself is positioned relatively.
.parent {
width: 20vmin;
height: 20vmin;
background: cyan;
display: table;
}
.child {
display: table-cell;
position: relative;
background: yellow;
}
.child::after {
content: '';
width: 50%;
height: 50%;
background-color: pink;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="parent">
<div class="child"></div>
</div>
After tackling the problem, I figured out that placing a container in every cell was the key to properly centering the element and its pseudo-element.
Why is the margin of an h2 element on my page displacing the entire body downward? This seems abnormal since the h2 element is within a div container. Is there a way to address this issue? ...
I designed a website and used DIV CSS to call an image. .header_bottom_area { background: url(../img/HomepagePanels.jpg)no-repeat scroll center center; max-width: 100%; width: auto; height: 911px; } I would like to have the same image as shown in ...
I am attempting to set the width of my .bar-1 outer span element based on the value of my inner span element. <span class="bar bar-1"> <span name="PERCENTAGE" id="PERCENTAGE" disabled="" title="Total Percentage" maxlength="255" value="66" tabinde ...
I'm currently learning about NextJS and I am developing a page located under the /security/ path. In the file /app/security/page.jsx, there is a simple anchor tag link as shown below: <Link href="#data-storage" scroll={false}>Data Sto ...
I need to set up a text field and submit button that will redirect users based on their input: index.html: If the user inputs "123" in the text box and clicks submit, they should be redirected to john.html page. AND If the user inputs "456" and clicks s ...
I'm working on a modal using Bootstrap and React. Inside the modal, there's a dropdown with an initial empty option: <select class="form-control" onChange={this.handleSelectCat}> <option disabled selected></option> < ...
I would like to implement a grid of squares for navigation purposes. By squares, I mean that the colored areas should have equal width and height. Currently, I have achieved this using JavaScript, but I am interested in a CSS-only solution. My project is ...
Looking at this code snippet, my goal is to have all the boxes rotate 180deg with a single click, without needing to apply different ID names: function rotateAllBoxes() { var boxes = document.getElementsByClassName("box"); for (var i = 0; i < box ...
After building a full-stack app using Netxjs, I generated a build and uploaded the .next folder on Cpanel. Setting up my node app: Here is a screenshot of my node app console: https://i.stack.imgur.com/sbpIP.jpg I added environment variables in both node ...
I am struggling to grasp the flex structure in Bootstrap. I'm attempting to overlay text on an image within the navbar, but it seems the container of the navbar is causing issues. Perhaps my containers are not set up correctly. Any assistance would be ...
I have a website that supports both English and Arabic languages. When the language is changed to Arabic, the "dir" attribute with a value of "rtl" is added to the HTML <html dir="rtl">. I want to add a class to the body element when the language i ...
Here is the Select component I've created using materials-UI <FormControl variant="outlined"> <Select value={this.state.value} onChange = {this.handleChange} className={this.props.classes.select} inputProps = {{class ...
I created a website for a client and everything was working perfectly on my end. However, they are experiencing errors on 3 of their Windows machines running IE8 where the ElementById cannot be found. Upon inspecting the html-source, I discovered that ther ...
After implementing jQuery form validation and redirecting using the function btn_onclick() { window.location.href = "http://localhost/loginprivate.php";} from index.php to loginprivate.php, my web app's PHP script is not being executed. The user is re ...
I am in search of a way to create those distinctive black dots with papers displayed here: body { background: linear-gradient(#ccc, #fff); font: 14px sans-serif; padding: 20px; } .letter { background: #fff; box-shadow: 0 0 10px rgba ...
Currently, I have this neat feature on my website where there's a button that toggles the image/background color - kind of like a dark mode switch. The background change is working fine, but I'm encountering some challenges with organizing the im ...
I am struggling to add margin to the right of a mui table with no success. Below is the code I have used: <TableContainer> <Table sx={{ mr: 100 }} aria-label="customized table"> <TableHead> <Tabl ...
Is there a way to navigate up one directory level in my jQuery code? The code below is referencing a folder named "uploads" on the C drive, but I can't find any mention of "uploads" in my HTML. How does it know to look there? And how can I go back to ...
I'm currently working with Next.js version 14.2.4 and tailwindcss version 3.4.1, and I've encountered an issue where rounded-lg and rounded-md classes are not applying any border radius. Oddly enough, other classes like rounded-xl and just rounde ...
This issue is specific to Safari, as it has been tested and works fine in Chrome, Opera, and Firefox. Upon hovering over a certain div (1), a child div (2) slides out by adjusting the left property. However, the child elements (buttons) within the second ...