Problem with pseudo element hover effect on margin and padding

I designed four interactive boxes, where clicking or hovering on one box increases the padding or margin, causing it to overlap with the adjacent boxes.

I attempted the following CSS:

.marketing-service.active {
   margin: 0;
}

and

.marketing-service.active:hover {
   margin: 0;
}

However, both strategies failed to resolve the issue. To reproduce the problem, ensure that one box is on the second row and then click on the first box before hovering over it.

How can I maintain the original position of all boxes while eliminating the extra spacing caused by the down arrow?

$('#marketing-tab1').addClass('active');
$('#marketing1').show();
  
$('.marketing-service').click(function() {
$('.marketing-service.active').removeClass('active');
$(this).toggleClass('active');

//To display service box
var item_number = $(this).attr('id').replace('marketing-tab', '');
/* $('html, body').animate({
scrollTop: $("#service-display-box").offset().top
}, 1500); */
$('#marketing'+item_number).show().siblings('.marketing-service-section').hide();
});
#marketing-services {
width: 80%;
margin: 0 10%;
}

.marketing-service {
display: inline-block;
width: 22%;
margin: 0 2%;
height: 400px;
background: #F0F0F0;
position: relative;
cursor: pointer;
}

.marketing-service:first-child {
margin-left: 0;
}

.marketing-service:last-child {
margin-right: 0;
}

.marketing-service:hover {
background: rgba(0, 255, 170, .4);
z-index: 1;
}

.marketing-service-wrap {
padding: 10%;
width: 80%;
}

.marketing-service-title {
font-size: 1.6em;
margin-bottom: 100px;
}

.marketing-img {
width: 125px;
height: 125px;
}


/*-- Down Arrow for boxes --*/

.marketing-service.active,
#marketing-tab1.active {
background: rgba(0, 255, 170, .4);
}

.marketing-service.active:after,
.marketing-service.active:before,
#marketing-tab1.active:after,
#marketing-tab1.active:before {
top: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
}

.marketing-service.active:after,
#marketing-tab1.active:after {
border-width: 0px;
margin-left: 0px;
border-color: rgba(0, 255, 170, .4);
border-right-color: rgba(0, 255, 170, .4);
margin-top: -30px;
}

.marketing-service.active:before,
#marketing-tab1.active:before {
border-color: #FFF;
border-top-color: rgba(0, 255, 170, .4);
border-width: 36px;
margin-left: -36px;
margin-top: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="marketing-services">
  <div class="marketing-service" id="marketing-tab1">
    <div class="marketing-service-wrap total-center">
      <h2 class="marketing-service-title">A</h2>
      <img src="../images/marketing-seo.png" class="marketing-img">
    </div>
  </div>
  <div class="marketing-service" id="marketing-tab2">
    <div class="marketing-service-wrap total-center">
      <h2 class="marketing-service-title">B</h2>
      <img src="../images/marketing-ppc.png" class="marketing-img">
    </div>
  </div>
  <div class="marketing-service" id="marketing-tab3">
    <div class="marketing-service-wrap total-center">
      <h2 class="marketing-service-title">C</h2>
      <img src="../images/marketing-conversion.png" class="marketing-img">
    </div>
  </div>
  <div class="marketing-service" id="marketing-tab4">
    <div class="marketing-service-wrap total-center">
      <h2 class="marketing-service-title">D</h2>
      <img src="../images/marketing-email.png" class="marketing-img">
    </div>
  </div>
</div>

Answer №1

Edit your CSS to remove the line border-color:fff:

.marketing-service.active:before,
#marketing-tab1.active:before {
  border-color: transparent;
  border-top-color: rgba(0, 255, 170, .4);
  border-width: 36px;
  margin-left: -36px;
  margin-top: 0;
}

Here is the corrected code snippet:

$('#marketing-tab1').addClass('active');
$('#marketing1').show();
  
$('.marketing-service').click(function() {
  $('.marketing-service.active').removeClass('active');
  $(this).toggleClass('active');

//To display the service box
var item_number = $(this).attr('id').replace('marketing-tab', '');


$('#marketing'+item_number).show().siblings('.marketing-service-section').hide();
});
#marketing-services {
  width: 80%;
  margin: 0 10%;
}

/* Rest of the CSS code here... */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="marketing-services">
  <div class="marketing-service" id="marketing-tab1">
    /* Content for marketing tab 1 */
  </div>
  <div class="marketing-service" id="marketing-tab2">
    /* Content for marketing tab 2 */
  </div>
  <div class="marketing-service" id="marketing-tab3">
    /* Content for marketing tab 3 */
  </div>
  <div class="marketing-service" id="marketing-tab4">
    /* Content for marketing tab 4 */
  </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

What is the best way to ensure all Bootstrap 4 columns have uniform heights?

Important Note. While this question has been asked numerous times in the past, it is now time for fresh responses as we are approaching the release of Bootstrap 4 which includes full flexbox support. My goal is to achieve equal column height using Bootstr ...

How come my navigation isn't responding to the CSS grid columns I've implemented?

I am currently reviewing Responsive Grid CSS tutorials on YouTube. I am following the instructor's lesson, but I am facing challenges in formatting my nav grid. I have shared both the HTML and CSS code, as well as images showing the comparison between ...

Design inspired by dot matrix patterns

Is it possible to create a background HTML page filled with a dot matrix designing tool? Can anyone provide guidance on how to achieve this? If I need to use a background-image for this, where can I find the appropriate picture? Thank you to everyone in ...

The SVG icon displays properly when viewed on a local machine, but is missing when the website is deployed

Something strange is happening with my SVG sprites. Everything seems to be working fine when I test my code locally, but once deployed on Firebase, one of the SVG images fails to appear. What could be causing this issue? Below is the code for two SVGs: sm ...

Unable to adjust the width of the content and sidebar

I've been attempting to adjust the width of content and sidebar on my website , but I'm not having much luck. It may seem like a simple question, but even after tweaking the CSS, I am still not seeing the desired outcome. Any assistance would be ...

Achieving Dynamic Alignment in CSS: How to Responsively Align a Div to the Width of its Parent Using Padding and Margins

My dilemma could not be clearer - I am struggling to properly align 4 divs within a width of 1150px (the maximum width of the content div). When resizing the screen, I want them to adjust accordingly: 4 in a row when possible, then 3 in the center, and so ...

Enhance Your Navigation with Bootstrap 4's Eye-Catching Link Hover

I'm struggling to implement a hover effect that specifically targets the a-links in the navigation bar without affecting the forwardslashes. It seems like the effect is applying to the entire navbar due to a potential conflict with Bootstrap 4. HTML ...

Enhancing an element by incorporating animation into its active state

For my web assignment, I have received specific instructions regarding a section of the webpage involving five dice: There are five dice in play. When the webpage loads, a three-dimensional image of each dice must be displayed. Upon clicking a dice, it ...

Is it possible for me to use Tailwind CSS in a .css file?

When I began my exploration of Tailwind with react, I encountered a hurdle. I have a strong dislike for inline CSS due to its subpar code readability. Is there a method available that would allow me to write Tailwind CSS in a separate file and then import ...

Achieving Perfect Vertical Alignment in Bootstrap 4 Grid Cells

I am currently working on an admin page that involves querying and reporting on the page weights of key pages on a website, such as landing pages. Bootstrap 4 is in the pipeline, and I have utilized it to design a layout that I am satisfied with. However, ...

Update the background URL of a div element using an HTML tag

My question is about a CSS div with set dimensions and background that I want to change on hover. I am aware that this seems like a simple task, but what I really want to do is retrieve the background sources from within the HTML tag itself. For example: ...

Issue with Angular Bootstrap: Navbar collapsing instead of expanding

I am currently working on an Angular project that utilizes Bootstrap for styling. My goal is to create a menu bar with a dropdown icon that appears when the screen size is too small to display all the menu items. However, I have encountered an issue where ...

Having trouble with Angular2's Maximum Call Stack Exceeded error when trying to display images?

I am facing an issue in my Angular2 application where I am trying to display an image in Uint8Array format. The problem arises when the image size exceeds ~300Kb, resulting in a 'Maximum Call Stack Exceeded' error. Currently, I have been able to ...

The scrolling feature within individual div elements seems to be malfunctioning in Ionic 2

In my current project using Ionic 2, I am faced with the task of designing a screen that contains two distinct grid views. The first grid view needs to occupy 40% of the height, allowing for scrolling within that specified area. On the other hand, the se ...

Tips for resizing the background to match the font size on a canvas marker in Google Maps

Check out my jsFiddle code below: var marker = new google.maps.Marker({ position: new google.maps.LatLng(-25.363882,131.044922), map: map, title:"Hello World!", icon: CanvasCrear("hola", 15) ...

Passing PHP value from a current page to a popup page externally: A guide

I'm currently facing an issue at work where there is a repetitive button and value based on the database. I need to extract the selected value from the current page into a pop-up page whenever the corresponding button is clicked throughout the repetit ...

Which takes precedence: the end of the script tag or the backtick?

Currently, I am working on developing a page builder widget. My goal is to save the entirety of the HTML code for the edited page to both local storage and a database. The PHP script will load the saved HTML from the database, while JavaScript will handle ...

The button labeled "issett" is malfunctioning

Hey there, so I've created a registration form using jQuery and PHP that validates user input in real-time as they type. Once all the information is correct, I want to allow the user to submit the form. My plan is to write an if statement that checks ...

Repairing my CSS with jQuery fullpage.js

My CSS on needs fixing. The word Obert is not aligning properly in the section. Interestingly, everything works fine without Javascript: I suspect the wrapper divs created by the plugin are causing the issue. Can someone lend a hand, please? ...

Tips for adjusting the alignment of the Vuetify component "VDatePicker" based on the position of its parent component on the screen

Currently, I am utilizing the VMenu component from Vuetify which contains another Vuetify component called VDatePicker. The issue arises when clicking on a text field triggers the appearance of the calendar (VDatePicker). Normally, the VDatePicker componen ...