Tips for concealing overflowing CSS content

How can I prevent CSS content from overflowing? I am trying to display a price tag in the CSS element, but it is protruding out of my card.

.content{
          content:'';
          position: absolute;
          left: 309px;
          top: 206px;
          z-index: 1;
          border-radius: 100%;
          width: 160px;
          height: 160px;
          //overflow: hidden;
          //display: block;
          background: rgba(0,0,0,.5)
      }
<div class="row">
        <div class="col s12 l4">
          <div class="card">
            <div class="card-image">
              <img src="http://lorempixel.com/300/400" style="height: 300px;width: 418px;">
              <div class="content">
              </div>
            </div>
          </div>
        </div>

Answer №1

To prevent overflow in the div with a position:absolute, ensure that its immediate parent (.card-image) has a position:relative so that it acts as a container for the absolutely positioned div.

Additionally, apply overflow: hidden to the parent container.

.card-image {
   position: relative;
   overflow: hidden;
   width: 418px;
   height : 300px;
}
<div class="row">
  <div class="col s12 l4">
    <div class="card">
      <div class="card-image">
        <img src="assets/img/jonatan-pie-415847.jpg" style="height: 300px;width: 418px;">
        <div style="content:'';
                  position: absolute;
                  left: 309px;
                  top: 206px;
                  z-index: 1;
                  border-radius: 100%;
                  width: 160px;
                  height: 160px;
                  background: rgba(0,0,0,.5);">
        </div>
      </div>
    </div>
  </div>

Answer №2

<div class="row">
  <div class="col s12 l4">
    <div class="card">
      <div class="card-image" style="position:relative; overflow:hidden;height: 300px;width: 418px;">
        <img src="assets/img/jonatan-pie-415847.jpg" style="height: 300px;width: 418px;">
        <div style="content:'';
                  position: absolute;
                  left: 309px;
                  top: 206px;
                  z-index: 1;
                  border-radius: 100%;
                  width: 160px;
                  height: 160px;
                  background: rgba(0,0,0,.5);">
        </div>
      </div>
    </div>
  </div>

It seems like the current setup might not be exactly what you are looking for. One key aspect is to ensure that the card-image is positioned relatively, which allows it to act as a reference point instead of the window. Additionally, applying overflow to it helps to hide any content within it.

I'm unable to view your image properly, so I may not fully grasp your requirements.

A possible suggestion would be to use the card-image with a background image and then add the circular element inside it using regular content.

.card-image{
    background-repeat: no-repeat;
    background-size: cover;
    position:relative;
    overflow:hidden;
    height: 300px;
    width: 418px; 
}

.price-wrapper{
    position: absolute;
    box-sizing: border-box;
    left: 309px;
    top: 206px;
    border-radius: 100%;
    width: 160px;
    height: 160px;
    background: rgba(0,0,0,.5);
    padding: 50px;
    color: #FFF;
}
<div class="row">
      <div class="col s12 l4">
        <div class="card">
          <div class="card-image" style="background-image: url('assets/img/jonatan-pie-415847.jpg')" >
            <div class="price-wrapper" >
                      $9.99
            </div>
          </div>
        </div>
      </div>

This approach provides more flexibility in managing the circular content. I've kept the background image as an inline style for easy modification through scripting languages like PHP.

I added some additional styling to include a price value within the circle, but feel free to adjust or remove these details based on your needs.

Just my two cents.

Answer №3

 <div class="row">
  <div class="col s12 l4">
    <div class="card">
      <div class="card-image">
        <img src="assets/img/jonatan-pie-415847.jpg" style="height: 300px;width: 418px;">
        <div style="content:'';
                  position: absolute;
                  left: 309px;
                  top: 206px;
                  z-index: 1;
                  border-radius: 100%;
                  width: 160px;
                  height: 160px;
                  overflow: hidden;
                  display:block
                  background: rgba(0,0,0,.5);">
        </div>
      </div>
    </div>
  </div>

Syntax : overflow: visible|hidden|scroll|auto|initial|inherit; check it out at https://www.w3schools.com/cssref/pr_pos_overflow.asp

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

show: alongside move: towards the left

Reviewing some vintage CSS code from 2008, I stumbled upon the following CSS snippet for a menu/navigation: #menu li { display: inline; } #menu a { display: block; float: left; height: 32px; margin: 0; padding: 18px 30px 0 30px; ...

How can I make a sticky element appear behind a different element?

https://jsfiddle.net/30suam6z/1/ .first { height: 100vh; background-color: red; position: relative; z-index: 2; /* Increase z-index to ensure it covers .test */ } .second { height: 100vh; background-color: yellow; position: relative; z- ...

Adjust font style within an HTML/CSS document

I recently obtained the source code for an online portfolio project, but I'm struggling to figure out how to modify the font style. Can anyone provide guidance on this issue? https://github.com/akashyap2013/PortFolio_Website ...

The CSS Scroll-Snapping feature seems to be overlooking one specific element that it should be snapping to

Currently, this website is designed to work exclusively for mobile devices. When viewed in Chrome's mobile view using the inspector, everything appears to be functioning correctly. However, when accessed through Safari or on an actual mobile phone, th ...

When using ReactJS, hovering over a row in a table should trigger a change in the background color of the corresponding row in another table with the same index

I need to create a feature where hovering over a row in the first table will highlight a corresponding row in the second table. The highlighting should be based on the index of the hovered row. Here is an example: <div> <table> < ...

What could be causing my HTML element to vanish once the animation is complete?

I have successfully implemented an animation on 3 HTML elements for a landing page I am currently developing. The animations are working as intended, but I am facing an issue where the two lower elements (an h1 tag and a button) briefly appear on the page ...

Cutting imagery to create a new design element

https://i.sstatic.net/IAh0h.jpg There is an image above with 6 gears (circles with pointy edges). My goal is to separate them into individual pictures and, on each picture's hover, have a relevant line with text appear. How can I achieve this? The a ...

Passing $index variable from a bootstrap modal window does not work in AngularJS

I'm running into a wall here. My issue involves using ng-repeat to populate a table with two buttons in each row - one for updating the row content and another for uploading files. The upload button triggers a bootstrap modal window where users can se ...

show error notification on the user interface using asp.net mvc

What is the best way to showcase a message on a designated div element <div asp-validation-summary="All" class="text-danger"></div> when transmitting a message from the server-side? [HttpPost] public IActionResult Signup(Signup signup) ...

Scroll bar for multiple selection select tag without using div element (not supported in firefox)

.selector select[multiple="multiple"] { border-radius: 0; height: 200px; margin: 0 0 0 -1px; max-width: 368px !important; padding-left: 3px; width: 368px !important; } <select id="id_included_packages_from" class="filtered" multiple="multipl ...

What is the best way to show a left and right arrow on a mobile website page?

I'm experiencing a strange issue with my webpage, specifically a post in Wordpress. When I try to insert the left right arrow character (U+2194) either by copying from a character map or using the html code, I end up with an icon instead of the actual ...

Arranging elements on a webpage using Javascript

Creating a Dynamic Div Layout with JavaScript I have successfully implemented functionality wherein clicking on + opens a div and clicking on - closes it. However, I am now faced with the challenge of handling multiple divs at runtime. How can this be ach ...

Integrate stylish checkbox design into a form in Rails

I discovered some beautiful css styles for checkboxes that I would like to use instead of the regular ones. You can find these styles here: . Could someone guide me on how to implement this change? This is the code snippet from the form: <div class=" ...

Zooming out on mobile devices on a webpage using Bootstrap 4

After creating a web app and styling it with bootstrap 4, I incorporated a media query to adjust font size and padding on mobile devices. The code snippet used for this purpose is as follows: @media (max-width: 1200px) and (orientation: portrait) { .con ...

The cakePHP time dropdown feature lacks customization options

When viewing my form in CakePHP, I noticed that the time select dropdown appears differently in Chrome compared to Firefox. In Firefox, there are 3 arrow buttons attached to each dropdown, whereas in Chrome it looks different. I want to hide the arrow but ...

Unable to render data in HTML page using Vue component

home.html: <body> <div id="app"> {{ message }} </div> <div id="counter"> {{ counter }} </div> <script type="text/javascript" src="https://cdn.js ...

Saving Bootstrap Data - Modals, Tags and Notifications

Check out my code snippets on this example/demo page. /* Messages Modal */ $(document).ready(function(){ var informer = $("#messageInformer a"); var refreshBadge = function(messageCount) { var badge = informer.find(".badge"); ...

Updating padding through local storage does not function as intended

I recently added two buttons to my website for adjusting the padding. While they are functional, I find myself manually setting the padding for nav, main, and footer in the CSS. Here is the snippet of the code: main { padding: 20px 25%; } footer { ...

Content Management System editing plan

Have you ever wondered if there is a structured approach to editing content management systems like Wordpress and Joomla? When it comes to editing aspects such as CSS and JavaScript, what steps do you usually take? Personally, I have been creating files l ...

I recently realized that my website has a strong Björk influence when viewed in IE. Any suggestions for what I should do next

After using Chrome and Firefox for a while, I decided to test out my website on IE8. To my surprise, the results were disastrous. The navigation was impossible, rotations were not rendering correctly, and everything looked like a complete mess. Do any of ...