5

Is it possible in css (without images) make items with border radius and triangle side?

li items

3
  • Yes, but it's not supported in older versions of IE. Is that an issue? Commented Sep 19, 2012 at 17:16
  • Probably easier to do with two elements per (for lack of a better term) thing. One for the bigger left hand part with the rounded edges and the other for the triangle. Commented Sep 19, 2012 at 17:18
  • it's not necessary IE support :) And it's ok if another element, but how can I create triangle without specified height? Commented Sep 19, 2012 at 17:23

3 Answers 3

4

You can use an SVG image that will render sharply at any size and will adapt to the element's size, it would look like this...

.button {
  background: #000;
  float: left;
  position: relative;
  color: #999;
  font: 15px/130% Arial, sans-serif;
  padding: 10px 20px;
  clear: both;
  margin: 10px;
  border-radius: 5px 0 0 5px;
}

.button:after {
  content: '';
  display: block;
  width: 10px;
  position: absolute;
  right: -10px;
  height: 100%;
  top: 0;
  background: transparent url('triangle.svg') 0 0 no-repeat;
}

http://jsfiddle.net/Ch7aA/

​This jsfiddle will only work in Webkit because I've inlined the svg so you can understand how it works, but if you load it from an external file it should work fine. Here's the rendering for reference:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

2

have a look at this: http://css-tricks.com/snippets/css/css-triangle/ or this: http://jonrohan.me/guide/css/creating-triangles-in-css/

for the dynamic height, there is a question and answer here: CSS triangle with dynamic height

1 Comment

That's greate solutions, but I have one problem: how can I create triangle without specified height? One li item can be in one line, another in two...
1

HTML:

<div><span>fubar</span></div>

CSS:

span{
    display:block;
    width:100px;
    float:left;
    background-color:green;
    text-align:center;
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    padding:5px 0;
}
div:after {
    content: "";
    display:block;
    float:left;
    border-top: 15px solid transparent;
    border-bottom:15px solid transparent;   
    border-left: 10px solid green;
}

jsFiddle Demo


Update:

To be able to handle varying heights you're going to need to either write some JavaScript code to dynamically change the border size or truncate the text using CSS. Though, it depends on your particular requirements.

4 Comments

Doesn't work for variable element height, like the OP indicated he needed. See JSFiddle.
Thanks, but yep, - problems with two lines :)
you can either use JavaScript or you can truncate the text with CSS - jsfiddle.net/hJfgw/7 - though it all depends on your particular requirements.
Heh, thanks for this variant, but truncate isn't acceptable for me :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.