sribin
sribin

Reputation: 1736

How to bevel the corner of a block div?

I have the following HTML document:

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8">
        <title>Тег DIV</title>
        <style type="text/css">
            .block1 { 
                width: 200px; 
                background: #ccc;
                padding: 5px;
                padding-right: 20px; 
                border: solid 1px black; 
                float: left;
            }
        </style> 
    </head>
    <body>
        <div class="block1">Text Content</div>
    </body>
</html>

How do I describe the style to get the following? enter image description here

Upvotes: 2

Views: 8598

Answers (4)

Nitesh
Nitesh

Reputation: 15779

Here is the Solution.

The CSS and HTML:

    ul {
      position: relative;
      overflow: hidden;
      font: 14px Arial;
      margin: 0;
      padding: 0;
      list-style: none;
      text-align: center;
    }
    ul:before {
      content: "";
      position: absolute;
      z-index: -1;
      left: 124px;
      margin-left: -120px;
      width: 0;
      border-left: 0 solid transparent;
      border-right: 230px solid transparent;
      border-top: 179px solid #CCCCCC;
    }
    li {
      height: 3.8em;
      line-height: 3em;
      position: relative;
      margin-left: -562px;
    }
    li:after,
    li:before {
      content: "";
      display: block;
      height: 0.4em;
      background: #fff;
      width: 100%;
    }
<ul>
  <li>Text Content</li>
</ul>

You have to use the border-width property to get your desired output.

Hope this helps.

Upvotes: 0

Hashem Qolami
Hashem Qolami

Reputation: 99544

Until CSS4 border-corner-shape property is in danger! and it's not implemented, This can be done by using CSS3 transforms (to keep border property free for further usage):

HTML:

<div class="box">
  Text Content
</div>

CSS:

.box {
  width: 200px; 
  height: 35px;
  line-height: 35px;
  padding: 0 5px;
  background-color: #ccc;
  padding-right: 20px;
  border: solid 1px black;
  border-right: 0;  
  position: relative;
}

.box:after {
  content: "";
  display: block;
  background-color: #ccc;
  border: solid 1px black;
  border-left: 0;
  width: 35px;
  height: 35px;
  position: absolute;
  z-index: -1;
  top: -1px; /* pull it up because of 1px border */
  right: -17.5px; /* 35px / 2 */
  transform: skew(-45deg);
  -o-transform: skew(-45deg);
  -moz-transform: skew(-45deg);
  -webkit-transform: skew(-45deg);
}

Here is JSBin Demo.

NOTE: There's another div in example above has class attribute of box2, which implemented without using CSS3 declarations that you might consider using it ;)

Upvotes: 4

sribin
sribin

Reputation: 1736

If I describe a document like this:

<!DOCTYPE HTML>
<html>
 <head>
  <meta charset="utf-8">
  <title>Тег DIV</title>
  <style type="text/css">
   .block1 { 
    width: 300px;
    height: 0px;
    border-style: solid;
    border-width: 200px 200px 0 0;
    border-color: #f200ff transparent transparent transparent;
   }
  </style> 
 </head>
 <body>
  <div class="block1">Text Content</div>
 </body>
</html>

I get almost what you need, but I do not understand why the text is not in the figure?

Upvotes: 0

naivists
naivists

Reputation: 33551

Most likely it can be done using the inivisble border trick. There are some "triangle generators" on the web, for example, this one

Upvotes: 0

Related Questions