使用 CSS 将 Span 显示为 Textarea

digitalsuite.net

我有这个代码:

.input {
  position: relative;
  z-index: 1;
  display: inline-block;
  margin: 1em;
  max-width: 350px;
  width: calc(100% - 2em);
  vertical-align: middle;
}
.input:focus{
      outline-offset: -2px;
  
}
.input__field {
  position: relative;
  display: block;
  float: right;
  padding: 0.8em;
  width: 60%;
  border: none;
  border-radius: 0;
  background: #f0f0f0;
  color: #aaa;
  font-weight: bold;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-appearance: none;
  /* for box shadows to show on iOS */
}

.input__field:focus {
  outline: none;
}

.input__label {
  display: inline-block;
  float: right;
  padding: 0 1em;
  width: 40%;
  color: #6a7989;
  font-weight: bold;
  font-size: 70.25%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.input__label-content {
  position: relative;
  display: block;
  padding: 1.6em 0;
  width: 100%;
}

.span-texatarea {
    overflow: auto;
    height: 8rem;
    resize: vertical;
    vertical-align: top !important;
    text-transform: none;
    color: inherit;
    font: inherit;
    border: none;
    outline: 0;
    margin: 0;
    -webkit-appearance: textarea;
    appearance:textarea;
    flex-direction: column !important;
    white-space: pre-wrap !important;
    word-wrap: break-word;
    display: inline-block;
    text-align: start;
    -webkit-writing-mode: horizontal-tb;
}




/* Kaede */

.input--kaede {
  display: block;
  overflow: hidden;
  margin: 1em auto 2em;
  background: #EFEEEE;
}

.input__field--kaede {
  position: absolute;
  top: 0;
  right: 100%;
  width: 60%;
  height: 100%;
  background: #fff;
  color: #9DABBA;
  -webkit-transition: -webkit-transform 0.5s;
  transition: transform 0.5s;
  -webkit-transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
  transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}

.input__label--kaede {
  z-index: 10;
  display: block;
  width: 100%;
  height: 100%;
  text-align: left;
  cursor: text;
  -webkit-transform-origin: 0% 50%;
  transform-origin: 0% 50%;
  -webkit-transition: -webkit-transform 0.5s;
  transition: transform 0.5s;
  -webkit-transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
  transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}

.input__label-content--kaede {
  padding: 1.5em 0;
}

.input__field--kaede:focus,
.input--filled .input__field--kaede {
  -webkit-transform: translate3d(100%, 0, 0);
  transform: translate3d(100%, 0, 0);
  -webkit-transition-delay: 0.06s;
  transition-delay: 0.06s;
}

.input__field--kaede:focus + .input__label--kaede,
.input--filled .input__label--kaede {
  -webkit-transform: translate3d(60%, 0, 0);
  transform: translate3d(60%, 0, 0);
  pointer-events: none;
}

@media screen and (max-width: 34em) {
  .input__field--kaede:focus + .input__label--kaede,
  .input--filled .input__label--kaede {
    -webkit-transform: translate3d(65%, 0, 0) scale3d(0.65, 0.65, 1);
    transform: translate3d(65%, 0, 0) scale3d(0.65, 0.65, 1);
    pointer-events: none;
  }
}

*, *:after, *:before { -webkit-box-sizing: border-box; box-sizing: border-box; }
.clearfix:before, .clearfix:after { content: ''; display: table; }
.clearfix:after { clear: both; }
<span class="input input--kaede">
					<input class="input__field input__field--kaede" type="text" id="input-35" />
					<label class="input__label input__label--kaede" for="input-35">
						<span class="input__label-content input__label-content--kaede">Full Name</span>


</label>
</span>

<span class="input input--kaede">
					<input class="input__field input__field--kaede" type="text" id="input-36" />
					<label class="input__label input__label--kaede" for="input-36">
						<span class="input__label-content input__label-content--kaede">E-Mail</span>


</label>
</span>

<span class="input input--kaede">
					<input class="input__field input__field--kaede" type="text" id="input-37" />
					<label class="input__label input__label--kaede" for="input-37">
						<span class="input__label-content input__label-content--kaede">Phone Number</span>


</label>
</span>

<span class="input input--kaede">
					<input class="input__field input__field--kaede" type="text" id="input-38" />
					<label class="input__label input__label--kaede" for="input-38">
          <span class="input__label-content input__label-content--kaede span-texatarea">Message 
          </span>


</label>
</span>

https://jsfiddle.net/css_stroller/6ag9j836/

我基本上希望“消息跨度元素”像 Textarea 一样显示,但焦点上的过渡动画。更具体地说:一旦消息区域成为焦点,动画和样式应该与其他跨度相似,但单词输入应该从顶部开始,自动换行和自动换行,就像普通的文本区域一样。我尝试添加一个新类“span-textarea”并尝试使用

 appearance:textarea; 

但这没有帮助。

标签“消息”也应该在

 vertical-align:middle;

所以它在框内居中,但它不起作用。我不太确定这是否可能。

瓦迪姆·奥夫钦尼科夫

我把它换成inputtextarea,并添加Flexbox的样式span文本为中心。演示:

.input {
  position: relative;
  z-index: 1;
  display: inline-block;
  margin: 1em;
  max-width: 350px;
  width: calc(100% - 2em);
  vertical-align: middle;
}

.input:focus {
  outline-offset: -2px;
}

.input__field {
  position: relative;
  display: block;
  float: right;
  padding: 0.8em;
  width: 60%;
  border: none;
  border-radius: 0;
  background: #f0f0f0;
  color: #aaa;
  font-weight: bold;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-appearance: none;
  /* for box shadows to show on iOS */
}

.input__field:focus {
  outline: none;
}

.input__label {
  display: inline-block;
  float: right;
  padding: 0 1em;
  width: 40%;
  color: #6a7989;
  font-weight: bold;
  font-size: 70.25%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.input__label-content {
  position: relative;
  display: flex;
  align-items: center;
  padding: 1.6em 0;
  width: 100%;
}

.span-texatarea {
  overflow: auto;
  height: 8rem;
  resize: vertical;
  vertical-align: top !important;
  text-transform: none;
  color: inherit;
  font: inherit;
  border: none;
  outline: 0;
  margin: 0;
  white-space: pre-wrap !important;
  word-wrap: break-word;
}

/* Kaede */
.input--kaede {
  display: block;
  overflow: hidden;
  margin: 1em auto 2em;
  background: #EFEEEE;
}

.input__field--kaede {
  position: absolute;
  top: 0;
  right: 100%;
  width: 60%;
  height: 100%;
  background: #fff;
  color: #9DABBA;
  -webkit-transition: -webkit-transform 0.5s;
  transition: transform 0.5s;
  -webkit-transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
  transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}

.input__label--kaede {
  z-index: 10;
  display: block;
  width: 100%;
  height: 100%;
  text-align: left;
  cursor: text;
  -webkit-transform-origin: 0% 50%;
  transform-origin: 0% 50%;
  -webkit-transition: -webkit-transform 0.5s;
  transition: transform 0.5s;
  -webkit-transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
  transition-timing-function: cubic-bezier(0.2, 1, 0.3, 1);
}

.input__label-content--kaede {
  padding: 1.5em 0;
}

.input__field--kaede:focus,
.input--filled .input__field--kaede {
  -webkit-transform: translate3d(100%, 0, 0);
  transform: translate3d(100%, 0, 0);
  -webkit-transition-delay: 0.06s;
  transition-delay: 0.06s;
}

.input__field--kaede:focus + .input__label--kaede,
.input--filled .input__label--kaede {
  -webkit-transform: translate3d(60%, 0, 0);
  transform: translate3d(60%, 0, 0);
  pointer-events: none;
}

@media screen and (max-width: 34em) {
  .input__field--kaede:focus + .input__label--kaede,
  .input--filled .input__label--kaede {
    -webkit-transform: translate3d(65%, 0, 0) scale3d(0.65, 0.65, 1);
    transform: translate3d(65%, 0, 0) scale3d(0.65, 0.65, 1);
    pointer-events: none;
  }
}

*,
*:after,
*:before {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.clearfix:before,
.clearfix:after {
  content: '';
  display: table;
}

.clearfix:after {
  clear: both;
}
<span class="input input--kaede">
  <input class="input__field input__field--kaede" type="text" id="input-35" />
  <label class="input__label input__label--kaede" for="input-35">
    <span class="input__label-content input__label-content--kaede">Full Name</span>
  </label>
</span>

<span class="input input--kaede">
  <input class="input__field input__field--kaede" type="text" id="input-36" />
  <label class="input__label input__label--kaede" for="input-36">
    <span class="input__label-content input__label-content--kaede">E-Mail</span>
  </label>
</span>

<span class="input input--kaede">
  <input class="input__field input__field--kaede" type="text" id="input-37" />
  <label class="input__label input__label--kaede" for="input-37">
    <span class="input__label-content input__label-content--kaede">Phone Number</span>
  </label>
</span>

<span class="input input--kaede">
<textarea class="input__field input__field--kaede" type="text" id="input-38"></textarea>
  <label class="input__label input__label--kaede" for="input-38">
    <span class="input__label-content input__label-content--kaede span-texatarea">Message
    </span>
  </label>
</span>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章