How to make a div rounded only from right and left? [duplicate] - html

This question already has answers here:
Border-radius in percentage (%) and pixels (px) or em
(3 answers)
Closed 2 years ago.
I want to round left and right side of the button like below
Notice that its straight line from top and bottom and only rounded from both sides.
button{
background: transparent;
border: 2px solid black;
font-size: 25px;
border-radius: 50%;
width: 200px;
padding: 5px;
}
<button>View All</button>
I have tried to use border-radius:50% but it made the whole button rounded.

Try like this.
button{
background: transparent;
border: 2px solid black;
font-size: 25px;
border-radius: 999px;
width: 200px;
padding: 5px;
}
<button>View All</button>

You can define a different border radius for the left/right side's of the div.
Try:
button{
background: transparent;
border: 2px solid black;
font-size: 25px;
border-radius: 10%/50%;
width: 200px;
padding: 5px;
}
<button>View All</button>
And experiment with variations of border-radius: 10%/50% like border-radius: 20%/40%...

You can specify each of the four corners radius with two percentages, ie: top-left, bottom-left, top-right & bottom-right. One for each corners horizontal and vertical semi-major and semi-minor axes of the ellipse.
button{
background: transparent;
border: 2px solid black;
font-size: 25px;
border-top-left-radius: 17.5% 50%;
border-bottom-left-radius: 17.5% 50%;
border-top-right-radius: 17.5% 50%;
border-bottom-right-radius: 17.5% 50%;
padding: 10px 25px;
}
<button>View All</button>
See the following Mozilla article for further explanation: MDN: border-radius

Related

Border Radius only rounding the top of a div?

Applying border-radius property on a div with a border only applies it to the top corners. Why is that?
Example:
https://jsfiddle.net/07tqbo56/1/
.asd {
margin-top: 35px;
width: 123px;
border-top-style: solid;
border-top-color: #1163b9;
border-top-width: 70px;
border-radius: 70px;
}
<div class="asd"></div>
This is how it looks like on Firefox 72, Ubuntu 19.
Not only in FireFox, it will look like that in all browsers,
Are you trying to do like this?
Just deleted the "Top" in border-style, -color and -width.
"Top" will do the changes only on the top of the design.
.asd {
margin: 35px;
width: 123px;
border-style: solid;
border-color: #1163b9;
border-width: 70px;
border-radius: 70px;
}
<div class="asd"></div>
I hope this would have solved your problem.
This is happening because your other border properties are only being applied to the top border, for example, border-top-style needs to be just border-style.
When only one border is solid, some browsers apply border-radius to just that border, while others still apply it to all borders.
.asd {
margin-top: 35px;
width: 123px;
border-style: solid;
border-color: #1163b9;
border-width: 70px;
border-radius: 70px;
}
<div class="asd"></div>
Define CSS like this
.asd {
margin-top: 35px;
width: 123px;
border: 70px solid #1163b9;
border-radius: 70px
}
<div class="asd"></div>

How to fix the triangle alignment issue and i don't what wrong in my code [duplicate]

This question already has answers here:
Shape with a slanted side (responsive)
(3 answers)
Closed 4 years ago.
I have to draw half diagonal triangle in card i tried but i don't know how to bring the exact output as shown in this image and i have uploaded my code too, so please if anyone know how to achieve as same like image please let me know for reference i have upload the excepted output image here Output
.cards{
border-bottom: 148px solid red;
border-left: 158px solid transparent;
}
.empty-space-section6 {
height: 411px;
width: 230px;
border-color: gray;
margin-left: 20px;
margin-top: 16.5px;
margin-bottom: 52.5px;
background-color: #FFFBE2;
}
<div class="empty-space-section6">
<div class="cards">
</div>
</div>
You need to increase border width and set alignment to right to achieve this. Check updated snippet below:
.cards {
border-bottom: 180px solid red;
border-left: 280px solid transparent;
float: right;
}
.empty-space-section6 {
height: 411px;
width: 230px;
border-color: gray;
margin-left: 20px;
margin-top: 16.5px;
margin-bottom: 52.5px;
background-color: #FFFBE2;
overflow: hidden;
}
<div class="empty-space-section6">
<div class="cards">
</div>
</div>
You can work with positioning to achieve this.
.cards{
border-bottom: 248px solid red;
border-left: 358px solid transparent;
position: absolute;
bottom: 0;
left: -50px;
}
.empty-space-section6 {
height: 411px;
width: 230px;
border-color: gray;
margin-left: 20px;
margin-top: 16.5px;
margin-bottom: 52.5px;
background-color: #FFFBE2;
position: relative;
overflow: hidden;
}
<div class="empty-space-section6">
<div class="cards">
</div>
</div>
I would consider to use instead a simple linear-gradient as the background so you wouldn't need to mess with borders.
e.g.
article {
width: 240px;
height: 360px;
box-shadow: 0 0 5px #999;
background: linear-gradient(-25deg, #9864bb 160px, #ffffff 162px);
}
<article></article>
In this example the gradient starts from bottom to top but of course you can change how it is anchored and the color-stop values.

More rounded corner - Border Radius CSS

I'm looking to do more rounded corners in CSS to have a result like this :
Currently, I have this code:
border-radius: 0 400px 0 0;
which results in:
The second value doesn't change the corner even if I put 50px or 1000px.
Is there a way to have a similar border radius?
You would need to elongate your border-radius:
.test {
border: 1px solid black;
text-align:center;
/* border-top-left-radius: horizontal vertical */
border-top-left-radius: 50px 20px;
}
<div class="test">
lorem ipsum
</div>
More information
Here another way to do.
.card {
max-width: 100px;
height: 20px;
margin: 10px;
background-color: green;
border-radius: 150px 100px/75px 0px 0px;
}
<div class="card "></div>

How to make the contents of an element with round-cornered border be also round-cornered?

http://jsfiddle.net/XjsWZ/
I'm trying to get the white box itself to have rounded corners in addition to its transparent gray border using CSS3. Is this possible?
html:
<div class="outer"><div class="inner"></div></div>
css:
.outer{
width: 300px;
height: 300px;
border: solid 10px;
border-radius: 5px;
border-color: rgba(0, 0, 0, 0.5);
}
.inner{
border-radius 5px;
}
Bonus question:
What's with those black squares in the corners on Chrome?
EDIT: I found a discussion of the black squares: Weird border opacity behavior in Webkit?
http://jsfiddle.net/XjsWZ/3/ maybe?
** edit **
I prefer JamWaffles':
.outer{
width: 290px;
height: 290px;
border: solid 10px;
border-radius: 15px;
border-color: rgba(0, 0, 0, 0.5);
background-clip:padding-box;
background-color:white;
padding: 5px;
}
Or if you want different looking corners there's a variant of Jedidiah's:
.outer{
width: 300px;
height: 300px;
background-clip:padding-box;
background-color: rgba(0,0,0,0.5);
border: solid 10px rgba(0,0,0,0.5);
border-radius: 10px; /*if you reduce this below 9 you will get black squares in the corners, as of Chrome 14.0.835.163 m*/
}
.inner{
border-radius: 5px;
background-color: white;
height: 100%;
}
JamWaffles answer is cleaner but if you did want to achieve this with the nested div tags and a translucent border you could set a background colour on the outer div to match the border colour, you would also need to set background-clip: padding-box; so that the border and background do not overlap.
Example:
http://jsfiddle.net/XjsWZ/7/
css:
.outer{
width: 300px;
height: 300px;
background-clip:padding-box;
background-color: rgba(0,0,0,0.5);
border: solid 10px rgba(0,0,0,0.5);
border-radius: 5px;
}
.inner{
border-radius: 5px;
background-color: white;
display:block;
width: 100%;
height: 100%;
}
html:
<div class="outer"><div class="inner"></div></div>
This will change the look of the box a bit, but if the border radius is greater than the width of the border, you'll get inner rounded corners too.
Example here. I've removed the inner div as it's not needed for the example, as I have made the assumption you're nesting only to achieve the rounded effect.
In relation to the black squares in the corners, I don't get any at all with Chromium 12. You could try using a normal hex colour instead of an RGBA one. For your current colour, it's #808080, although I do appreciate the need for translucency; this is for a Facebox-style popup?
http://jsfiddle.net/XjsWZ/10/
It seems like this would be a good solution although it technically doesn't use a border, it maintains the correct alpha value while getting rid of the black squares in webkit:
css:
.outer{
width: 300px;
height: 300px;
background-clip:padding-box;
background-color: rgba(0,0,0,0.5);
border: solid 10px rgba(0,0,0,0.5);
border-radius: 5px;
}
.inner{
border-radius: 5px;
background-color: white;
display: block;
width: 280px;
height: 280px;
position: relative;
top: 10px;
left: 10px;
}
html:
<div class="outer"><div class="inner"></div></div>

set css border to end in a 90 instead of a 45 degree angle

I have a div with different colors for both the border-bottom and border-right properties.
So they are separated via a line leaving the box in a 45 degree angle.
How can I make the bottom-border shorter so that the right border goes all the way to the bottom of the element which would yield a 90 degree angle separator-line?
You can do this with box-shadow.
Demo:
Output:
CSS:
#borders {
border-bottom: 20px solid black;
box-shadow: 20px 0 0 0 red;
height: 150px;
margin: 30px;
width: 150px;
}
HTML:
<div id="borders"></div>
I solved this issue using border-width. You simply reduce the width of the border at the edges you don't want to see.
If we don't want the border on the upper edge, we can put border-width to 0.
border-width: 0px 5px 5px 5px;
border-color:#ddd #000 #000 #000;
Sad fact: Border corners are mitered. Always. (It's only visible if using different colors.)
In order to simulate a butt joint, you can stack two divs to get a simulated result:
div {
position: absolute;
left: 0;
top: 0;
height: 100px;
width: 100px;
}
<div style="border-left: 2px solid #ff0000; border-bottom: 2px solid #ff0000;">
</div>
<div style="border-right: 2px solid #00ff00; border-top: 2px solid #00ff00;">
</div>
Stack more or control the top and bottom differently for better control over the appearance of the joint.
For the top border and the bottom border, you can use box-shadow:
.box {
border: 10px solid #ddd;
border-top: 0;
border-bottom: 0;
box-shadow: 0 10px 0 #D03FBE, 0px -10px 0 #D03FBE;
float: left;
width: 100px;
height: 100px;
}
<div class="box"></div>
What you are seeing is that borders on different sides will split diagonally around the corner:
.border {
border: 10px solid;
border-top-color: forestgreen;
border-right-color: gold;
border-bottom-color: steelblue;
border-left-color: firebrick;
width: 40px;
height: 40px;
}
<div class="border"></div>
This is a behavior many use to create CSS triangles
To overcome this I can find 2 solutions: borders on a wrapper element, or linear gradients:
Option 1: Wrapper elements
.wrapper {
border-bottom: 10px solid steelblue;
height: 40px;
width: 50px;
}
.border {
border-right:10px solid gold;
height: 40px;
width: 40px;
}
<div class="wrapper">
<div class="border"></div>
</div>
Note how the wrapper element has height of 5px more then the child. This is essential for the borders to align.
Option 2: Linear Gradients
.border {
border-bottom: 10px solid;
border-right: 10px solid;
border-image: linear-gradient(to top, steelblue, steelblue 10px, gold 5px, gold) 10;
height: 40px;
width: 40px;
}
<div class="border"></div>
If you're looking for square ends on your borders, you can set two of the borders to 0px and then run a dummy animation like so :
#keyframes widthSet {
to{
border-right-width: 10px; //or top and bottom, your choice
border-left-width: 10px;
}
}
with animation-fill-mode: forwards;
You can't.
For 90˚ angles you could just use colored divs.
You could get a similar effect for arbitrary angles by using skew transitions and absolute positioning, but it will be hard (if not impossible) to get it to look the same in older browsers (IE8 and lower will particular be a problem).