Can I create a div with a rounded right side?

Is there a way to give a div a slightly rounded right side using CSS? If so, can you show me how in this fiddle template: http://jsfiddle.net/z2hejemu/

HTML

<div class="rounded-side">
    <p>By default, this div is rectangular. I would like to round the right side of it, if possible. </p>  
</div>

CSS

div.rounded-side {background-color:yellow;padding:10px;}

div.rounded-side > p {font-size: 36px;}

Answer №1

If you're aiming to achieve a semicircle, you can make use of the scaling requirement outlined in the specification. The trick lies in employing the border-radius property with significantly large and equal values (refer to this fiddle http://jsfiddle.net/gLsd2z4L/ based on your initial code):

div.rounded-side {
    background-color:yellow;
    padding:10px;
    border-radius: 0 100em 100em 0;
}

div.rounded-side > p {font-size: 24px;}
<div class="rounded-side">
    <p>This div is by default rectangular in shape.
       I'd like the right side of it to be rounded, if that's possible. </p>  
</div>

The reason behind this methodology, as explained in the specification, is:

Corner curves must not overlap: When the sum of any two adjacent border radii exceeds the size of the border box, UAs must proportionally reduce the used values of all border radii until none of them overlap.

In this situation, the combined radii measure up to 200em; assuming that the height (or width) of your element is less than this total, the radii will be scaled down uniformly. By selecting identical values for the radii and opting for very large figures (beyond the reach of the element's dimensions), the browser is prompted to carry out the necessary scaling.

In reference to the link shared by Stephen P in a comment on another response titled "The curious case of border-radius:50%", they recommend using 9999px; my preference for 100em is purely aesthetic. Unless specific units/values impact performance (which is highly unlikely), the choice between options doesn't matter much, as long as the radii are uniform and collectively exceed the element's size.

Answer №2

Don't forget to include the border-radius property: http://jsfiddle.net/z2hejemu/3/

div.rounded-side {
    background-color:yellow;
    padding:10px; 
    -webkit-border-radius: 0 10px 10px 0;
    border-radius: 0 10px 10px 0;
}

Remember, the format for border-radius is (in this example): top-left top-right bottom-right bottom-left

Answer №3

Here is a solution that can help address your problem.

div.rounded-side {
    border-radius:0 20px 20px 0;
} 

Answer №4

<!DOCTYPE html>
<html>
<head>
<style> 

div 
{
border: 2px solid #a1a1a1;
padding: 10px 40px; 
background: #dddddd;
width: 300px;
border-top-right-radius: 2em;
border-bottom-right-radius: 2em;
-webkit-border-top-right-radius: 2em;
-webkit-border-bottom-right-radius: 2em;
-moz-border-top-right-radius: 2em;
-moz-border-bottom-right-radius: 2em;
}

</style>
</head>
<body>

<div>The border-radius property gives elements rounded corners.</div>

</body>
</html>

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

Angular2 - the pipe was not located while organizing records

I've successfully fetched data from an API and displayed it in the view, but I'm struggling to organize the data by date. Whenever I attempt to do so, I encounter this error message: The pipe 'groupBy' could not be found pipe.ts impor ...

The tabs are visible in the drawer, but the transition is not occurring

I am a beginner when it comes to using material ui. After clicking on advanced sports search, a drawer pops up. I have been trying to incorporate tabs in the drawer, but every time I click on tab two, the drawer closes. In reality, it should switch between ...

Why are my images only 1 pixel tall in Internet Explorer 8?

<img src="blah.png" width="150" height="auto"> When viewed in Firefox, Chrome, or Safari, the image will appear as intended. However, Internet Explorer may cause the image to display at a height of only 1 pixel while maintaining the width of 150 pix ...

Toggle the hamburger menu using JavaScript

How can I close my hamburger menu when clicking a link for one page navigation? The menu is functioning properly, but I need a way to close it. Unfortunately, I have limited knowledge of JS. I only have the HTML and CSS for this: HTML in index.html file ...

When there are spaces in the button, it will result in the button creating a new line within the Navbar

There is a line break in the navbar when a space is added to the button text The CSS for the Navbar is manually inputted (Utilizes Bootstrap) <img src="images/SCP_Logo.jpg" style='width: 100%; max-width:100%;'> & ...

The display:block-inline feature seems to be malfunctioning

Even though I've specified the width of columns as 25%, the boxes are still not aligning in a single line: ...

Identifying a flaw in an HTML5 video

I am attempting to identify when an error occurs while playing an HTML5 video. Specifically, I am encountering a situation where I am trying to play an HLS video on a MAC (where "canPlayType" is at least "maybe"), but the video will not play for unknown r ...

Creating dropdown options within a DataGrid in Form.IO: A step-by-step guide

I'm currently working with the Form.IO JS library to develop a new form. Within this form, I need to include a DataGrid containing 11 components. To ensure all components fit inline, I have applied the CSS rule overflow: auto (overflow-x: auto; overfl ...

Displaying a single row of a PHP array in bold formatting

I have a MySQL query result showing user information and subjects they have chosen. I want to highlight one specific row by making it bold using PHP while keeping the rest as regular text. How can I achieve this? $resultSet = $db->query ("...my q ...

Collapsing Bootstrap menu bar causing logo overlap

When the navbar collapses (when it shows the toggle icon), the menu items (home, services, portfolio, about, contact) overlap with the logo. If I remove the position:absolute from the logo (navbar-brand), the menu appears in the center. Is there a way to h ...

I am looking to adjust the height of my MUI Grid component

Recently exploring React, and I'm looking to set a height limit for MUI Grid. I've structured my project into 3 sections using MUI grid components. My goal is to restrict the page height in order to eliminate the browser scrollbar. If the conten ...

Incorporating user input into a div element

So, I'm in the process of building my own Task Tracker using JavaScript to enhance my skills, but I've hit a roadblock. I successfully implemented adding a new div with user-inputted tasks, however, there's no styling involved. <div cla ...

Guide to vertical centering of inline elements within an inline-block using HTML and CSS

Despite reading numerous resources and articles on vertical alignment/centering in HTML/CSS, I still can't seem to get my specific case working as expected. If you have a moment, please take a look at http://jsfiddle.net/pf29r/3/ <div class="oute ...

Chrome causes Bootstrap to add an additional pixel

I am currently utilizing bootstrap to design a webpage. I have divided the body into two segments: content and header. Within the content block, there is a div with the class .container .sameTable, inside of which resides another div with the classes .row ...

What is the best way to create a border of white space around the background color of a table cell using CSS?

Is there a way to create a white space around the background color of a table cell using CSS? My current code has the background color extend all the way to the edge, and padding only affects the content, not the background color. #main-monitor { widt ...

How can HtmlUnit be used to identify and address website pages that display errors?

I've encountered an issue while trying to access this Ajax page through my Java program using the HtmlUnit 2.15 API. It seems that the problem arises from a broken link to a missing file located here. This is the snippet of code I'm working with ...

Struggling to make the fgetcsv file function seamlessly with my MySQL database

I have been attempting to use the fgetcsv function to import all rows of a CSV file into my database. This functionality should be straightforward, but for some reason it is not working as expected. Below is the code I am using: <?php $file = $_FILES[ ...

In React js, I wanted to display the animation specifically on the "add to bag" button for the added item

When I click the "add to bag" button, all other buttons also display the animation. How can I make sure that only the clicked button shows the animation? Any suggestions? <Table responsive> <thead> <tr> ...

optimal method for organizing design elements

I have a container with 9 square-shaped divs that I want to arrange in the following layout: It should resemble something like this: _________ ____ ____ | A | B | C | | |____|____| | | D | E | |_________|____|____| | F | G | ...

Tips for modifying a text input in a list

Managing comment boxes and buttons for each box can be a bit tricky. Clicking on the edit button should enable only that specific textbox, while save or cancel actions should hide the text box and show "<p></p>". Below is my ng-template where ...