markdown 使用CSS3和Flexbox设置样式的“选择”选项

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 使用CSS3和Flexbox设置样式的“选择”选项相关的知识,希望对你有一定的参考价值。

<div class="select" tabindex="1">
  <input class="selectopt" name="test" type="radio" id="opt1" checked>
  <label for="opt1" class="option">Oranges</label>
  <input class="selectopt" name="test" type="radio" id="opt2">
  <label for="opt2" class="option">Apples</label>
  <input class="selectopt" name="test" type="radio" id="opt3">
  <label for="opt3" class="option">Grapefruit</label>
  <input class="selectopt" name="test" type="radio" id="opt4">
  <label for="opt4" class="option">Bananas</label>
  <input class="selectopt" name="test" type="radio" id="opt5">
  <label for="opt5" class="option">Watermelon</label>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
body {
  background:#2d2d2d;
  display:flex;
  justify-content: center;
  align-items:center;
  flex-wrap:wrap;
  padding:0;
  margin:0;
  height:100vh;
  width:100vw;
  font-family: sans-serif;
  color:#FFF;
}

.select {
  display:flex;
  flex-direction: column;
  position:relative;
  width:250px;
  height:40px;
}

.option {
  padding:0 30px 0 10px;
  min-height:40px;
  display:flex;
  align-items:center;
  background:#333;
  border-top:#222 solid 1px;
  position:absolute;
  top:0;
  width: 100%;
  pointer-events:none;
  order:2;
  z-index:1;
  transition:background .4s ease-in-out;
  box-sizing:border-box;
  overflow:hidden;
  white-space:nowrap;
  
}

.option:hover {
  background:#666;
}

.select:focus .option {
  position:relative;
  pointer-events:all;
}

input {
  opacity:0;
  position:absolute;
  left:-99999px;
}

input:checked + label {
  order: 1;
  z-index:2;
  background:#666;
  border-top:none;
  position:relative;
}

input:checked + label:after {
  content:'';
  width: 0; 
	height: 0; 
	border-left: 5px solid transparent;
	border-right: 5px solid transparent;
	border-top: 5px solid white;
  position:absolute;
  right:10px;
  top:calc(50% - 2.5px);
  pointer-events:none;
  z-index:3;
}

input:checked + label:before {
  position:absolute;
  right:0;
  height: 40px;
  width: 40px;
  content: '';
  background:#666;
}
Styled "select" options using CSS3 and Flexbox
----------------------------------------------
A standard &lt;select&gt; element doesn't allow a designer to style the options that end up dropping down aside from background color and text color. I wanted to change that, so I came up with this. It uses radio buttons as the selection, and flexbox to order the selected option.

A [Pen](https://codepen.io/cssinate/pen/KVdYjz) by [Paul Grant](https://codepen.io/cssinate) on [CodePen](https://codepen.io).

[License](https://codepen.io/cssinate/pen/KVdYjz/license).

以上是关于markdown 使用CSS3和Flexbox设置样式的“选择”选项的主要内容,如果未能解决你的问题,请参考以下文章

css3弹性盒模型(Flexbox)

CSS3:flexbox布局语法教程

CSS3 Flexbox:显示:box vs. flexbox vs. flex

CSS3 Flexbox:显示:box vs. flexbox vs. flex

CSS3 Flexbox:显示:box vs. flexbox vs. flex

CSS3弹性盒模型flexbox布局基础版