Styling an image with CSS at the top

image with 3 lines on itI am looking to create a color element that resembles a border but slightly overlaps the bottom part of the image - similar to the example shown in the linked picture.

I attempted to use CSS borders, but it did not achieve the desired effect. Any assistance would be greatly appreciated.

I have also incorporated Bootstrap5 into the project.

enter image description here

*image frame left styling original*/
.imageFrameLeft {
  display: inline-block;
/*  position: relative;*/
  position: relative;
  font-size: 0; 
}

.imageFrameLeft::before, .imageFrameLeft::after {
  position: absolute;
  border-style: solid;
  border-color: violet;
  content: '';
}

.imageFrameLeft::before {
  top: 0rem;

  right: 35rem;

  bottom: 6rem;

  left: 0;
  border-width: 6.5rem 0 6.5rem 0;

}

.imageFrameLeft::after {
  top: 0;
  right: 6.5rem;

  bottom: 6.5rem;
  left: 0rem;
  border-width: 0 0rem 0 6.5rem;

}


.imageFrameRight {
  display: inline-block;
  position: relative;
  font-size: 0; 
}

.imageFrameRight::before, .imageFrameRight::after {
  position: absolute;
  border-style: solid;
  border-color: navy;
  content: '';
}

.imageFrameRight::before {
  top: 0rem;

  right: 0rem;
  bottom: 6.5rem;

  left: 35rem;
  border-width: 6.5rem 0 6.5rem 0;

}

.imageFrameRight::after {
  top: 0;
  right: 0rem;
  bottom: 6.5rem;
  left: 5rem;
  border-width: 0 6.5rem 0 0rem;
}
<div class="imageFrameLeft">
    <img class="img-fluid mr-5" src="https://www.timeoutdubai.com/cloud/timeoutdubai/2021/09/11/hfpqyV7B-IMG-Dubai-UAE-1200x800.jpg" alt="">
</div>



<div class="imageFrameRight">
  <img class="img-fluid mr-5" src="https://www.timeoutdubai.com/cloud/timeoutdubai/2021/09/11/hfpqyV7B-IMG-Dubai-UAE-1200x800.jpg" alt="">
</div>

Answer №1

Here's an elegant solution utilizing a single pseudoelement and a clip-path to create a visually appealing design. The text is cleverly incorporated within the pseudoelement itself.

.imageFrameRight {
  box-sizing: border-box;
  display: inline-block;
  position: relative;
  padding: 6.5rem 6.5rem 0 0;
}

.imageFrameRight::after {
  background-color: magenta;
  box-sizing: content-box;
  clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%, 0% calc(100% - 6.5rem), calc(100% - 6.5rem) calc(100% - 6.5rem), calc(100% - 6.5rem) 6.5rem, 0% 6.5rem);
  display: block;
  height: 2rem;
  left: auto;
  padding: 50% 6.5rem 2rem 4rem;
  position: absolute;
  right: 0;
  top: 0;
  transition: background-color .3s ease 0s;
  transition-property: background-color, color;
  content: 'Learn more \2192';
  width: 60%;
}

.imageFrameRight:hover::after {
  background-color: navy;
  color: white;
}
<figure class="imageFrameRight">
  <img class="img-fluid mr-5" src="https://www.timeoutdubai.com/cloud/timeoutdubai/2021/09/11/hfpqyV7B-IMG-Dubai-UAE-1200x800.jpg" alt="">
</figure>

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

Tips for adjusting the height of a Safari extension during runtime

After successfully developing a Safari extension, I am facing an issue with adjusting the width and height of the popover dynamically at runtime. Can anyone provide insights on how to modify the dimensions of the popover based on its content? ...

What steps can I take to resolve this CSS problem?

I'm trying to create a box around specific html elements, but the current code is causing each element to be enclosed individually. I don't want to use the html or body element as I have other elements that need to remain outside of the box. h1, ...

What are the steps for effectively utilizing the EmChart to achieve precise font sizes in ems?

Can you explain the intended use of this chart and instructions for how to utilize it? ...

There seems to be an issue with the accurate calculation of the screen width while utilizing the scrollbar-gutter

Please take note: The scrollbar-gutter: stable; property is not compatible with Safari. Additionally, the issue seems to be specific to Chrome and works fine in Firefox. I have observed some unusual behavior when attempting to position elements fixed to t ...

Aligning jQuery Mobile Buttons in a List Divider

Seeking assistance with aligning buttons within a list divider in a jQuery mobile app. Take a look at this link to a jsFiddle demonstration I created where the button appears next to the text. Is there a way to align the button to the right without causing ...

Once you address a block using jQuery

$(function(){ $(window).scroll(function () { var scrollVal = $(this).scrollTop(); var adscrtop =$(".header").offset().top // 在 RWD 767以下不作動 if(window.screen.width>767){ if(sc ...

Tips for creating a vertical drawer using jQuery and CSS

Hello, I am currently working on developing a drawer component using Ember.js. If you want to view the progress so far, feel free to check out this jsbin http://jsbin.com/wulija/8/edit My goal is to have the drawer look like the following initially: +--- ...

Invoke data-id when the ajax call is successful

Initially, there was a smoothly working "like button" with the following appearance: <a href="javascript:void();" class="like" id="<?php echo $row['id']; ?>">Like <span><?php echo likes($row['id']); ?></span ...

Running yarn build in react results in CSS modifications

When working in my local development environment, I have everything functioning as intended. However, after executing yarn build, all of my styles appear drastically different. The project was set up using create-react-app and styled with regular CSS. Bel ...

How about: "Is there a way to show items in a list without using

I have removed the bullet points from an unordered list, but I am having trouble displaying Log with every message. The code I have doesn't seem to be working as expected. I want users to be able to differentiate between messages easily, without seein ...

retrieve the current page/url using an attribute selector

I've been attempting to format a text menu in my CSS so that the link matches the current URL, but it doesn't appear to be working. Here's the code snippet: #pages.tabs ul li a[href$=location]{color:blue !important;} , where #pages.tabs ul ...

What is the reason behind genNewColor function's malfunction?

I'm having trouble with this code that is supposed to generate a random color. The CSS formatting works perfectly, but I suspect there might be an issue with the function itself. When I try to run the code, it doesn't produce any error messages ...

Having trouble loading styles in Vue after publishing to npm

I'm currently using vue-cli3 for the npm publication of a Vue component. Below are my build scripts: "package-build": "eclint fix && vue-cli-service build --target lib --name @xchat-component/chat-component ./src/index.ts & ...

Accordion borders in Bootstrap do not appear at the top when accordion items are hidden

I am currently using a Bootstrap 5 accordion component on my website. Additionally, I have implemented a JavaScript code snippet that allows users to search and hide specific accordion items dynamically. However, I have noticed that when the top accordion ...

How do you efficiently include several elements within a single column in Boostrap 5?

I've been working with Bootstrap 5 to display a grid of images similar to this link, but the images are not displaying as intended due to some CSS code. #projects img { width: 100%; height: 100%; } <section id="projects"> ...

CSS styling on top points gets lost when scrolling

My screen displays an image with bubbles scattered randomly, each positioned using CSS styles for top and left. Strangely, when I scroll, all the bubbles lose their top style and reposition themselves to the bottom of the image. If anyone has insight into ...

Is it possible to incorporate a similar box on a webpage?

I am trying to find a way to add a similar box to a webpage like the one shown in this image. The design I am referring to is from Reddit's theme, but I would like to know how to create a box with a different color and then have another box next to i ...

The best approach to incorporating interactive animation in next.js

My vision is to develop a character creation application using next js. The app should empower users to customize the character using sliders and gender selection buttons. The ultimate goal is to have a 2D animated version of the character that dynamicall ...

Ways to implement border spacing using CSS

Here's a snippet of the code I've been working on: HTML: <html> <body> <div id="article"> <h1>TITLE</h1> <p>text</p> </div> </body> </html> CSS: #article { colo ...

Ways to modify the color of mat-icon within an input field using Angular 6

Here is the code from my HTML file: <div class="input-field"> <div> <input type="text" id="name" required email/> <label for="name">Email: <mat-icon svgIcon="mail" class="change-color"></mat-icon> &l ...