Stop the border from curving along with the container's border radius

Currently, I am working on a tabs component that features a container with border radius. When a tab item is selected, it should display a bottom border.

However, I'm facing an issue where the border curves along with the border radius instead of remaining horizontal, as illustrated in the desired outcome image:

Desired Outcome

https://i.sstatic.net/HTkdZ.png

What I've Attempted

I have tried various approaches to tackle this problem. One attempt involves styling the selected tab with a bottom border, but it extends beyond the border-radius rather than being cut off as intended. Additionally, I experimented with using CSS's :after pseudo-element to truncate the border, but the result did not seamlessly merge into the radius as desired.

Another strategy I explored was tying the border radius to the tab icon, as shown below:

body {
  background-color: #121212;
}

.wrapper {
  padding: 15px;
}

.tabs {
  background-color: #211F22;
  display: flex;
  height: 60px;
}

.tab {
  align-items: center;
  color: white;
  display: flex;
  flex: 1;
  justify-content: center;
}

.first {
  border-top-left-radius: 15px;
  border-bottom-left-radius: 15px;
}

.last {
  border-top-right-radius: 15px;
  border-bottom-right-radius: 15px;
}

.selected {
  border-bottom: 2px solid #7D53DA;
}
<div class="wrapper">
  <div class="tabs">
    <div class="tab first selected">
      Tab 1
    </div>
    <div class="tab last">
      Tab 2
    </div>
  </div>
</div>

Nevertheless, the challenge with this approach is that the border follows the curve of the radius, which is not ideal. Do you have any suggestions on how to achieve this design using CSS?

Answer №1

To achieve this desired effect, consider using a clever trick involving an inset box-shadow. Set the shadow with a high negative h-offset value, no blur, and a spread equal to the h-offset minus the desired border height.

For instance, for a bottom border of -5px, try the following CSS:

box-shadow: inset 0px -505px 0px -500px red;

Take a look at the demonstration here: https://jsfiddle.net/ynwem642/

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

Select a specific element to apply a CSS selector for a button

One of the challenges I am facing involves a webpage with multiple submit buttons. My goal is to iterate through each button and click on them one by one. While I am aware that this can be achieved using xpath like this (//button[@class='submit' ...

Converting intricate HTML table data into JSON format with the help of jQuery

Looking to extract JSON data from selected rows in the HTML table below using jQuery. The JSON output should include any user-entered comments from the textboxes. Any guidance or suggestions would be greatly appreciated. <table id="potable_grid" class ...

How to Manage Empty Lines in HTML Documents within WordPress

Just recently, I launched my brand new website. Everything seems to be functioning properly except for one issue that I discovered in the HTML source code. There are 15 blank lines before "<!doctype html>", which is causing some problems with SEO and ...

Why does the URL keep adding the link every time I click on an "href" link?

I have a button labeled <a href="home.jsp">Home</a> and another link <a href="CRUD/Books/Add.jsp">Add</a> If I click on Home and then Add, everything works fine. However, if I click on Add again, the URL starts to multiply like ...

Tips for effective page management

After creating a navbar in my project, I've come to the realization that it requires a component for each page and subpage. This seems redundant especially when dealing with multiple navigation options like shown in this image. Is it necessary to crea ...

The touchstart event is activated when you touch an item within

Is it possible to retrieve the index of ul li elements with touchstart, similar to how it can be done with a click function? <ul id = "list" ontouchstart="touchStart(event,'issues')"> <li> ...

Using a combination of PHP and HTML, you can successfully transfer and save a

I am having trouble uploading a file to the server in PHP and HTML using move_uploaded_file(). When I use this URL , the process is successful. However, when I use this URL , the process fails. Here is my PHP code: <?php if (isset($_FILES['image& ...

Scroll sideways with AJAX content replacement

I've successfully discovered various methods for loading and replacing content with ajax, as well as ways to hide/show with effects. However, I'm now seeking a technique that allows the new content to slide into a div while the old content slide ...

JavaScript code does not seem to be functioning properly on my computer, but it works perfectly fine on

While the code functions perfectly in JSFiddle, it seems to fail when I try to implement it in an HTML file. Despite my efforts, I am unable to pinpoint the source of the issue. If you'd like to view the working version, here is the Fiddle demo. Bel ...

Automatically redirect to the linked page once the video concludes

Would it be feasible for a html5 video to trigger the opening of a new page upon completion? What would be the approach to achieve this using javascript? ...

What is the best way to ensure that this jQuery window has a minimum size?

Recently, I came across a helpful jQuery demo that demonstrated how to create a popup window on my website. For those interested, the demo link can be accessed here: http://jqueryui.com/dialog/#modal-message The design of the window I am aiming to replica ...

difficulties arise when adjusting font size in html and css

When I first created an all HTML/CSS website, I used clickable images as a menu that scaled perfectly on all monitors and browsers. Now, for my new project, I wanted to use a background image for the menu with hyperlinked text on top. I thought setting the ...

How to eliminate the external white border from a Java applet when it is integrated into an HTML webpage

As someone experienced in dotnet, I decided to venture into creating a Java applet for my application. After successfully developing and signing the applet, it functioned perfectly within my application. However, one issue perplexed me - when I attempted ...

The angular2-webpack-starter kicks off with a simple static page

When starting my project using angular2-webpack-starter, the initial loading of index.html allows us to create our own components. However, in my case, I am looking to first direct users to a static page without any Angular code before clicking a button th ...

The Jquery Addclass function is not functioning properly

I have been struggling with this code as it seems to not be working in any browser, including IE, Chrome, and Firefox. I suspect that the system should add a class, so I checked the DOM using Chrome's console. I did see the class being added, but ther ...

What steps can I take to prevent constantly re-fetching a disabled CSS file?

I'm currently in the process of implementing a dark theme on my website, and my current method involves using 2 style sheets: <link rel="stylesheet" type="text/css" href="/flatly.css"> <link rel="stylesheet& ...

Unable to locate the hidden element

Attempt to access the attribute of a shadow element resulted in encountering ElementNotVisibleException Element with CSS input[type='checkbox'] is not present on screen <checkbox _ngcontent-ebv-c14="" label="User Access" ng ...

I'm attempting to utilize a basic webcam capture upload feature, but it seems that the upload function is not functioning properly

UPDATE: This is the complete code that I simply copied and pasted. <!DOCTYPE HTML> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script language="JavaScript" type="text/javascrip ...

Adding a half circle connector in HTML can be accomplished by using SVG (Scal

My task is to replicate the construction shown in this image: https://i.sstatic.net/kaRMO.png I have written the entire code but I am unsure how to include a half circle next to the full circle and connect it with a line connector. Here is my code: .ps- ...

Showing pictures from directories outside the web root (public_html)

Situation: I have a collection of images stored in a directory named uploads or images located outside the website's main folder (outside of public_html). My goal is to display one of these images inside a file called image.php. Guidelines for achi ...