Create a CSS border with a stylish downward arrow design

Recently, I came across a specific requirement that I need help with. You can see the image https://i.sstatic.net/j4Qdf.png.

I found a helpful resource on how to create triangles using CSS on https://css-tricks.com/snippets/css/css-triangle/. However, I am struggling to attach it to a border with the dimensions of 10px in height and 40px in width. Can anyone provide guidance on achieving this?

Answer №1

To create the arrow design, ensure the parent div has position: relative; and the child div has position: absolute;.

The key to creating the arrows is through the transform property.

The arrow size may need adjustment, as it is currently set at 2x the desired size.

* {box-sizing: border-box;}
.line {height: 20px; border-bottom: solid 2px #000; margin-top: 100px; position: relative; z-index: 1;}
.arrow {content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); height: 20px; width: 80px; z-index: 2; background-color: #fff;}
.arrow .pin {width: calc(50% + 5px); height: 2px; background: #000; display: inline-block; float: left; transform: rotate(25deg); transform-origin: 0 0;}
.arrow .pin:last-child {transform: rotate(-25deg); transform-origin: 100% 0; float: right; margin-top: -2px;}
<div class="line">
<div class="arrow">
<div class="pin">

</div>
<div class="pin">

</div>
</div>
</div>

For an arrow size of 40px x 10px, the following adjustments can be made:

* {box-sizing: border-box;}
.line {height: 20px; border-bottom: solid 2px #000; margin-top: 100px; position: relative; z-index: 1;}
.arrow {content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); height: 10px; width: 40px; z-index: 2; background-color: #fff;}
.arrow .pin {width: calc(50% + 3px); height: 2px; background: #000; display: inline-block; float: left; transform: rotate(25deg); transform-origin: 0 0;}
.arrow .pin:last-child {transform: rotate(-25deg); transform-origin: 100% 0; float: right; margin-top: -2px;}
<div class="line">
<div class="arrow">
<div class="pin">

</div>
<div class="pin">

</div>
</div>
</div>

Answer №2

That explanation is very clear.

First step: Apply the position: relative; property to the div where you want to insert the arrow.

Second step: Insert the CSS arrow:

<div class="arrow-down"></div>
and give it a position: absolute; property to position it correctly.

For instance, if you had a div with the class box, here is what you would need to do:

.box {
  width: 200px;
  height: 150px;
  background-color: red;
  margin: 30px auto;
  position: relative;
}

.arrow-down {
  width: 0; 
  height: 0; 
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 10px solid #f00;
  position: absolute;
  bottom: -10px;
  left: 80px;
}
<div class="box">
   <div class="arrow-down"></div>
</div>

You can view the code in action here: https://jsfiddle.net/t2ne282z/

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 best way to evenly space 3 divisions in a row so that the last element is centered on the page?

Is there a way to align three divs horizontally, evenly spaced, in a manner that positions the rightmost element at the center of the page? ...

Using jQuery and Bootstrap to Enhance Checkbox Button Styling

I am currently working on an asp.net webform and attempting to style my checkbox similar to the design shown here: When I try to replicate the HTML and JS code from the above link on my page, it does not seem to be functioning properly, most likely due to ...

Prevented: Techniques for providing extra cushioning for a button, but with the condition that it contains an external icon

How can I apply padding to a button only if it contains an external icon? If the button has an external icon, I want to give it padding-right: 30px (example). However, if there is no external icon present, then the button should not have the 30px padding. ...

Adaptive design exhibits varying appearances across various screen sizes

Currently, I am working on a responsive design WordPress site and here is the markup: <div class="contact-wrap"> <div class="contact-number">123-456-7890</div><!--.contact-number--> <div class="user-login"><a href="#"& ...

CSS3 family tree tutorial: Incorporating a wife into the design

I came across a fascinating tutorial about creating a family tree using CSS3 only. However, I'm struggling to understand how to depict a marriage. To explain further: What the code currently accomplishes is this: what i aim to include is this: Alth ...

Centered image

I am working on a website and struggling to center the image on all screen sizes. I attempted the following code:- <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript" lang ...

css overflowing content can disrupt the layout of the screen

I am currently working on creating a modal that will be displayed in the center of the screen with the same width as the main page. However, I am facing an issue where the modal is not perfectly centered. I suspect that this is due to the overflow style ...

Guide on making a persistent sidebar using CSS and JavaScript

I'm in the process of developing a website that features a main content area and a sidebar, similar to what you see on Stack Overflow. The challenge I am facing is figuring out how to make the sidebar remain visible as a user scrolls down the page. T ...

How to modify the color of a div element with jQuery?

I need some help changing the color of a div with 'jQuery', but I am not sure how to do it. Below is the code I have been trying: function updateDivColor() { $('#OutlineX1').css("color","blue"); } ...

What is the best way to ensure consistent spacing between columns in a Bootstrap 3 grid layout, similar to the spacing on the left and right sides?

Is there a way to achieve equal spacing between all blocks in a row, similar to the left and right padding that Bootstrap automatically applies? Currently, Bootstrap adds padding to all columns on both sides, but does not render extra spacing on the left s ...

Is there a way to ensure that text remains inside an unconventional image while scrolling?

I am trying to achieve a torn and indented effect on an image on my webpage, with rough edges and an inner shadow. I want the content on top of this image to scroll underneath the torn edges without extending beyond the visible area of the image. The image ...

Updating the global CSS styles that were inherited from the node_modules folder in a Next.js project

I've been attempting to customize the CSS style for a rc-pagination component that was included in a CSS file I already imported in the root component _App. However, despite my efforts to override the styles in the index.css file of this component, no ...

Is it feasible to select the last child of an input without having to specify the submit

Here is a portion of the HTML code I am currently testing: <form action="#" method="post> <input name="username" type="text" placeholder="Username" /><br /> <input name="password" type="password" placeholder="Password" />&l ...

Achieving full coverage of cell content within a cell area by utilizing align-items in CSS Grid

Is it possible to achieve two conflicting goals using CSS Grid? In my design, I want the content in each cell to be vertically centered using align-items: center; At the same time, I need the entire area of the cell to be filled with color. However, ...

html2canvas bottom margin

I coded this in react function download(element) { html2canvas(element).then((canvas) => { window.open(canvas.toDataURL('image/png')); }); } return ( <div className='box' onClick={( ...

How can I use a CSS file in PHP to conceal the folder structure?

main.css $theme->assign('css_file',SITE_URL.'styles.php?theme='.THEME_ID); $theme->display(TEMPLATES_PATH.'header.tpl'); header.tpl <link rel="stylesheet" href="{$css_file}"> styles.php include TEMPLATES_PATH. ...

Container Slides Along Despite Accurate Measurements

In a recent project of mine, I utilized two containers positioned side by side. Upon clicking a button, my goal was to have the content container (essentially a false body) decrease its width while the menu container would slide in. Despite my best effort ...

CSS designs that adapt with the screen: Triangles in

I'm currently working on creating a responsive triangle using CSS. I want both the height and width of the triangle to adjust as the window size changes. Below is my static code: #triangle { z-index: 2; width: 0; height: 0; position:absolute ...

Enhancing Your Website with Animation Delay using Animate.css and ViewportChecker

I am attempting to apply a delay to various elements with animated classes on a specific webpage using animate.css version 3.5.1 by Daniel Eden and jquery-viewport-checker version 1.8.7 by Dirk Groenen. My initial approach was to utilize the setTimeout fu ...

What is the best way to create a fixed positioning for a div within a Material-UI table container?

When using the Material UI Table, I encountered an issue with applying the sticky property. The table itself works fine, but I also have a button inside the TableContainer that should be sticky alongside the table head. I attempted to achieve this by using ...