How to make a vertical input field? - html

This is what I want. A vertical input field, the 'x' is the close button:
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:

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! :)

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>

Related

How do i place my label over my text box input?

I have the below code to make a login form but i cant get the checkbox label to be like always against the edge of the text area. I always sits to the right of the text area. I cant get it to be dependant on the div it is in. On inspection it sits outside the div.
Different things i have tried have included giving the label a left value but this messes it up when the screen size changes.
I want something like this
Here is a jsfiddle if this is easier
function showHidePassword() {
var x = document.getElementById("pass");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
body {
background-color: #ffffff;
}
* {
box-sizing: border-box;
}
input[type=text],
select,
textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
}
input[type=password],
select,
textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
}
label {
padding: 12px 12px 12px 0;
display: inline-block;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
float: right;
}
input[type=submit]:hover {
background-color: #45a049;
}
.container1 {
border-radius: 25px;
background-color: #f2f2f2;
padding: 40px;
position: center;
margin: 15% 30%;
}
.signup {
border-radius: 25px;
background-color: #f2f2f2;
padding: 40px;
position: center;
opacity: 0.96;
}
.container1 .new-body {
background: #f2f2f2;
}
.signup .new-body {
background: #f2f2f2;
}
.signup .row {
padding-top: 5px;
}
.col-25 {
float: left;
width: 25%;
margin-top: 6px;
}
.col-75 {
float: left;
width: 65%;
margin-top: 6px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - when the screen is less than 600px wide, make the two columns stack on top of each other instead of next to each other */
#media screen and (max-width: 600px) {
.col-25,
.col-75,
input[type=submit] {
width: 100%;
margin-top: 0;
}
.col-70,
input[type=submit] {
width: 95%;
margin-top: 0;
}
}
.passw {
cursor: pointer;
width: 30px;
height: 20px;
}
.col-75 label {
padding-top: 16px;
position: absolute;
z-index: 100;
}
<form>
<div class="row">
<div class="col-25">
<label for="pass">Password</label>
</div>
<div class="col-75">
<input type="password" id="pass" name="password" minlength="5" pattern="[A-Za-z][A-Za-z0-9]*[0-9][A-Za-z0-9]*" placeholder="Password" title="A valid password is a set of 5 characters, each consisting of an
upper or lower-case letter, or a digit. The password must begin with a letter and contain at least one digit" autocomplete="current-password" required>
<label for="passShowIcon" id="showHide"><input name="passShowIcon" type="checkbox" class="passw" onclick="showHidePassword();">
<span class=" "></span></label>
</div>
</div>
<div class="row">
<input type="submit" value="Submit">
</div>
</form>
If you wanted to make sure the checkbox appears inside the text input. You could wrap both input fields with a relative class, and then apply absolute positioning to the checkbox.
Like so:
https://jsfiddle.net/x0o46g7a/2/
.wrapper {
position: relative;
}
.text {
width: 100%;
height: 100%;
}
.checkbox {
position: absolute;
top: -8px;
right: -8px;
}
Something to note:
I would recommend adding some padding-right to your text input, to make sure it's text does not overlap/underlap the absolute positioned checkbox.
Based on your code, add the following rules in your css.
float: right to .col-75 instead of float left
right: 0 to .col-75 label
those will ensure that checkbox will remain inside the input field.

Place an HTML textbox on an image in a fixed position for both desktop and mobile site

I am trying to add a textbox on top of an image (treasure chest) and I want the textbox to stay intact in a fixed position right about the slate on the treasure chest. (image attached)
It looks perfect in the desktop, but in mobile the text box comes a little lower than the slate as shown in picture. How can i make it stick in the same position on mobile too? (pic attached)
<img src="img/Shadow_plate2x.png" style="position:relative; width:75%;height:75%"><br>
<input type="number" oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
type = "number"
maxlength = "5" id="PlayerAnswer24" align="middle" name="PlayerAnswerx" required="required" style="background-color: transparent;
position:absolute;
top: 31%;
left: 50%;
transform: translate(-50%, -50%);
letter-spacing: 22px;
color:white;
padding-left:30px; border:0px" placeholder="XXXXX" autocomplete="off"/>
This is the code which I have. Please help. TIA. (Pardon me for my rookie mistakes)
I'm not sure exactly what you're going for for mobile view, but this HTML/CSS is a simpler way to set things up, and you should be able to tweak it more easily:
let input = document.getElementById("PlayerAnswer24");
input.oninput = function() {
if (this.value.length > this.maxLength) {
this.value = this.value.slice(0, this.maxLength);
}
}
.container {
position: relative;
width: 75%;
height: 75%;
display: flex;
justify-content: center;
}
#chest {
max-width: 100%
}
#PlayerAnswer24 {
position: absolute;
letter-spacing: 22px;
color: white;
padding-left: 30px;
border: 0px;
top: 37%;
}
<div class="container">
<img id="chest" src="https://i.imgur.com/1McVPJe.png"><br>
<input type="number" type="number" maxlength="5" id="PlayerAnswer24" name="PlayerAnswerx" required="required" placeholder="XXXXX" autocomplete="off" />
<div>
Since img element can't have children we encase it with a div and expand it to fill the parent, Now the div and the img have the same dimensions which means we can align an input within the div and it'll be aligned with the img as well.
Used percentage values to keep it dynamic with the width.
*,
*:before,
*:after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
div {
border: 1px solid;
position: relative;
/* remove unwanted space below the image*/
font-size: 0;
/* to resize bottom right corner */
resize: both;
overflow: auto;
/* starting point*/
width: 400px;
height: 300px;
}
img {
max-height: 100%;
max-width: 100%;
min-height: 100%;
min-width: 100%;
}
input {
position: absolute;
height: 9%;
width: 54%;
top: 36%;
left: 22%;
border-radius: 2px;
border: none;
/* red to show up */
background-color: red;
letter-spacing: 22px;
color: white;
outline: none;
text-align: center;
font-size: 16px;
padding-left: 30px;
}
<div>
<img src="https://i.imgur.com/1McVPJe.png">
<input type="number" placeholder="XXXXX" />
</div>

css for 2 inc/dec buttons by an input that reposition properly when resizing screen

I want to display an input box in html and 2 small buttons to the right, one on top of each other. Something like this
https://jsfiddle.net/danaya/yw94f0Lt/3/
The html code is simple
<div class="list">
<div class="name">product</div>
<div class="input">
<input type="text" size="3" value="1">
<div class="inc">+</div>
<div class="dec">-</div>
</div>
<div class="price">2.99</div>
</div>
And this is the css
.list {
display: flex;
}
.name,
.input,
.price {
padding: 10px 10px;
border: 1px solid red;
}
.name {
width: 50%;
}
.input,
.price {
text-align: right;
width: 25%;
}
.input {
position: relative;
top: -5px;
}
input {
line-height: 25px;
}
.inc,
.dec {
display: block;
position: absolute;
width: 13px;
height: 13px;
background-color: #999;
text-align: center;
color: #fff;
line-height: 12px;
}
.inc {
top: 11px;
left: 40px;
}
.dec {
top: 25px;
left: 40px;
}
As it is right now, when I resize the window, the div.input is resized and so the buttons, being related to the input, lose their position by the input element.
I need to keep the flex display in the .list element, but other than that I can change anything. I also need the buttons to not increase the width of the div.input element, that's why I'm using the position:relative.
Any ideas?
Thanks
Would this work for you?
.list {
display: flex;
align-items: center;
}
.name,
.price {
padding: 0 10px;
}
.input, input {
box-sizing: border-box; /*to set the equal height to bot .input and input*/
height: 31px; /*13 + 13 (buttons) + 5 (paddings for buttons) = 31px */
}
.input {
position: relative;
/*width: 25%; Use this if you want to increate the width of your div.input*/
}
input {
padding-right: 15px; /* 15px set so that input characters do not go underneath the + and - buttons */
width: 100%; /* set 100% so that input will take 100% width of its parent size */
}
.inc,
.dec {
box-sizing: border-box;
display: block;
position: absolute;
width: 13px;
height: 13px;
background-color: #999;
text-align: center;
color: #fff;
line-height: 12px;
}
.inc {
top: 2px;
right: 2px;
}
.dec {
bottom: 2px;
right: 2px;
}
<div class="list">
<div class="name">product</div>
<div class="input">
<input type="text" size="3" value="1">
<span class="inc">+</span>
<span class="dec">-</span>
</div>
<div class="price">2.99</div>
</div>

Vertical align messed up by border

As shown in the fiddle here with the following HTML:
<body>
<div class="main_container">
<div class="question">
<p>Test question here</p>
</div>
<input class="answer" type="text">
<input class="submit" type="submit">
</div>
</body>
And CSS:
#import 'https://fonts.googleapis.com/css?family=Open+Sans';
body {
text-align: center;
width: 100%;
font-family: 'Open Sans',sans-serif;
//background-color: rgba(0,150,250,0.75);
}
.question {
border-style: solid;
border-color: rgba(0,150,250,0.75);
border-width: 2em;
background-color: white;
border-radius: 1.618em;
margin: 5em auto;
width: 75%;
height: 10em;
}
.question>p {
border-radius: 1.618em;
position: relative;
top: 50%;
transform: translateY(-50%);
}
.answer {
font-size: 1.618em;
border: 0;
border-radius: 1.618em;
width: 50%;
margin: auto;
}
I am able to get the test question centered if I remove the border-style:solid property of question. However, I am wondering why with border-style it is not centered. I've tried using box-sizing:border-box to no avail.
Thanks
Your Vertical align is messed up because browser applied top bottom margin in p tag, if you removed it this will solve your problem
.question > p {
margin: 0;
}
or
p {
margin: 0;
}
see my updated fiddle here
There is by default margin on p elements, so when there is no border on parent element what happens is margin collapsing on parent-child and that margin doesn't affect position of p. But when you set border (it can be any border as you can see here DEMO) on parent element you prevent margin-collapsing and now you can see margin on p element.
So one solution is to remove margin from p
#import 'https://fonts.googleapis.com/css?family=Open+Sans';
body {
text-align: center;
width: 100%;
font-family: 'Open Sans', sans-serif;
//background-color: rgba(0,150,250,0.75);
}
.question {
border-style: solid;
border-color: rgba(0, 150, 250, 0.75);
border-width: 2em;
background-color: white;
border-radius: 1.618em;
margin: 5em auto;
width: 75%;
height: 10em;
}
.question>p {
background-color: red;
border-radius: 1.618em;
position: relative;
top: 50%;
transform: translateY(-50%);
}
.answer {
font-size: 1.618em;
border: 0;
border-radius: 1.618em;
width: 50%;
margin: auto;
}
p {
margin: 0;
}
<div class="main_container">
<div class="question">
<p>Test question here</p>
</div>
<input class="answer" type="text">
<input class="submit" type="submit">
</div>
Try having the parent div displayed as a table and the p displayed as a table-cell then use vertical-align.
See the below snippet.
#import 'https://fonts.googleapis.com/css?family=Open+Sans';
body {
text-align: center;
width: 100%;
font-family: 'Open Sans',sans-serif;
//background-color: rgba(0,150,250,0.75);
}
.question {
border: 2em solid rgba(0,150,250,.75);
background-color: white;
border-radius: 1.618em;
margin: 5em auto;
width: 75%;
height: 10em;
display: table;
}
.question p {
border-radius: 1.618em;
position: relative;
display: table-cell;
vertical-align: middle;
}
.answer {
font-size: 1.618em;
border: 0;
border-radius: 1.618em;
width: 50%;
margin: auto;
}
<body>
<div class="main_container">
<div class="question">
<p>Test question here</p>
</div>
<input class="answer" type="text">
<input class="submit" type="submit">
</div>
</body>
Just set margin 0px of p tag. Sample is
.question>p {
background-color:red;
border-radius: 1.618em;
position: relative;
top: 50%;
transform: translateY(-50%);
margin:0px;
}
You can use flexbox here:
1.) Add display: flex; and flex-direction: column; to .question
2.) Add margin: auto 0; to .question > p.
3.) Erase everything else except border-radius from .question > p
Here is a fiddle: https://jsfiddle.net/35jhjqcx/
Update inner paragraph positions to absolute and remove the margins
and update outer div of paragraph position to relative
see working fiddle link
.question {
border-style: solid;
border-color: rgba(0,150,250,0.75);
border-width: 2em;
background-color: white;
border-radius: 1.618em;
margin: 5em auto;
width: 75%;
height: 10em;
position: relative;
}
.question>p {
background-color: red;
border-radius: 1.618em;
top: 50%;
margin: 0;
transform: translateY(-50%);
position: absolute;
width: 100%;
}

Dynamically change width to adjust div inside another div with CSS

I am trying to create a custom div with input text and two buttons inside it as shown below.
But when i resize the screen it becomes like this
Is there a way to avoid the two buttons to come down ? Instead it should remain inside the original div.
Here's the code i tried:
.searchBar {
background: #DDDDDD;
width:100%;
height:50px;
padding: 10px;
position: relative;
}
.search_field {
display: inline-block;
border-radius:4px ;
background: #FFFFFF;
width: 70%;height: 32px;
position: relative;
left: 60px;
overflow: inherit;
}
.search_field input {
width: 89%;
padding: 0;
border-top-left-radius: 4px;
padding-left: 10px;
padding-top: 5px;
padding-bottom: 5px;
border:1px inset red;
}
.search_field input:focus {
outline-color: transparent;
outline-style: none;
}
.search_field button {
border: none;
background: none;
}
<div id="searchBar" class="searchBar">
<div class="search_field">
<input type="text" id="searchInput" placeholder="Search" oninput="showSearchButtons()"/>
<button id="btn1" hidden="true" onclick="alert()"><img src="assets/images/search.png"></button>
<button id="btn2" hidden="true" onclick="alert()"><img src="assets/images/saveBtn.png"></button>
</div>
</div>
Any help is appreciated. Thanks
You can use calc to calculate the width of your input element relative to your buttons:
width: calc(100% - 100px);
Just make sure the width of your buttons is taken of the 100%. In SASS it could look like this:
$buttons: 50px;
width: calc(100% - #{$buttons * 2});
Below is a simplified implementation. I still have the % values as a fallback for older browsers - but that's more a habit than necessity as every major browser supports calc, even IE9 and onward.
input, button {
float: left;
height: 50px;
display: block;
box-sizing: border-box;
margin: 0;
padding: 0;
border: none;
}
input {
width: 70%;
width: calc(100% - 100px);
padding: 10px;
}
button {
/* Note that this width is equal to 100%
/* minus the percentage width of the input
/* divided by the amount of buttons. */
width: 15%;
width: 50px;
line-height: 50px;
}
/* This rule is just to make sure your images don't decide the buttons width */
button img {
max-width: 100%;
display: inline-block;
}
<input type='text' placeholder='search' />
<button><img src="http://placehold.it/50x50" /></button>
<button><img src="http://placehold.it/50x50" /></button>
Please try this instead of your styles:
.searchBar{
background: #DDDDDD;
width:100%;
height:50px;
padding: 10px;
position: relative;
}
.search_field {
border-radius:4px ;
background: #FFFFFF;
position: relative;
padding-right: 100px; /* You can change as button width */
}
.search_field input {
width: 100%;
padding: 0;
padding-left: 10px;
padding-top: 5px;
padding-bottom: 5px;
border: solid 1px #FF0000;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box;
}
.search_field button {
border: none;
background: none;
position: absolute;
top: 0;
}
.search_field button#btn1 {
right: 50px; /* Change as your requirement */
}
.search_field button#btn2 {
right: 0; /* Change as your requirement */
}