Create a stylish frame around the interior triangle shape

I have created a div containing a triangle shape as shown below:

#inner-div {
  width:200px;
  height:200px;
  background-color:black;
  position:relative;
  border:2px solid red;
}
#triangle {
  border-right:15px solid transparent;
  border-left:15px solid transparent;
  border-bottom:15px solid white;
  position:absolute;
  bottom:0px;
  left:50%;
  margin-left:-13.5px;
}
<div>
  <div id="inner-div">
    <span id="triangle"></span>
  </div>
</div>

My goal is for the red border to not follow a straight path, but instead curve along with the triangular shape. I would like to achieve this using CSS only, without the need for images.

NOTE: I am aware of similar questions on SO, however, the solutions provided are often limited to WebKit browsers and do not offer cross-browser compatibility. I am looking for a solution that works across different browsers.

Answer №1

To achieve this effect, you can utilize a pseudo-element: http://codepen.io/joshnh/pen/5e1c4f87107511497a63ca8a68e5804b

<div class="inner-div">
    <span class="triangle"></span>
</div>

.inner-div {
  width:200px;
  height:200px;
  background-color:black;
  position:relative;
  border:2px solid red;
  z-index:-1;
}
.triangle {
  border-right:15px solid transparent;
  border-left:15px solid transparent;
  border-bottom:15px solid white;
  position:absolute;
  bottom:-2px;
  left:50%;
  margin-left:-15px;
}
.triangle:after {
  border-right:18px solid transparent;
  border-left:18px solid transparent;
  border-bottom:18px solid red;
  content:'';
  position:absolute;
  left:-18px;
  bottom:-15px;
  z-index:-1;
}

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

What is the method of duplicating an array using the array.push() function while ensuring no duplicate key values are

In the process of developing a food cart feature, I encountered an issue with my Array type cart and object products. Whenever I add a new product with a different value for a similar key, it ends up overwriting the existing values for all products in the ...

Is there a reason why Social Bar isn't appearing at the top?

My challenge is to position the bar close to the black footer. It appears correctly in Chrome, but not in Firefox and Opera. The screenshot shows how it looks in Chrome. However, in Firefox and Opera, the social bar is positioned lower and does not align ...

When using Selenium WebDriver to locate an object, an error may occur stating that the result of the xpath expression is "[object Text]" instead of an element as expected

I am currently utilizing Selenium to validate the existence of specific text within a web page. Here is an example of how the HTML appears. <html> <div class="a-content"> <!--!-->==$0 " Text to Locate" <b ...

Issue encountered while retrieving information from XML file through AJAX

I am facing an issue while using AJAX to fetch data from an external XML file. The error I receive is "Invalid argument" and I am working with IE 8. Below is the code snippet: var xhr; xhr = new XMLHttpRequest(); xhr.open("GET","C:/Users/abc/Desktop/Pr ...

What is the best way to expand the header, content, and footer colors to cover the entire width of a page while keeping everything centered within a fixed width

I managed to get the header and main content area to stretch across the full page, while keeping the content centered. But now I am facing an issue with the footer not stretching like the header. How can I make the footer stretch as well? HTML: <body ...

Alert received upon selecting the React icon button

In the login code below, I have utilized FaEye and FaEyeSlash react icons. However, every time I click on them, a warning message pops up. To avoid this issue, I attempted to switch from using tailwindcss to normal CSS. Login.jsx import { useContext, useS ...

Currently, there is a requirement to include past build outcomes in the HTML test report within the playwright

Is there a way to display the previous build status of each test case for every test case? I have been attempting to use test.info() in playwright, but it seems inaccessible from onTestEnd. One option could be to retrieve the previous build data from Jenki ...

Whenever I attempt to execute my .html and .js files, I encounter the error message: "Uncaught SyntaxError: Unexpected token <"

Just starting out in react.js, I decided to include CDN links to compile some basic react.js code into my html. Unfortunately, I encountered this error: "Uncaught SyntaxError: Unexpected token <" I did some research and found a suggestion to add: t ...

Obtain the value of v-model in a child component within VueJS

In my Vuetify App, I have implemented a Vue2Editor using a custom component called text-editor. Here is how it looks: <vue-editor :value="text" @input="updateText" ></vue-editor> The props for this component are defined as follows: props ...

The svg line is drawn with a width that is half of the specified width

I am looking to create a horizontal line that is 10px wide. I tried using the code below <svg width="500" > <line x1="100" x2="460" y1="0" y2="0" stroke="red" stroke-width="10px&qu ...

Having trouble getting your AJAX call to function properly? Could be that you're searching for the incorrect

Whenever the button is pressed, I need an AJAX call to be sent to my events_controller#check action. Here's the code snippet: events\new.html.erb: <button id="check-button" type="button">Check</button> application.js: $(document). ...

Clickable Slider Picture

I'm having a minor issue with a jQuery script that slides images on my website. The script itself is functioning properly, but I am trying to add links to each image. I've attempted placing <a href> and </a> tags around the <img> ...

Discovering the window.scrollTop, ScrollY, or any other distance value while utilizing CSS scroll snap can be achieved by following these

I am currently utilizing css scroll snap for smooth scrolling through sections that are 100vh in height. The functionality of the scroll snap is quite impressive. However, I need to find a way to determine the exact distance the user has scrolled down the ...

Is it possible to duplicate a response before making changes to its contents?

Imagine we are developing a response interceptor for an Angular 4 application using the HttpClient: export class MyInterceptor implements HttpInterceptor { public intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<an ...

JavaScript => Compare elements in an array based on their respective dates

I have an array consisting of more than 50 objects. This array is created by concatenating two arrays together. Each object in this array contains a 'date' key with the date string formatted as: `"2017-03-31T11:30:00.000Z"` Additionally, there ...

Tips for identifying the amount of <ul> elements contained within every div

Dealing with a large file structured in the same way, I am looking for a method to isolate a specific div, determine the number of ul's within it, and then iterate through each one to extract the value of every li element. <div class="experiment ...

Tips for executing a never-ending blocking operation in NodeJS?

Currently, I have a collection of API endpoints within Express. One specific endpoint triggers a lengthy process that hinders the flow of other incoming requests in Express. I am determined to transform this process into a non-blocking one. In order to ga ...

Struggling with establishing recognition of a factory within an Angular controller

I am currently facing an issue while trying to transfer data from one controller to another using a factory in Angular Seed. My problem lies in the fact that my factory is not being recognized in the project. Below is my snippet from app.js where I declare ...

Lost in a sea of confusion with ember-cli-postcss and autoprefixer

I'm currently working on an ember build that incorporates autoprefixer. My issue arises from the fact that the output location for 'assets/application-name.css' has shifted from its normal path to 'app/styles/app.css', and I would ...

How come the width factor encompasses the border when the box-sizing is set to content-box?

My HTML file contains the following code: <html lang="en" class=""><head> <meta charset="UTF-8"> <title>CodePen Demo</title> <meta name="robots" content="noindex"> ...