What is the best way to make this CSS arrow see-through?

My goal is to achieve this desired outcome:

Currently, I have the following (focusing only on the left element for now):

I am struggling to make the left arrow transparent and I can't seem to figure out how.

This is the CSS Code I have so far:

.main_container .photo_container .mask a {
    color: #FFFFFF;
    font-size: 25px;
    position: relative;
}

.main_container .photo_container .mask a:first-child {
    border: 1px solid #FFFFFF;
    padding: 5px 11px 7px;
}

.main_container .photo_container .mask a:first-child::before {
    border-bottom: 7px solid transparent;
    border-right: 7px solid rgba(0, 0, 0, 0.2);
    border-top: 7px solid transparent;
    content: "";
    display: inline-block;
    left: -8px;
    position: absolute;
    top: 20px;
}
.main_container .photo_container .mask a:first-child::after {
    border-bottom: 24px solid transparent;
    border-right: 25px solid #eee;
    border-top: 24px solid transparent;
    content: "";
    display: inline-block;
    left: -26px;
    position: absolute;
    top: -1px;
}

This is the corresponding HTML Code:

<div class="photo_container">
    <img src="images/placeholder/car1.png" class="img-responsive" alt="" />
    <div class="mask">
        <a href=""><i class="fa fa-search"></i></a>
        <a href=""><i class="fa fa-link"></i></a>
    </div>
</div>

Any assistance would be greatly appreciated!

Answer №1

If you're open to utilizing the transform property, here's a straightforward approach:

To achieve this effect, create a pseudo element positioned after the original one, center it correctly, and apply a 45-degree rotation.

The calculation for the 70.71% figure involves using s = q / sqrt(2), where s represents the side length of a square and q denotes the diagonal length.

.arrow
{
    border:             1px white;
    border-style:       solid solid solid none;
    position:           relative;
    width:              50px;
    height:             50px;
}

.arrow::after
{
    content:            "";
    display:            block;
    top:                50%;
    left:               0;
    position:           absolute;
    border:             1px white;
    border-style:       none none solid solid;
    width:              70.71%; /* the side of a square is 70.71% the length of its diagonal */
    height:             70.71%;
    transform:          translate(-50%, -50%) rotate(45deg);
}

To customize which borders are displayed and adjust the positioning for the arrow to show up on the desired side, make the following tweaks:

body
{
background-color:     black;
padding:              50px;
}

.arrow_left,
.arrow_right
{
display:            inline-block; /* for side-by-side placement */
border:             1px white;
position:           relative;
width:              50px;
height:             50px;
}

.arrow_left  { border-style: solid solid solid none; }
.arrow_right { border-style: solid none solid solid; }

.arrow_left::after,
.arrow_right::after
{
content:            "";
display:            block;
top:                50%;
position:           absolute;
border:             1px white;
width:              70.71%; /* the side of a square is 70.71% the length of its diagonal */
height:             70.71%;
transform:          translate(-50%, -50%) rotate(45deg);
}

.arrow_left::after
{
left:               0;
border-style:       none none solid solid;
}

.arrow_right::after
{
left:               100%;
border-style:       solid solid none none;
}
<div class="arrow_left"></div>
<div class="arrow_right"></div>

Answer №2

The arrow on the left cannot have a transparent appearance, as it is actually created by applying a solid border to a quarter of a box.

(Check out this informative article on how the css triangle effect is produced.)

To achieve the desired look, you may need to consider using images or adjusting the graphic design accordingly.

Answer №3

Attempting to use borders to create a transparent triangle has proven unsuccessful. Let's explore alternative methods to achieve our desired outcome. I have devised a simple demonstration - any triangle can be formed by connecting 2 lines (basic trigonometry knowledge required.) http://codepen.io/anon/pen/PPbxEQ - I utilized some variables in CSS and incorporated stylus for better readability of the source code rather than focusing solely on the compiled result. We introduce a pseudo element for the initial icon, rotate it, adjust its height, and then alter the transform origin. It is a straightforward process.

We make adjustments to the angle and recalculate the cosine of the angle;

*,
*:before,
*:after {
  box-sizing: inherit;
}
html {
  box-sizing: border-box;
}
body {
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: url("http://7-themes.com/data_images/out/2/6775415-beautiful-images.jpg");
  background-size: cover;
  background-repeat: no-repeat;
  background-position: 0 0;
  overflow: hidden;
}
html,
body {
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
}

.Icons {
  width: 50vmin;
  height: 25vmin;
  display: flex;
}
.Icon {
  flex: 1;
  border-color: currentColor;
  border-style: solid;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(2vw + 2vh + 4vmin);
  color: #fff;
  position: relative;
}
.Icon + .Icon {
  margin-left: -1px;
}
.Icon:first-of-type {
  border-width: 1px 1px 1px 0;
}
.Icon:last-of-type {
  border-width: 1px 0 1px 1px;
}
.Icon:first-of-type:before,
.Icon:first-of-type:after,
.Icon:last-of-type:before,
.Icon:last-of-type:after {
  content: '';
  position: absolute;
  margin: auto;
  color: inherit;
  background-color: currentColor;
  width: 1px;
  height: calc(50% / 0.866025404); 
}
.Icon:first-of-type:before,
.Icon:first-of-type:after {
  left: 0;
}
.Icon:first-of-type:before {
  top: 0;
  transform: rotateZ(30deg);
  transform-origin: top;
}
.Icon:first-of-type:after {
  bottom: 0;
  transform: rotateZ(-30deg);
  transform-origin: bottom;
}
.Icon:last-of-type:before,
.Icon:last-of-type:after {
  right: 0;
}
.Icon:last-of-type:before {
  top: 0;
  transform: rotateZ(-30deg);
  transform-origin: top;
}
.Icon:last-of-type:after {
  bottom: 0;
  transform: rotateZ(30deg);
  transform-origin: bottom;
}
<div class="Icons">
  <div class="Icon">I</div>
  <div class="Icon">O</div>
</div>

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

When a radio button is checked, add a class to its parent element that has a specific class assigned to it

In order to dynamically add a class to a specific div element higher up the DOM hierarchy when a radio button is clicked, I am in need of assistance. There are multiple instances of these div elements with different radio buttons, so it is crucial that on ...

I am interested in implementing a variable to define rows within a <tr> element in an HTML table

I am facing an issue with finding specific rows in a table by using a variable like /tr[i]/ where i represents the row I want to access. When I hardcode the element in my code, it works perfectly: driver.find_element_by_xpath("//tbody[@class='sample& ...

:Incorporating active hyperlinks through javascript

Hey there, I've encountered a little conundrum. I have a header.php file that contains all the header information - navigation and logo. It's super convenient because I can include this file on all my pages where needed, making editing a breeze. ...

Implementing a configuration file into a client-side web application using asynchronous methods

Currently, I am facing a challenge with an SPA that is being developed using various custom components from different sources. The main issue at hand is how to initialize certain settings (such as Endpoint URLs) using a settings file that can be configure ...

I am adding the main stylesheet to the queue, but for some reason my images are not appearing

I'm in the process of converting HTML to a Wordpress theme. I've successfully enqueued the stylesheet, but unfortunately, some of the images are not displaying properly. It seems like it could be an issue with the subfolder structure. ...

When a table row is selected, set the OnClick attribute of an input to the value of the TD cell in that row based on

I'm really struggling with this. So, here's the issue - I have a table where rows get assigned a class (selected) when clicked on. Now, there's an input inside a form that needs to redirect to another page when clicked, and it also needs t ...

Height CSS does not conceal side bar hyperlinks

CSS .nested-menu { .list-group-item { cursor: pointer; } .nested { list-style-type: none; } ul.submenu { height: 0; } & .expand { ul.submenu { ...

Customizing the width of the JQuery $ui.progressbar by overriding its properties

After spending some time, I successfully overrode the function that controls the width of the progress bar element in the jQuery UI widget version 1.12.1 from September 14, 2016. Initially, I needed the progress bar to completely fill a column in a table. ...

Dynamic background featuring a tall vertical image

I have an image that is extremely long, measuring 2263 x 8192 pixels. I want to design a website with a background that spans the width of the window and the full height of the image, all while maintaining responsiveness. The concept is to have this elong ...

What is the best way to ensure that a child div can expand to fit within the scrollable area of its parent div

I am facing an issue with a parent div that changes size based on the content inside it. When the content exceeds the initial size, causing the parent to scroll instead of expanding, I have a child div set to 100% width and height of the parent. However, t ...

Incorporate audio playback on image click using JavaScript, with the feature to automatically pause the playback if multiple images are playing simultaneously

<img class="cl" src="photo/198.jpg"/></br> <audio class="cs" controls> <source src="audio/198 banu nagamothu.mp3" type="audio/mpeg"> </audio> I prefer not to have audio controls initially, but when the image i ...

What could be the reason for my user input not being captured and saved as variable data on the HTML webpage?

Here is the code I am working with: var g = document.getElementById("al").value; function start() { document.getElementById("test2").innerHTML = typeof(g) + parseFloat(g); } <p id="test2">Output will be displayed here:</p> <form> ...

Transfer the photo and save it to my database

I've been working on creating a form to upload images and store them in my database, but I'm facing some challenges: Notice: Undefined index: fileToUpload in C:\xampp\htdocs\confee\admin\upload.php on line 3 Notice: Un ...

Ways to remove the highlighting from a selected list item using CSS/Javascript

I have a problem with a list of images and keywords that act as selections for users. When a user clicks on a selection, it highlights the corresponding image using CSS shadow. However, I am trying to figure out how to deactivate this highlight later on, e ...

Update the html() function to include any content that has been typed into a

I have a webpage structured like this: <div id="report_content"> Some information <textarea name="personal"></textarea> <b>Other information</b> <textarea name="work"></textarea> </div> Whe ...

Is there a way to set the background of the first sibling element to blue, but change it when another sibling element is hovered over?

I have a list of names: <div>Timothy Gruns</div> <div>Lawrence Fishly</div> <div>Jackson Crolya</div> What I want is for the background color to change to blue when any name is hovered over. However, if no names are be ...

Utilize custom fonts from your local directory within a Vite Vue3 project

Inside my main.scss file, I am loading local fonts from the assets/styles/fonts folder: @font-face { font-family: 'Opensans-Bold'; font-style: normal; src: local('Opensans-Bold'), url(./fonts/OpenSans-Bold.ttf) format('truety ...

Modify the div's visibility based on selected option in the dropdown menu

In my PHP file, I have the following codes: <section id="placeOrder"> <h2>Place order</h2> Your details Customer Type: <select name="customerType"> <option value="">Customer Type?</option> <option value="ret ...

Combine React 17 with webpack 5 and babel-plugin-react-css-modules, enabling the use of CSS modules with stylename functionality

I am in the process of setting up a new React application using the latest technologies available, including React 17, Webpack 5, and other essential modules. My goal is to implement CSS modules utilizing the styleName concept with the help of babel-plugi ...

I am facing difficulties displaying Arabic language characters on my HTML code

I created a website and included the following meta tag in the head section: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> However, all Arabic text appears distorted as shown in the image. Interestingly, when I manually cha ...