Tips on aligning border-radius with parent border-radius

Seeking to create a text box with a sleek line on the left side for design flair. The challenge arises when attempting to match the thickness of the line with the border radius of 10px. After various unsuccessful attempts, here is the current solution:

div {
  position: relative;
  width: 400px;
  height: 200px;
  background-color: rgba(0, 255, 50, 0.3);
  border-radius: 10px;
}

div::before {
  content: "";
  position: absolute;
  top: 50%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
  left: 0;
  width: 5px;
  height: calc(100% - 3px);
  background-color: rgba(0, 150, 0, 0.5);
  border-radius: 5px 0 0 5px / 10px 0 0 10px;
}

p {
  position: absolute;
  top: 40%;
  left: 35%;
}
<div>
  <p>Make me beautiful!</p>
</div>

Is there a way to successfully achieve this relationship between line thickness and border radius?

Edit: Utilizing the same variable for background color unity between the line and box, followed by applying a filter to darken the line.

Answer №1

If your goal is simply to add some decorative elements, consider using a gradient:

div {
  position: relative;
  width: 400px;
  height: 200px;
  background: 
   linear-gradient(rgba(0, 150, 0, 0.5) 0 0) /* color */
     left / 5px 100% no-repeat, /* position / width height */
   rgba(0, 255, 50, 0.3);
  border-radius: 10px;
}

p {
  position: absolute;
  top: 40%;
  left: 35%;
}
<div>
  <p>Transform me into a masterpiece!</p>
</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 could be the reason for my Form styling failure?

Currently working on freecodecamp's portfolio creation exercise. It should be a straightforward task, but I'm facing a small issue that's puzzling me. I'm trying to remove the border and outline (when focused) from my contact-area form ...

Clip the text with ellipsis if it exceeds the limit and show the file

Currently working on an upload feature where I need to show the name of the uploaded file. File Name.txt The problem arises when the name is too lengthy, resulting in a display like this: File Name Is Too Long...txt I attempted to solve this by implement ...

What is the best way to display two tables together using inline styling?

I attempted to display 2 tables inline by setting their display property to inline, but unfortunately, it did not work as expected. Is there a more straightforward way to achieve the desired inline display for these tables? table { display: inline; } ...

Hyperlink -> Boundary

Our homepage features various elements as part of the menu. Each element consists of a picture, title, and small description. The issue is that these menu items always display a border when the mouse hovers over them, despite attempts to hide it. You can ...

A Challenge with Session Variables in Internet Explorer 8 and Classic ASP

I run a website that has a stock management system with a table displaying stock and inventory information. When the "images" link is clicked, the Session variable for images switches between "show" and "hide" and then reloads the page with the updated va ...

Potential Performance Issue with Material UI's withStyles Function

I've been given the task of optimizing the loading speed of a page in our react redux web app. When the page load action is triggered, there seems to be a slight freeze lasting about half a second. After checking the profiler, everything seems fine ...

Ways to trigger the onclick event from different controls

I have a videojs player and a button on my html page. The videojs player supports the functionality to pause/play the video when clicked. I want to trigger this event by clicking on my button. How can I achieve this? Here is the code that I tried, but it ...

Try using Bootstrap 4 Carousel columns instead of the traditional carousel-item

Is it possible to use Bootstrap to display grid columns or rows within a Carousel instead of carousel-items? The concept involves having intricate grid column structures that rotate like carousel-items. For instance, if we have the following grid: <div ...

"Enhance your website with a dynamic hover effect and striking letter spacing in

In the div below, there is a span with the following code: <div class="mission-button"><span class="mission">view our mission</span></div> Accompanied by this CSS: .mission-button::before { content:'&ap ...

Troubleshooting the non-functioning addEventListener in JavaScript

I am facing an issue where a function that should be triggered by a click event is not working and the console.log message does not appear <script src="e-com.js" async></script> This is how I included the javascript file in the head ...

Trouble with CSS animations in ThreeJS's CSS3DRenderer

Seeking a way to incorporate plain text (2D or 3D) into a threeJS scene while applying CSS effects, I stumbled upon this resource. It seemed to offer the solution I was looking for. However, when I tried to apply an animate.css class (a well-known CSS anim ...

execute php function when form is submitted

Hello, I am attempting to create a code using this PHP function: <?php function generateRandomString($length = 6) { return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/str ...

Requesting for Nav to be positioned directly below the header, in a fixed manner, with no overlapping

After successfully resolving the issue of my header overlapping content, which was thanks to your help, I encountered a new challenge. I was advised to group my navigation bar with my h1 header for a fixed position but doing so caused everything to go hayw ...

What is the best method for arranging checkboxes in a vertical line alongside a list of items for uniform alignment?

Trying to come up with a solution to include checkboxes for each item in the list, maintaining even vertical alignment. The goal is to have the checkboxes in a straight vertical line rather than a zigzag pattern. Coffee Nestle ...

Content from ajax request is invalid

Currently, I am facing an issue with loading a comment list and replacing the existing list on my HTML page with the new one. Previously, I used to load a simple XML list, iterate over its elements, and generate content. Although this method worked fine, i ...

The Android Webview is experiencing difficulties with loading CSS styles and displaying the blockquote font color effect

I am facing an issue with loading HTML content in CSS through Android WebView. Despite having the code executed, I don't see any observable changes in font color for the text inside blockquote tags Here is the HTML code: <html> <head> ...

Creating a full-width tab card with Bootstrap-Vue: A step-by-step guide

I stumbled upon something similar in the documentation for bootstrap-vue: A card with tabs: Now, how can I style the tabs to look like this: This is my current code: <b-card no-body> <b-tabs card> <b-tab title="Tab 1" active& ...

Simple steps for integrating JavaScript ads into your WordPress website

Received an advertisement from my client, a 300x250 ad in ad folder consisting of 1 HTML file, 1 JavaScript file, and 1 images folder. Questioning how to integrate these files into the side panel of my Wordpress website's homepage. I've spent a ...

Implementing JavaScript Code in TypeScript

Every JavaScript code should also be valid in TypeScript, but when attempting to run the following code snippet below, an error is triggered. Could someone convert this JavaScript code into TypeScript? Error: 20:9 - TS2531 Error: Object is possibly 'z ...

Adding CSS styles on hover with Jquery append

Currently, I am attempting to use jQuery to append hover CSS styles to buttons. While I have been successful in applying the desired styles upon hovering over the button, the issue arises when the mouse moves away - the styles remain. Here's the code ...