I have three text inputs (2 input text, 1 textarea) and a submit button inside a div with position:relative. The 3 text inputs and a submit button all have position:relative as well. The first 2 inputs (q and d) line up as expected, but the last two (t and qS) lie off to the right and don't follow the expected CSS. I would like all of the textboxes and the submit button to line up under each other the same distance from the left side.
Markup:
<form method='POST' action='ask.php'>
<input type='text' id='q' >
<textarea id='d'></textarea>
<input type='text' id='t'>
<input type='submit' value='submit' id='qS'>
</form>
CSS:
#q{
position: relative;
top: 30px;
left: 20px;
width: 400px;
border: 1px solid orange;
font-size: 13px;
}
#d{
position: relative;
top: 60px;
left: 20px;
height: 100px;
width: 400px;
}
#qS{
position: relative;
top: 20px;
left: 20px;
}
#t{
position: relative;
top: 20px;
left: 100px;
}
Your css is quite messy. To get what you want delete all your CSS and replace your HTML with this...
<form method='POST' action='ask.php'>
<p><input type='text' id='q' ></p>
<p><textarea id='d'></textarea></p>
<p><input type='text' id='t'></p>
<p><input type='submit' value='submit' id='qS'></p>
</form>
For further styling and spacing use CSS. There is no need to set anything to position:relative... and there's no need to use top,left,right either. Simply use margin where needed. If you want to move everything together, set margin to your form element.
By default all elements are positioned relative, and hence you don't need to specify it for every element. If you want to add margins, padding add to the divs and it will do the work for you. Here is an example of the code.
http://jsfiddle.net/cdRzW/
Update: The default position is static and not relative, however, the elements are automatically placed in the HTML flow and in this case relative positioning is not required.
Related
I would like to have a html5 number input field containing the EUR sign, and no matter what editing occurs to the field, for the sign to be persistent. I tried to do that but the EURO sign is in beginning , I want to move this sign in the end of the input but for some reasons i can't do it? Any help? Result
My html code:
<span class="input-symbol-euro">
<input type="number" value="0" min="0" step="1" />
</span>
Css code:
.input-symbol-euro {
position: relative;
}
.input-symbol-euro input {
padding-right:18px;
}
.input-symbol-euro:before {
position: absolute;
top: 0;
content:"€";
left: 5px;
}
Here is jsfiddle : DEMO
Why not set right instead of left:
.input-symbol-euro:after {
position: absolute;
top: 0;
content:"€";
right: 18px;
}
See this jsfiddle. Adjust the value as necessary depending on how far you want it from the end, and set it to a negative value if you want it outside the input.
As you're positioning the element absolutely, after and before make no difference, although it would be more semantically correct to use after.
You need to set right instead of left. Which place the content based on the right side of input
.input-symbol-euro {
position: relative;
}
.input-symbol-euro input {
padding-right: 18px;
}
.input-symbol-euro:after {
position: absolute;
top: 0;
content: "€";
right: 5px;
}
<span class="input-symbol-euro">
<input type="number" value="0" min="0" step="1" />
</span>
Use the :after pseudo class, and position the content from the right side of the box:
.input-symbol-euro {
position: relative;
}
.input-symbol-euro input {
padding-right: 18px;
}
.input-symbol-euro:after {
position: absolute;
top: 0;
content: "€";
right: 5px;
}
<span class="input-symbol-euro">
<input type="number" value="0" min="0" step="1" />
</span>
I have a responsive layout. One block has a form input and button. How can I make the elements have a combined width of 100%?
Im using Twitter Bootstrap 3 but I cant see any classes they provide for this.
Ive tried using display table on the the container and display table-cell on the the children but it doenst work, im assuming text input doenst render the styles in the same way a div would.
I could use absolute positioning but then the CSS would break if the button's text was lengthened. So I would rather stay clear of this method.
I dont want to set a fixed % width eg 80% for the input and 20% for the button. I want the button to take up the space it requires, and for the input to take whatever is left.
http://codepen.io/anon/pen/jEPoRG
<div class="form-group">
<input type="text" placeholder="Search">
<button type="submit" class="btn btn-default">Submit</button>
</div>
.form-group {
background: grey;
margin-top: 10px;
margin-left: auto;
margin-right: auto;
width: 30%;
}
If you put a div around the search bar, then you can use display: table/table-cell on .form-submit and its children. I assumed that .search_bar_div's width would have been auto, but that didn't quite stretch all the way. But then I tried 100% and this seems to be working as you want.
I tested Mozilla and Chrome only.
<style type="text/css">
.form-group {
background: grey;
margin-top: 10px;
margin-left: auto;
margin-right: auto;
width: 30%;
display: table;
}
.search_bar_div {
width: 100%;
display: table-cell;
}
.form-group .search_bar_div #search_bar {
width: 100%;
}
.form-group .btn {
display: table-cell;
}
</style>
<div class="form-group">
<div class="search_bar_div">
<input id="search_bar" type="text" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</div>
In an overlapping like the one below, how to prevent the large space between the title and text field?
.icon-link-mail {
position: relative;
left: 485px;
top: 29px;
padding: 8px 8px 7px 8px;
z-index: 2
}
<h3>Title</h3>
<form name="mail_form" id="mail_form" method="POST" action="">
<label for="sendto">
<i class="icon-envelope icon-2x icon-link-mail" style="color:#E4E4E4; text-decoration:none"></i>
<input name="sendto" class="sendto" type="text" style="width: 98%; margin-bottom:10px" placeholder="Send to.." />
</label>
</form>
Result can be seen in this fiddle
Personally I'd just use a pseudo-element, but if you wish to use the <i> icon, then we can do that a lot better by using position:absolute instead of position:relative. Adding position:relative just moves the icon, but leaves the space that it would have taken. position:absolute won't leave that space.
We need to make sure to set the parent contain (label) to position:relative though, so that the icon will be absolutely positioned in relation to the parent instead of the entire page.
#mail_form label {
position: relative;
}
.icon-link-mail {
position: absolute;
z-index: 2;
right: 0;
}
<h3>Title</h3>
<form name="mail_form" id="mail_form" method="POST" action="">
<label for="sendto">
<i class="icon-envelope icon-2x icon-link-mail" style="color:#E4E4E4; text-decoration:none"></i>
<input name="sendto" class="sendto" type="text" style="width: 98%; margin-bottom:10px" placeholder="Send to.." />
</label>
</form>
Result
Fiddle
http://jsfiddle.net/Ay6Hw/4/
I find the best way to do this is to just use an image. Here would be the code:
.search input {
padding-left: 17px;
background: #FFF url("../images/icon_search.png") left no-repeat;
}
.search input:focus {
background:#fff;
}
This will also remove the background image on focus giving the user a better experience overall.
Here is a solution that works with simple CSS and standard font awesome syntax, no need for unicode values, etc.
Create an <input> tag followed by a standard <i> tag with the icon you need.
Use relative positioning together with a higher layer order (z-index) and move the icon over and on top of the input field.
(Optional) You can make the icon active, to perhaps submit the data, via standard JS.
See the three code snippets below for the HTML / CSS / JS.
Or the same in JSFiddle here:
Example: http://jsfiddle.net/ethanpil/ws1g27y3/
$('#filtersubmit').click(function() {
alert('Searching for ' + $('#filter').val());
});
#filtersubmit {
position: relative;
z-index: 1;
left: -25px;
top: 1px;
color: #7B7B7B;
cursor: pointer;
width: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="filter" type="text" placeholder="Search" />
<i id="filtersubmit" class="fa fa-search"></i>
So, I'm trying to make a chatbox, with the following:
<div class="text-container">
<div class="text" id="textholder">
<p>message</p>
...
<p>message</p>
</div>
</div>
<div class="chatbox-container">
<div class="chatbox">
<input type="text" id="textinput" class="inputText" placeholder="Enter text" />
<input type="submit" class="send" onclick="addMessage()" value="Send" autofocus />
</div>
</div>
With the following css:
.text-container{
width: 100%;
height: 500px;
overflow: auto;
position: relative;
}
.text{
position: absolute;
bottom: 0px;
left: 25%;
width: 50%;
height: auto;
}
.chatbox-container{
width: 100%;
height: 30px;
overflow: auto;
}
Where I add some more p's to with the addMessage() function (just adds paragraph with text to innnerHTML of #textholder)
now the problem is that I can't get the text div to overflow(auto), which means the text just disappears.
I want the text to be in the center of the text-container, but I want the scroll to be on the container, so it looks like in skype.
How can I do this? Also, I've tried to basicly align the messages to the bottom of the textbox in a skypelike manner, but I've read that this can also be done by vertical-aligning. yet this didn't work how I wanted it.
Hopefully you get what I'm asking, English is not my native language, and I'm not sure if I'm asking it in the right way.
thanks in advance!
ps. please take into account that this is part of a bigger page, thus I left out some parts.
Ammend your text class to :
.text{
position: absolute;
bottom: 0px;
height: 500px; //fix the height
width :90%;
overflow: auto; //scroll the content
}
Fiddle : http://jsfiddle.net/logintomyk/pETfX/
You have made the container overflow, while the messages are in text, so you need to overflow that class mate!! :)
Probably this is what you are looking for
.text-container {
height:200px;
overflow: auto;
border:1px solid #ccc;
}
.chatbox-container {
height: 30px;
}
jsfiddle
I have a problem with my web form fields not lining up properly.
see screenshot: http://awesomescreenshot.com/00cw0c80e
The label is longer than normal BUT I need it to be that long. If I shorten the label, it lines up find as expected.
Anyone can help?
Thanks! :)
ps. I've looked at various samples in the net but no go.
my css
input.issu {
margin-bottom: 8px;
width: 220px;
}
label.issu {
display: block;
float: left;
margin-bottom: 8px;
padding-left: 10px;
padding-right: 10px;
width: 270px;
text-align: left;
vertical-align: top;
}
select.issu {
margin-bottom: 8px;
width: 240px;
}
br.issu {
float: clear;
}
my html code (I've tried with and without div tags)
<div>
<label for="departingFrom" class="issu">Direct flight into Singapore from (please name city)<span class="red">* required</span></label>
<input id="departingFrom" name="departingFrom" class="issu" value="" type="text">
<br class="issu">
</div>
<div>
<label for="additionalInfo" class="issu">Additional info(e.g. accompanying family members)<span class="red">* required</span></label>
<input id="additionalInfo" name="additionalInfo" class="issu" value="" type="text">
<br class="issu">
</div>
add overflow:hidden property to container div of label and input as follow. It will work fine.
css:
div{
overflow:hidden
}
Use a table, putting the labels in one column, input fields in another. Then set vertical-align on the cells as desires (there are different interpretations on what “lining up” means in a case like this).