How to bevel the corner of a block div?

匿名 (未验证) 提交于 2019-12-03 00:50:01

问题:

I have the following HTML document:

               Тег DIV
Text Content

How do I describe the style to get the following?

回答1:

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:

Text Content

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 ;)



回答2:

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



回答3:

If I describe a document like this:

      Тег DIV
Text Content

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



回答4:

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%;     }
  • Text Content

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

Hope this helps.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!