Place an element above the top border, but below the bottom border

I'm facing a challenge with my div-container, which contains a bootstrap collapse element. Inside it, there is a circular element that changes its position when the collapse function is used. The goal is to have this element positioned at the top border but hidden behind the bottom border.

https://i.sstatic.net/7wriK.png

How would you approach solving this issue?

My initial thought was to use object-fit to trim the bottom part of the circular element, but this didn't align well with the transition and collapse effects. Another idea was to add a thick border-bottom as an after-pseudo-element to cover the bottom part, but I haven't had success with that yet.

Do you have any suggestions or experience in tackling a similar problem?

Thank you!

Answer №1

Utilize clip-path with CSS:

.box {
  border: 3px solid;
  height: 200px;
  margin: 50px;
  position: relative;
  clip-path: inset(-200% 0 0); /* Apply a large negative value on the top to only clip left/right/bottom */
  transition: 1s;
}

.box:hover {
  height: 50px;
}

.box:before {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 100px;
  height: 100px;
  border: 3px solid;
  border-radius: 50%;
  background: red;
}
<div class="box">

</div>

Answer №2

You can also utilize transform3D along with the background property to conceal certain parts of it:

div {
  margin:0 1em;
  padding:1px;
  display:flex;
  padding-bottom:2em;
  background:white;
  transform-style: preserve-3d;
}
div[class] {
  border:solid;
  border-bottom:none;
  height:150px;
  transition:0.25s;
}
div[class] + div {
  border-top:solid;
  }
div[class]:hover {
  height:60px;
}
div span { 
  height:150px;
  width:150px;
  align-self:center;
  background:red;
  border-radius:50%;
  margin-right:1em;
  border:solid;
  margin-left:auto;
  margin-bottom:-2.2em;
  transform:rotatex(-0.15deg) translatez(1px);;
}
<div>Content placed here</div>
<div class>
  <p>Hover over to collapse</p>
  <span></span>
</div>
<div>Additional content here</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

Breaking up phrases into separate lines (Bootstrap 4 + Mobile)

On my website, I currently have a sentence that is fully displayed on the Desktop version. However, I am looking to modify it so that it breaks into 2-3 lines when viewed on Mobile using Bootstrap-4. For example, here is the text in question: Our large, ...

The width of the flexbox child item is too narrow for the content it contains

I am facing an issue with the Flexbox child element not aligning correctly with the content width. Here is the code snippet: https://i.sstatic.net/jtCnSuhF.png .pw-event-options { -webkit-box-flex: 0; -webkit-flex: 0 0 280px; -moz-box-flex: 0; ...

Ways to assign a default background shade to a webpage with a transparent background

My page has a completely transparent background achieved by using: body { background:none transparent!important; } When I display this page in a transparent iframe on another site, I can see the website's background through the page. However, if ...

Effective ways to enable users to upload files in a React Native app

Being in the process of developing a react native app, I am faced with the challenge of allowing users to easily upload files from their mobile devices (pdf, doc, etc). Unfortunately, my search for a suitable native component has proven fruitless. Can anyo ...

Wrapping is disabled for all elements within the container div that contains three additional div elements

I am trying to prevent one of the three divs inside a fixed top navbar container from sliding underneath another, causing the navbar to become taller. The code below is using Bootstrap and the issue is with the navbar-header div sliding underneath the he ...

TinyMCE editor does not appreciate being shifted from place to place

While working on my webpage, I encountered an issue with TinyMCE editors when trying to move them within the DOM tree. Strangely, the editor clears itself completely and becomes unusable. This problem seems to be consistent in Safari 4 and Firefox 3.6, but ...

Creating Structured Lists with HTML Columns

Can you assist me in achieving a single column layout for all the bullet points, as I would like to experiment with various designs? Below is what my current display looks like and how I envision it to be presented: https://i.stack.imgur.com/NhMCC.jpg Pl ...

How can I move Bootstrap 5 navbar list items to the right side?

I'm struggling to position the signup and login links on the right side of the page. I've tried using mr-auto, ml-auto, and justify-content-end but none of them seem to be working. <nav class="navbar navbar-expand-lg navbar-light"&g ...

Issue with resizing background image in CSS

There's a header image on a page that is controlled by CSS: #photos-banner .navbar { background-image: url("../images/bands/photos.jpg"); border-radius: 0; border-bottom: 0; padding-bottom: 8px; background-repeat: no-repeat; background-position: cent ...

The anchor tag's href attribute isn't working properly when using a single slash, but it works

I'm encountering an issue where my absolute URL is not clickable in an anchor tag as shown below: <a href="/account/login"><Login</a> However, it works with double slashes: <a href="//account/login"><Login</a> B ...

Issues with CSS filters affecting the layout of webpage elements

Is there a way to keep a div pinned to the bottom of the viewport while applying a filter to the body in CSS? I tried using position: fixed; bottom: 0px, but it seems to mess up the positioning when a filter is added to the body. body { filter: bright ...

Image uploading in Angular is not compatible with Internet Explorer, however, it functions correctly in Google Chrome

As of now, my implementation has been successful in all browsers except for Internet Explorer 11. Despite being able to successfully upload .jpeg, .jpg, and .png images in Google Chrome, I am facing issues when trying to upload them in IE 11. The code wo ...

Implementing dynamic CSS in AngularJS using conditional statements

One technique I've been using in angularjs involves toggling between two windows using the ng-click and ng-show directives: <div ng-init="showTab2 = false"> <a ng-click="showTab2 = true; showTab1 = false ">#Tab1 </a> ...

Disabling buttons in a Fiori UI5 application using HTML: A step-by-step guide

I don't have much experience with scripting languages. I am attempting to hide buttons within a SAP Fiori app by using the "Inspect element" tool in the Mozilla browser. When I delete the HTML code, the button disappears, but I would like to accomplis ...

Creating an external JavaScript and CSS file for date picker in Eclipse can be done by following a few simple steps. By creating separate files for the

I am using the following javascript and css styles: <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all" /> <script src="http://ajax.googleapis.com/ajax/libs/jq ...

Google Maps in Angular is not showing up

My Angular Google Maps implementation seems to be working, but unfortunately, the map is not showing on my website. I have confirmed that my JS is loading the maps and I can retrieve the map properties. Interestingly, when I check the Chrome AngularJS Debu ...

Utilize the dimensions of one image to resize others using the JavaScript method .getBoundingClientRect

I am attempting to transfer the width and height measurements of the initial image to all subsequent images on the page. Currently, I have successfully applied the dimensions of the first image to the second one, but I am facing difficulties with the thir ...

Ways to Retrieve HTML Snippet from Handler Request and Load it into a String

I'm encountering an issue with my ASP.NET MVC application. I'm attempting to retrieve the following HTML snippet from a Handler in a separate ASP.NET project, within one of my controllers, in order to display it in a View: <br /> <div i ...

Struggling to update the inner HTML of a <p> tag using LocaleDateString() function

Recently, I've been experimenting with creating a calendar but encountered a frustrating issue. I created a variable storing a date using the toLocaleDateString method. However, when attempting to modify a paragraph's inner HTML, nothing seemed t ...

When linking to a section, the Bootstrap navbar obscures the top part of

I have been working on my inaugural website for educational purposes and encountered the following issue: Every time I try to link to a specific section on the same page, it opens as intended but the top portion is obscured by the navbar. <body data-s ...