Looking to include a tag in the top left corner of a product card?

Looking to create a unique tag for a card on my website to showcase a new product. My vision is to have an eye-catching design positioned in the top left corner of the card.

Seeking assistance with crafting the CSS code for this specific element.

Initial attempts at creating a square shape with rounded corners didn't meet expectations. Here's a sample layout for reference.

Below is the HTML and CSS code snippet for the card:

#games div {
  background-color: #3A7BCD;
  border-radius: 7px;
  cursor: pointer;
  overflow: clip;
  min-width: 100%;
  max-width: 400px;
  margin-bottom: 15px;
}

#games div *:not(img) {
  margin: 10px;
}

#games div img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}
<div>
  <img src="https://i.postimg.cc/9FJYqQKg/Screen-Shot-2024-05-08-at-4-22-24-PM.png" alt="Banner image">
  <h2>
    Title
  </h2>
  <p>
    Description
  </p>
</div>

Answer №1

Check out this demonstration of using a simple div instead of an image: The key here is the use of position: absolute, with the parent element having position: relative to serve as the position reference point. The values for left and top can be customized according to requirements, along with the angle set by transform: rotate(...). The concept should be straightforward:

#parent {
  background-color: #3A7BCD;
  border-radius: 7px;
  cursor: pointer;
  margin-bottom: 15px;
  position: relative;
  top: 30px;
  left: 30px;
  width: calc(100% - 60px);
}

#parent *:not(img) {
  margin: 10px;
}

#parent img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}
#new {
 width: 100px;
 height: 60px;
 background: green;
 position: absolute;
 transform: rotate(-25deg);
 top: -25px;
 left: -30px;
 border-radius: 8px;
 color: white;
 font-size: 30px;
 line-height: 60px;
 text-align: center;
}
<div id="parent">
<div id="new">NEW</div>
  <img src="https://i.postimg.cc/9FJYqQKg/Screen-Shot-2024-05-08-at-4-22-24-PM.png" alt="Banner image">
  <h2>
    Title
  </h2>
  <p>
    Description
  </p>
</div>

Answer №2

The issue lies within the overflow property set to clip, causing any content that exceeds the element to be hidden. A potential remedy, although not perfect, could involve enclosing your element in a div of identical dimensions and then incorporating the desired tag.

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

Utilize a Fancybox hyperlink for every image within the specified div container

I'm looking for a solution to automatically add a fancybox link to every image within the div #artikel. Essentially, I want to convert each <img src="image.png"></img> to <a href="image.png" class="fancybox" rel="artikel"><img ...

Switch Styles with Angular Directive

Looking to toggle a class using this code snippet (shoutout to Zombi for the helpful directive!) I'm struggling to figure out how to change the class of element "B" when element "A" is clicked. Any suggestions on how I can achieve this? Angular mod ...

Trouble with displaying a CSS background image in Google Chrome on the Three.js birds demo

My website displays a background image in both Safari and Firefox, but for some reason Google Chrome is not showing it. I am unsure why this is happening. Do you have any insights on what I might need to adjust? renderer = new THREE.CanvasRenderer(); ren ...

Dynamically Modify Custom Style Class Properties in JavaFX Using CSS

Embarking on my CSS journey, I have limited experience since I mainly worked with JavaFX applications and not web languages. In one of my JavaFX applications, I utilized a css style sheet featuring a Windows 10 UWP theme. The default style classes adhere t ...

I am curious as to why the Bootstrap 4 dropright selected menu appears as a default browser button in Chrome, while it functions seamlessly in Firefox

An issue has been identified that is specific to Chrome. The dropright selected menu appears differently in Chrome compared to Firefox, where it displays correctly with a white background. !https://i.sstatic.net/BulRA.jpg The Bootstrap version being used ...

Sticky box fails to maintain position as header scrolls

I am looking to create a Sidebar that sticks to the window while scrolling, but stops when it reaches the footer. I have managed to get it partially working, but there is a small issue that I can't seem to solve. Test it live here: Everything seems ...

I am looking to generate a dynamic div right beneath these three divs

I need to dynamically create multiple HTML divs using a function called addPatientQueryDiv(). Here's an example of the code I'm using: <div id="childRow" class="dynamicDivRow" style="float: left; width: 70%;"> <div class="pChild ...

Displaying a box with a question mark using Glyphicon and Font Awesome icons

I'm having a problem with my website not displaying the Glyphicons or Font Awesome Icons. When I enter the code, it shows up like this: http://prntscr.com/8qwwmd. This is the first time I've encountered this issue and it's only affecting som ...

Creating a multi-column ordered list that spans multiple pages is a great way to organize and

My goal is to showcase a numbered list in a three-column format, following the guidelines presented in this particular query. However, I am looking to maintain the continuity of the list across different pages by ensuring that the subsequent item on the ...

The combination of jQuery html() method and the &amp; symbol is

While conducting a search among a list of individuals, I encountered an issue with displaying results on the fly. Specifically, I needed a link to appear as: chatid=18&userid=45&create=new However, after displaying the results using the following ...

The dropdown menu displaces nearby content

Visit this website for more information To access the blog section, simply click on "BLOG" in the top menu. Once there, look to the right side under the circle logo and select "Dísznövények" from the dropdown menu. Be cautious of long content strings b ...

Creating a gradient circle in the header menu of your WordPress site

I am absolutely in love with the half CSS gradient circle featured on this WordPress website, but I'm struggling to implement it myself. Here is the URL for reference: Could someone please provide me with detailed instructions on how to achieve this ...

What are the steps to achieve a double-layered border that is inverted?

Can a unique scoop border style be created using CSS or jQuery? Similar to the design in the image below: ...

How can I modify the HTML code for rooms in the HTML 5 client of the bigbluebutton application?

Is it possible to customize the HTML code of rooms within the BigBlueButton source code? Additionally, how can I modify the CSS styles of elements in room sessions? For instance, I am interested in hiding the logo of BigBlueButton by setting 'display: ...

Is it possible to determine the optimal dimensions for a viewbox that would accommodate all the elements of a drawing?

In the event that a drawing contains multiple shapes and paths, where all of these elements need to be fully visible without any cropping, the viewbox must encompass everything. Yet, is it possible to identify the specific values for min-x, min-y, width, ...

Utilizing CSS to maintain the layout of content in portrait or square orientation

Is there an optimal approach to ensure that a webpage's square content appears "tall" when viewed in different screen orientations? For instance, when the device is held vertically, the content should occupy the full width, whereas in horizontal orien ...

How can I incorporate webkit-specific styles onto a layer?

Is it possible to apply the CSS rule -webkit-backdrop-filter: saturate(1.8) blur(20px); on a Layer in order to create a quick simulation of background blur? ...

Using a single div to display a sequence of background images one after the other

Picture this scenario: I have two images, one measuring 1px by 700px and the other 1px by 800px. Is there a way in CSS3 to set them as backgrounds for one div which will then have a total height of 1500px? Can this be achieved with CSS3 alone? div{ b ...

Is there a way to change the background color of the body on click and have it applied throughout the entire site

Is there a way to change the background-color of the entire site and specific modal elements when a user switches between two radio buttons? Here is the HTML code for the radio buttons: <div class="btn-group btn-group-xs" data-toggle="buttons"> ...

The HTML button triggers a function to execute on a different webpage when clicked

I'm facing a straightforward issue that I can't seem to figure out due to my limited experience with Angular and web development. The problem revolves around two components, namely home and dashboard. In the home.component.html file, there's ...