Allow an arrow to link between two separate div elements

I'm looking to create something similar to this:

representation

Although I've come across similar issues, none of them fully address my task. Here is an example that I found:

.blue-background {
  background-color: blue;
  border-radius: 5px;
  top: 3em;
  left: 230px;
  padding: 10px;
  font-family: Roboto, sans-serif;
  font-size: 14px;
  line-height: 22px;
  color: #313333;
  display: flex;
  align-items: center;
  width: 260px;
}

.blue-background::after {
  content: ' ';
  width: 0px;
  height: 0px;
  border-top: 25px solid transparent;
  border-left: 37px solid blue;
  border-bottom: 25px solid transparent;
  border-right: 0px solid transparent;
  position: absolute;
  top: 43%;
  left: 47%;
}

.child-image-wrapper {
  max-width: 260px;
  margin: auto;
  img {
    max-width: 260px;
  }
}
<div class="col-md-4 col-xs-12">
  <div class="image-block">
    <div class="blue-background">
      <h2>Some Text <span class="arrow"></span></h2>

    </div>
    <div class="child-image-wrapper">
      <img src="This is an image" />
    </div>
  </div>

The issue with the CSS above is that it only works at a specific screen size (around 585px), causing the arrow to "detach" from the left div and move into the right div. What I want is for the blue arrow to stay attached to the left div regardless of screen size. Is there a way to achieve this? I apologize for being new to front-end design.

Answer №1

If you want to achieve this, follow these steps:

.container {
  width: 10em;
  height: 2em; /* Make sure it matches the height and width of .right::after */
  display: flex;
}

.left {
  background-color: lightblue;
  width: 50%;
}

.right {
  background-color: lightpink;
  border-left: 1px solid purple;
  width: 50%;
  position: relative;
  overflow: hidden;
}

.right:before {
  height: 2em; /* Should match the height above */
  width: 2em; /* Should match the width above */
  background-color: #b77681;
  position: absolute;
  top: 50%;
  left: 0%;
  content: "";
  border: 1px solid #864954;
  transform: translate(-73%, -50%) rotate(45deg);
}
<div class='container'>
  <div class='left'>

  </div>
  <div class='right'>

  </div>
</div>

Answer №2

Exploring the intricacies of the position property, particularly when using absolute and relative, can lead to a deeper understanding of CSS positioning. Take a look at this helpful guide here.

If you're looking to customize the position of an arrow, consider adjusting the top and left properties within the .blue-background::after selector to achieve your desired placement.

For reference, here's a practical demonstration: https://jsfiddle.net/qa9un7fy/

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

Warning in Next.js: When utilizing conditional rendering, the server HTML is expected to have a corresponding <div> inside another <div>

Although similar questions have been asked on various platforms like Google, none seem to provide answers that align with my specific situation. Essentially, my goal is to have a different search bar displayed in the header based on the page I am currentl ...

Saving functions in the localStorage API of HTML5: A step-by-step guide

I have encountered an issue while trying to store an array in local storage using JSON.stringify. The array contains functions (referred to as promises) within an object, but it seems that when I convert the array to a string, the functions are removed. Su ...

Turn off the CSS hover effect for a custom button if the ng disabled attribute is set to true

My goal is to disable custom buttons, and the disable(pointer) function is working correctly. The issue arises when we try to hover on the button, as the hover effect still works. I therefore need to disable hover as well. I am looking to apply ng-disabl ...

Diagonal-left ending div in cascading style sheets

Looking to achieve a div with a diagonal side similar to the image in the link below: https://i.sstatic.net/u9grW.png I'm trying to figure out the best way to do this. One idea is to position 2 divs closely together and rotate one of them. Alternativ ...

Small hiccup in jQuery leading to duplicate entries in the field

I am attempting to use jQuery to add the value of a select box to both a hidden input field and a div that is displayed in public view. Below is the code I have: <script type='text/javascript'> $("#departments_submit").click(function(){ ...

The functionality to clear the input search text upon clicking is malfunctioning

Why isn't this basic script working as expected? It has worked fine in the past, but now it's not functioning properly. <form name="form1"> <input type="search" placeholder="Search..." required="required" onfocus="if(this.value == &ap ...

Quick and hassle-free form editing is a breeze with our user-friendly platform

Currently, the forms I have require certain files to be filled out before the submit button can be clicked. What I need is for the 'Title' field at the top of the list to also be marked as required. I know how to accomplish this for text fields, ...

Discovering the selected radio button following a div's appearance

How do I determine which radio button is selected after clicking a specific div? For instance: <div class="largelines"> <p class="line">OPTION 1</p> <div class="delete"> <a href="#" title="Delete"></a> ...

Integrating data binding within a .append function using AngularJS

I followed this code example (http://jsfiddle.net/ftfish/KyEr3/) to develop a form. However, I encountered an issue with an input having ng-model set to "value" and needing to display that value within {{ }} in a TD: angular.element(document.getElementByI ...

Utilize Cordova's social share plugin to send a text message containing a variable

I have implemented the social share plugin from Cordova in order to share SMS messages with a specific phone number. <a class = "lft" onclick="window.plugins.socialsharing.shareViaSMS('My cool message', 7767051447, function(msg) {cons ...

When the button with an image is clicked, it will display a loading element

I have developed an application that heavily utilizes ajax, and I am looking to implement the following functionality: I would like to have a button with both text and an image. When this button is clicked, it should be disabled, and instead of the origina ...

Problem encountered with modal and JavaScript: Uncaught TypeError: Unable to retrieve the property 'classList' of null

Trying to implement a modal feature for the first time but encountering an error when clicking the button. Unsure if I'm following the correct procedure as a JS beginner. Any assistance would be appreciated. ERROR { "message": "Uncaugh ...

What is the best way to gather the "name" and "value" attributes from a designated section of a form using JavaScript and store them in an array?

How can I extract the "name" and "value" attributes from a specific section of a form and store them in an array using JavaScript? Here is the section of the form in question: <div class="multiPickerForm"> <input type="text" name="Id" value="1"& ...

What could be causing unexpected results when Rails 2 encodes apostrophes in HTML?

When using h to HTML encode text in Rails 2, I'm encountering issues with apostrophes. Specifically, my apostrophes are being displayed as &#39;, which is not the desired outcome. Has anyone experienced this issue before? My understanding was tha ...

Creating a Dynamic Grid Layout: A Step-by-Step Guide

Having created a specific grid layout using HTML and CSS, I am struggling to make it work across all devices. I have already created the CSS, but I seem to be missing something in the HTML, such as the col-md or col-sm classes from Bootstrap. However, ever ...

How to centrally align text in list items using Bootstrap 5

Incorporating Bootstrap 5 into my project, I am facing a challenge with vertically aligning text in an li element. Despite trying various techniques mentioned in the Bootstrap documentation for middle/center alignment, none of them seem to be effective. I ...

HTML Email Not Displaying Properly in Outlook

My email is displaying correctly on webapps and browsers, but the layout is off on Outlook client version 2102 (build 13801.21106). I've tried adjusting cellspacing, cellpadding, and width, but nothing seems to work. https://i.sstatic.net/HrRlE.png h ...

Is there a way to apply a setTimeout to a <div> element upon the first click, but not on subsequent clicks?

Check out the fiddle I've created: http://jsfiddle.net/dkarasinski/dj2nqy9c/1/ This is the basic code. I need assistance with a functionality where clicking on a black box opens a black background and then after 500ms a red box appears. I want the ...

Ways to halt a script entirely once its tag has been eliminated

I have a script from a page tracker website that runs periodically. Occasionally I need to restart the script from the beginning. To do this, I typically remove the script tag from the DOM and then re-append it. However, because the script utilizes setInt ...

Can CSS alone be used to provide a cover for auto-scaling images?

One common technique is using max-height and max-width to make an image automatically fit in a div, as shown below: .cover img { max-width: 100%; max-height: 100%; } But is there a way to create a translucent cover (with opacity set to 0.8) that ...