简体   繁体   English

如何在css中使右侧倾斜?

[英]How to make right side in css oblique?

I want to make background for menu list item looks as a tab, how can this be done in CSS and to add icon beside it我想让菜单列表项的背景看起来像一个选项卡,如何在 CSS 中完成并在它旁边添加图标作为这个例子

CSS CSS

#cdnavheader .activeMenuItem span {
background-position: 100% -145px;
color: #2d83ab;
padding: 12px;
background-repeat: no-repeat;
color: #fff;
background-color: #2d489b;
border-top-left-radius: 5px;
border-top-right-radius: 5px;

} }

You can also use a pseudo and transform:您还可以使用伪和转换:

 a { display: inline-block;/* fallback*/ position: relative; overflow: hidden; border-radius:5px 5px 0 0; padding: 1em 3em 1em 2em; } a:before { content: ''; position: absolute; top: 0; right: 0; width: 120%; height: 200%; z-index: -1; background: tomato; border-radius:inherit; transform: skew(35deg) } nav { display: flex; margin: 1em; }
 <nav><a href="#"> some link</a> <a href="#"> some link</a> <a href="#"> some link</a> </nav>

Use a zero height DIV with a big border:使用带有大边框的零高度 DIV:

 .tab { width: 100px; height: 0px; border-right: 20px solid transparent; border-bottom: 20px solid green; }
 <div class="tab"></div>

More info here: https://css-tricks.com/snippets/css/css-triangle/更多信息: https : //css-tricks.com/snippets/css/css-triangle/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM