选择后的框阴影

时间:2017-04-20 12:32:54

标签: css

如何使用box-shadow

为alement添加新的::after效果

在最后一个元素上我都想要外部暗框和白色内框

https://jsfiddle.net/6r4vpt0j/

<ul>
  <li class="dropdown_calendar_li">test</li>
  <li class="dropdown_calendar_li now">test</li>
  <li class="dropdown_calendar_li selected">test</li>
  <li class="dropdown_calendar_li now selected">test</li>
</ul>

ul {
  list-style:none outside none;
    margin:0;
    padding:0;
}

.dropdown_calendar_li {
    display:inline-block;
    text-align:center;
    padding:10px;
  background:#aaa
}

.dropdown_calendar_li.now,
.dropdown_calendar_li.now.selected {
    box-shadow:0 0 0 2px #1f1f1f;
}

.dropdown_calendar_li.now.selected::after {
  box-shadow:inset 0 0 0 2px #fff;
}

3 个答案:

答案 0 :(得分:1)

查看更改:

  1. .dropdown_calendar_li需要position:relative;
  2. 这样

    1. dropdown_calendar_li.now.selected::after可以处理position: absolute;
      1. 在这种情况下,
      2. :after元素需要content: ''和一些displaysize属性。
      3. &#13;
        &#13;
        ul {
          list-style:none outside none;
        	margin:0;
        	padding:0;
        }
        
        .dropdown_calendar_li {
          position: relative;
        	display:inline-block;
        	text-align:center;
        	padding:10px;
          background:#aaa
        }
        
        .dropdown_calendar_li.now,
        .dropdown_calendar_li.now.selected {
        	box-shadow:0 0 0 2px #1f1f1f;
        }
        
        .dropdown_calendar_li.now.selected::after {
          position: absolute;
          top: 0;
          left: 0;
          content: '';
          width: 100%;
          height: 40px;
          display: block;
          box-shadow:inset 0 0 0 2px red;
        }
        &#13;
        <ul>
          <li class="dropdown_calendar_li">test</li>
          <li class="dropdown_calendar_li now">test</li>
          <li class="dropdown_calendar_li selected">test</li>
          <li class="dropdown_calendar_li now selected">test</li>
        </ul>
        &#13;
        &#13;
        &#13;

答案 1 :(得分:1)

伪元素至少需要content: ""。它们也需要像任何其他元素一样的尺寸,否则它们将无法显示。

在您的情况下,您可以在最后一个元素上使用两个框阴影并完全删除伪元素。

&#13;
&#13;
ul {
  list-style:none outside none;
	margin:0;
	padding:0;
}

.dropdown_calendar_li {
	display:inline-block;
	text-align:center;
	padding:10px;
  background:#aaa
}

.dropdown_calendar_li.now {
	box-shadow:0 0 0 2px #1f1f1f;
}

.dropdown_calendar_li.now.selected {
    box-shadow:0 0 0 2px #1f1f1f, inset 0 0 0 2px #fff;
}
&#13;
<ul>
  <li class="dropdown_calendar_li">test</li>
  <li class="dropdown_calendar_li now">test</li>
  <li class="dropdown_calendar_li selected">test</li>
  <li class="dropdown_calendar_li now selected">test</li>
</ul>
&#13;
&#13;
&#13;

答案 2 :(得分:-1)

For ::在您需要添加内容之后:&#34;&#34;在css。试试这个

.dropdown_calendar_li.now.selected::after {
  content: "";
  box-shadow:inset 0 0 0 2px #fff;
 }