如何在矩形内插入一个小矩形?

时间:2014-11-11 18:12:37

标签: css html5

I want to make something like this

这是我的链接http://jsfiddle.net/ashadee/xhaLqvav/

Html代码

<a href="#" class="rectangle">Eat your lunch</a><br>

CSS

a{
        font-size: 1.2em;
        white-space: normal;
    }
a.rectangle
{
    width: 70%;
    height: 5%;
    border: 1px solid black;
    padding: 5%;
    margin-top: 0%;
    background-color: #FAFAFA;
    opacity: 0.4;
    display: block;
    text-decoration: none;
    text-align: center;
    font-family: Comic Sans MS;
    box-shadow: 10px 10px 5px #888888;
}

我如何使设计像图像中的那样?我应该使用canvas属性。

1 个答案:

答案 0 :(得分:1)

演示 - http://jsfiddle.net/victor_007/xhaLqvav/2/

使用pseudo元素:after:before来设置右侧框和圆角

&#13;
&#13;
a {
  font-size: 1.2em;
  white-space: normal;
}
a.rectangle {
  width: 70%;
  height: 5%;
  border: 2px solid black;
  padding: 5%;
  margin-top: 0%;
  background-color: #FAFAFA;
  opacity: 0.4;
  display: block;
  text-decoration: none;
  text-align: center;
  font-size: 32px;
  font-family: Comic Sans MS;
  box-shadow: 10px 10px 5px #888888;
  position: relative;
}
a:before {
  content: '';
  border-right: 2px solid black;
  height: 100%;
  position: absolute;
  background: orange;
  width: 50px;
  top: 0;
  bottom: 0;
  left: 0;
}
a:after {
  content: '';
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: black;
  position: absolute;
  left: 35px;
  top: 50%;
  transform: translatey(-50%)
}
&#13;
<a href="#" class="rectangle">Stanford</a>
<br>
&#13;
&#13;
&#13;