most venerable sir
most venerable sir

Reputation: 669

How to make a vertical input field?

This is what I want. A vertical input field, the 'x' is the close button:

enter image description here

This is what I have so far:

*{
  margin:0;
  padding:0;
}
html,body{
  height:100%;
  width:100%;
}
.sidenav{
  height:100%;
  width:20%;
  background:#111;
  overflow-x:hidden;
  box-sizing:border-box;
  padding:calc((20% - 50px)/2);
}
.sidenav a{
  position:relative;
  bottom:18px;
  font-size:90px;
  color:#818181;
}
<div class='sidenav''>
  <a>&times</a>
</div>

I know how to make a regular, bare-boned html input field:

<form>
  <input type=text placeholder='enter name'></input>
  <input type='submit' id='submit'></input>
</form>

EDIT: I want to integrate it to make a stylistically uniform, like this search bar from CodePen:

enter image description here

Upvotes: 2

Views: 5918

Answers (2)

G-Cyrillus
G-Cyrillus

Reputation: 105873

you may take a look at writing-mode.

The writing-mode CSS property defines whether lines of text are laid out horizontally or vertically and the direction in which blocks progress.

About MSIE https://msdn.microsoft.com/library/ms531187(v=vs.85).aspx

.sideway {
  writing-mode: vertical-rl;
  writing-mode: sideways-lr;/* FF*/
  background: gray;
  padding: 0.25em;
  vertical-align:top;
}

form {
  border: solid gray
  }
<form><span class="sideway">
  <input type=text placeholder='enter name' size=8/>
  <input type='submit' id='X'/>
  </span>
</form>

<edit> Chrome does not apply writing-mode on form element (bug?)

Work around possible: demo

.sideway {
  font-size: 3em;
  margin: 0 1em 0 0;
  white-space: nowrap;
  background: #333;
  padding: 0.25em 0;
  float: left;
  width: 2em;
}
.sideway span {
  vertical-align: top;
  display: inline-block;
  transform: translatey(100%) rotate(270deg);
  transform-origin: 0 0;
}
.sideway span:before {
  content: '';
  padding-top: 100%;
  float: left;
}
input {
  font-size: 1em;
  color: gray;
  background: none;
  border: none;
  line-height: 0.8em;
  vertical-align: middle;
  outline: none;
}
[type="submit"] {
  font-size: 2em;
  vertical-align: middle;
  width:1em;
}
form {
  overflow: hidden;
  border: solid #333 0.5em;
}
p {
  overflow: hidden;
  margin: 1em;
}
<form>
  <p class="sideway">
    <span>
       <input type=text placeholder='enter name' size=8/>
       <input type='submit' id='submit' value='&times'/>
    </span>
  </p>
  <p>whatever else comes in your form</p>
</form>

Upvotes: 3

Obsidian Age
Obsidian Age

Reputation: 42304

What you're looking for is transform: rotate().This takes a value in degrees, so you can rotate either to the left or to the right. rotate(90deg) goes from top to bottom, rotate(-90deg) goes from bottom to top.

You'll also probably want to make use of transform-origin to choose where the rotation gets based from, in order for the rotated text to align at the correct position.

Here's a minimal example:

input[type="text"] {
  transform: rotate(-90deg);
  transform-origin: left 0;
  position: absolute;
  bottom: 0;
}
<input type='text' placeholder='enter name'>

And here's a (rough) working example. Maximise the snippet to see it positioned correctly. You may need to adapt the positioning based on your page layout.

input[type="text"] {
  position: absolute;
  bottom: -150%;
  left: 25%;
  transform: rotate(-90deg);
  transform-origin: left 0;
}

form {
  position: relative;
}

* {
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  width: 100%;
}

.sidenav {
  height: 100%;
  width: 20%;
  background: #111;
  overflow-x: hidden;
  box-sizing: border-box;
  padding: calc((20% - 50px)/2);
}

.sidenav a {
  position: relative;
  bottom: 18px;
  font-size: 90px;
  color: #818181;
}
<div class='sidenav'>
  <form>
    <input type='text' placeholder='enter name '>
    <a>&times</a>
  </form>
</div>

Hope this helps! :)

Upvotes: 8

Related Questions