Adhesive strip attached inside a flex box container

Within my parent container, I am using flex-box to organize the layout.

One of the child divs (.child-two) needs to stick out 60px from the top once it reaches the header.

Unfortunately, setting position: sticky doesn't work when the parent container is a flex-box.

<div class="parent-container">
   <div class="child-one"></div>
   <div class="child-two"></div>
   <div class="child-three"></div>
</div>

Here's the css:

.parent-container {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -ms-flex-flow: row wrap;
    flex-flow: row wrap;
    padding-top: 24px;
    -ms-flex-line-pack: baseline;
    align-content: baseline;
}

.child-two {
  position: sticky;
  top: 66px;
  background-color: #2ecc71;
}

.child-one, .child-three {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -ms-flex-flow: row wrap;
    flex-flow: row wrap;
    margin-bottom: 16px;
}

Is there a way to achieve this without removing the flex property from the .parent-container?

Note that this code snippet is simplified and part of a larger web application with multiple elements.

Answer №1

It seems like the issue you're facing with your CSS is not immediately evident without a closer inspection of the code itself.

span > span{
  width:50px;
  height:50px;
  margin:5px;
  border:solid 1px black;
}

.container-parent{
  display:flex;
  height:500px;
  padding-top:50px;
}

.child-four{
  position:relative;
  top:20px;
}
<div class="container-parent">
   <span class="child-one"></span>
   <span class="child-two"></span>
   <span class="child-three"></span>
</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

Reformat an input number by substituting commas with periods

Here's the code I'm working with: <input type="number" tabindex="3" placeholder="Item Price" step="0.01" min="0.10" max="999.99"> An example value inside this input is 1,95. I need to replace the comma with a dot. Can this be done using ...

Ways to incorporate additional spacing within a code section using HTML and CSS

I am in the process of creating a new widget. To implement it, users will need to copy and paste a code snippet from my website directly into their HTML code. There are two main functionalities that I want to incorporate: I would like to include proper ...

Display additional input field using Jquery when text is entered in the textbox

Is there a way to display the input field #f_past_data when the text field #f_past_farmaco is filled out? The field #f_past_farmaco is for entering text. I attempted the following solution but it did not work as expected. $('label[for=f_past_data], ...

Find the preceding element of the element that includes a specific link text

Can someone help me figure out how to click on a <td> element that precedes the <td> element with the linkText "Main" using Selenium? The element I'm looking to click is shown in the highlighted area of this image: https://i.sstatic.net/Q ...

What could be causing my jQuery to malfunction after I include the .sqrt() function?

Seeking assistance in creating a grid of divs, I am working on finding the square root of the user's input to determine the height and width required to form a square. The code below is what I currently have: $('#size').click(function(){ $ ...

What is the best way to modify a div's background image on hover and incorporate transitioning effects like fadeIn?

After finding a helpful solution for the initial part of my question, I had success implementing it and have shared it below (Big thanks to rsofter!). Now, I am looking to enhance the background image with fadeIn and fadeOut effects - what additional steps ...

Step-by-step guide on completing and submitting a form through a Windows application

Many are questioning the age and repetition of this query, but here is where my issue begins. Are you noticing two input fields with the same name? HTML CODE <html> <head><title></title> </head> <body> <input type= ...

Can a script be dynamically loaded into a div while accessing local variables?

Consider the scenario where you have two files: test.html <div id="stuff"></div> <button onclick="doStuff()">Magic</button> <script> var foo = new function() { this.bar = function() { return "THE MAGIC!"; }; ...

Disable the movement and dragging functionality of the scroll feature in Google Maps using React

I have a map.jsx file in my React application that contains the code below: import React from 'react'; import GoogleMapReact from 'google-map-react'; import './map.css'; const Map = ({ location, zoomLevel }) => ( <d ...

Transitioning background with background sizing set to cover

I have been searching for an answer to this question, but haven't found one yet. Currently, I have a series of divs with background-images set to 'background-size: cover'. My goal is to make the images zoom in and grow on hover. However, i ...

Style selector for dynamic drop-down menus

import React, { Component } from "react"; export default class FontChanger extends Component{ constructor(props){ super(props); this.state ={ selectedFont: "", currentFont: "", }; this.handleFon ...

Ensuring the text remains positioned above another element constantly

Looking to have the text float above a regular box and resize the font size accordingly? Here's what I've tried: https://jsfiddle.net/a87uo3t2/ @import url('https://fonts.googleapis.com/css?family=Share+Tech+Mono'); body { margin: ...

Struggling to unlock the mystery of a jammed trigger box

I'm currently working on implementing a small 'trigger box' that will expand upon clicking. It was functional before, but it seems to be encountering an issue now and I'm unsure of the cause. While I have some understanding of HTML and ...

Issues with Organizing Bootstrap Card Layout

I'm in need of assistance with creating a responsive Bootstrap card grid. My goal is to have a grid layout with 6 cards, initially displayed as 2 rows of 3 cards. As the screen size decreases, I want the layout to adjust accordingly to maintain reada ...

Utilize xdebug and NetBeans 8.2 to troubleshoot PHP code submitted through an HTML form

After successfully setting up the XDebug extension to debug PHP code within NetBeans IDE (ver. 8.2), I encountered an issue. While debugging works fine when setting a breakpoint and running the script in debug mode, I am having trouble debugging PHP code t ...

The HTML modal validation feature on Spring is malfunctioning as it is vanishing unexpectedly

After setting up a login and registration feature for my blog website, I encountered an issue where the website would reload whenever a user tried to log in or register. This caused the modal to disappear, making it impossible to display any error messages ...

Alter the button's color seamlessly while staying on the same page

I have implemented a feature that allows me to change the category of photos without having to leave the page and it works perfectly. My next goal is to create a button system where the pre-defined category of a photo is indicated by a button with a green ...

Numerous sections of content

Struggling to align these two pieces of content side by side. While I've had success displaying content like this in the past, I'm hitting a roadblock this time around. Any assistance would be greatly appreciated. HTML <div class="block-one" ...

Ways to transfer JavaScript arguments to CSS style

Currently, I am developing a web service using Angular and Spring Boot. In this project, I have implemented cdkDrag functionality to allow users to place images in specific locations within the workspace. My goal is to maintain the placement of these image ...

Problem Encountered with Jquery Validation for Name Field (Restriction to Alphabetic

I am struggling to validate a name format using a predefined jQuery validation tool. My intention is for the name field to accept only characters, but even with the correct regex pattern, it still allows numbers to be entered. The specific script I am us ...