Add padding arround input - css

I'm working on this code. I would like to add some space around this input field:
<span class="theSpan">
<h:inputText id="search" class="input_style" value="#{accounts.searchString}"></h:inputText>
<h:commandButton value="Search by title" action="#{bookBean.searchByTitle(accounts.searchString)}">
<f:ajax execute="search" render="output"></f:ajax>
</h:commandButton>
</span>
CSS:
.input_style {
width: 260px;
padding: 5px;
padding-right: 40px;
outline: none;
border: 2px solid #999999;
border-radius: 5px;
background-color: #FBFBFB;
/* font-family: Cambria, Cochin, Georgia, serif;*/
/* font-size: 16px;*/
/*background-position: 270px -10px;*/
/* background-image: url('http://www.kirupa.com/images/search.png');*/
background-repeat: no-repeat;
margin-bottom: 30px;
}
.theSpan {
vertical-align: baseline;
}
Visual result:
How can I add some space between the input filed and the table? Also how can I place the text "Search by title" at line line with input field?

Add margin after the input-style
.input_style{
margin-bottom:10px;
}
padding creates space inside the element and margin creates outside the element so you need to use margin.
Coming to "Search by title" use line-height css in this and line-height should be equal to height of input

To put space between two elements use margin (which adds space outside of the borders of your element), not padding (which adds space inside the border of your element).
To vertically align the text next to the input, place it inside of a span element and apply the following CSS to that span.
Since a text field and a span are both inline elements, they should semantically both be placed into a container (block level) element. That is the element that should get the margin applied to it.
.input_style {
width: 260px;
padding: 5px;
padding-right: 40px;
outline: none;
border: 2px solid #999999;
border-radius: 5px;
background-color: #FBFBFB;
background-repeat: no-repeat;
}
.theButton {
vertical-align: baseline;
}
div { margin-bottom: 30px;
border:1px solid red; /* only here to show the layout */
}
<div>
<input type="text" id="search" class="input_style" >
<button class="theButton">Search By Title</button>
</div>
<div>
This is the next item in the flow of the document.
</div>
Another way to solve this issue is to simply make the button the same
height as the input field, then alignment isn't necessary since both elements are the same height:
/* Note that this rule now applies to the input field and the button */
.input_style, .theButton {
width: 260px;
padding: 5px;
padding-right: 40px;
outline: none;
border: 2px solid #999999;
border-radius: 5px;
background-color: #FBFBFB;
background-repeat: no-repeat;
}
/* Now we just reset aspects of the button that are different
from the input field */
.theButton {
width:auto;
border:0;
}
div { margin-bottom: 30px;
border:1px solid red; /* only here to show the layout */
}
<div>
<input type="text" id="search" class="input_style" >
<button class="theButton">Search By Title</button>
</div>
<div>
This is the next item in the flow of the document.
</div>

I would wrap your entire block in a div tag. That way you can easily control both the spage around the form and the line height alignment.
Add CSS
.my-form-wraper {
/*set margins, padding, line-height, etc. here ^/
}
And HTML:
<div class='my-form-wraper'>
<h:inputText id="search" class="input_style" value="#{accounts.searchString}"></h:inputText>
<h:commandButton value="Search by title" action="#{bookBean.searchByTitle(accounts.searchString)}">
<f:ajax execute="search" render="output"></f:ajax>
</h:commandButton>
</div>

Related

Input border cutout for label cross section [duplicate]

This question already has answers here:
Placing <label> text inside the border of a text input
(7 answers)
Text in Border CSS HTML
(10 answers)
Closed last year.
I would like to put inputs label on border cross section and would like to hide borders under label like this
I did this by simply making label background white but it obviously doesn't work if I place it inside grey div any other solution for this?
Also I'm using quasar inputs so I'm limited to css only solutions
Use fieldset
textarea {
width: 100%;
border: none;
}
<form>
<fieldset>
<legend>Your heading</legend>
<textarea></textarea>
</fieldset>
</form>
You can use position absolute for the label and the use top and left for position your label. Why using position? Then you have more flexibilty. Maybe you can push the label to the right and so on.
* {
font-family: arial;
}
/** float container */
.float-container {
border: solid 1px #ccc;
box-sizing: border-box;
margin-bottom: 8px;
padding: 0 8px;
position: relative;
width: 300px;
}
input {
border: none;
font-size: 16px;
outline: 0;
padding: 16px 0 10px;
width: 100%;
}
label {
font-size: 12px;
position: absolute;
top: -6px;
left: 10px;
background: white;
}
<div id="floatContainer1" class="float-container ">
<label for="floatField1 ">Label 1</label>
<input type="text" id="floatField1" data-placeholder="Placeholder 1">
</div>

changing the Style of Radio buttons in jQuery mobile 1.4.0

I have the Following Radio buttons in my jQuery mobile app , I need to style them as the Radio button in the image bellow . I have tried the following css but it didn't give me the same result , Please Help me ..
Html
<div data-role="page">
<div data-role="header" data-theme="b" style="height:63px;">
</div>
<div data-role="content">
<form>
<fieldset>
<input type="radio" id="Male" value=" Male" name="radio-group-1" />
<label for="Male" data-inline="true" style="background:transparent !important;">Male </label>
<input type="radio" id="Female" value=" Female" name="radio-group-1" />
<label for="Female" data-inline="true" style="background:transparent !important;" >Female </label>
</fieldset>
</form>
</div>
</div>
CSS
input[type="radio"] {
display: none;
}
.ui-btn.ui-radio-off:after, .ui-btn.ui-radio-on:after{
width: 25px;
height: 25px;
}
.ui-btn.ui-radio-off:after, .ui-btn.ui-radio-on:after{
margin-top: -18px;
margin-left: -38px;
}
.ui-btn.ui-radio-on:after{
width: 55px;
height: 55px;
background: green !important;
background-size:100px 24px;
}
This is what i get
To get a green inner circle with transparent around it and a border after that, you really need 2 circles. This could be achieved by adding a :before element as well as the :after element in CSS.
Here is a DEMO
The CSS makes the whole button 56px tall and vertically centers the text by making the line-height the same. When off, the radio image is 26x26 with a gray border. When on, the :before css adds a new 26x26 empty circle with a border while the :after css creates a smaller green circle in the center. NOTE: you may need to tweak sizes and margins to get your desired results.
input[type="radio"] {
display: none;
}
.ui-radio label {
height:56px;
line-height: 56px;
padding-left: 50px;
}
.ui-radio .ui-btn.ui-radio-off:after {
background-image: none;
width: 26px;
height: 26px;
border: 2px solid #6E7983;
margin-top: -13px;
}
.ui-radio .ui-btn.ui-radio-on:after {
background-color: #86D51C;
width: 14px;
height: 14px;
margin-top: -6px;
margin-left: 10px;
border: 0;
}
.ui-radio .ui-btn.ui-radio-on:before {
content:"";
position: absolute;
display: block;
border: 2px solid #6E7983;
border-radius: 50%;
background-color: transparent;
width: 26px;
height: 26px;
margin-top: 14px;
margin-left: -39px;
}

CSS layout - what is causing additional space

I have created the following jsFiddle to demonstrate my problem (or lack of understanding more like)
http://jsfiddle.net/gRCS6/
And Code here
<div id="scoreboard"></div>
<canvas id="game">
Your browser does not support canvas.
</canvas>
<div id="controls">
<button type="submit" id="newGame">New</button>
<button type="submit" id="pause">Pause</button>
<button type="submit" id="help">Help</button>
</div>
#game {
border: 1px solid #000000;
background-color:#333333;
width: 250px;
margin:0px;
}
#scoreboard {
border: 1px solid #000000;
background-color:#333333;
color: orange;
width: 250px;
height: 40px;
font:36px arial,sans-serif;
text-align: right;;
}
#controls {
margin-top: -5px;
padding:0px;
}
button {
border: 1px solid #000000;
margin-left:0px;
background-color:#333333;
color: orange;
width:82px;
height: 40px;
}
Why does the div with id "controls" need a margin-top of -5px to make it touch the canvas above it?
What is taking up that 5 pixels?
What is stopping the 3 buttons from being next to each other with no space between them?
"Why does the div with id "controls" need a margin-top of -5px to make it touch the canvas above it?"
Like ralph.m pointed out, can be fixed by adding
canvas {
display: block;
}
"What is stopping the 3 buttons from being next to each other with no space between them?"
Well, since there are spaces (the character ' ') between the button elements in the html code you will see those spaces between the buttons when the page is displayed. You can either remove the spaces:
<button type="submit" id="newGame">New</button><button type="submit" id="pause">Pause</button><button type="submit" id="help">Help</button>
Instead of
<button type="submit" id="newGame">New</button>
<button type="submit" id="pause">Pause</button>
<button type="submit" id="help">Help</button>
Or you can try to fix it with css styling, for example by adding float: left; to the button selector.
The canvas element is display: inline (or is it inline-block?) by default, which means by default there is a gap at the bottom so that it will align with the baseline of any text beside it.
You can change this by setting the canvas to display: block or vertical-align: bottom.
It's a similar problem with the buttons, which are display: inline-block, meaning that there is space between them (as there is a natural space between words). As mentioned in the chosen answer, removing the white space is an option, but a more elegant solution is as follows:
#controls {word-spacing: -2em; display: table; width: 100%;}
button {word-spacing:0;}
Answer to Q1: Check this topic. Different browsers have different algorythm, so you should some extra parameters for body css.
body
{
margin: 0;
padding: 0;
}
Answer to Q2: Avoid using to close button tab. is not necessary, if you remove it, the margin between buttons will disappear. http://jsfiddle.net/gRCS6/5/
<button type="submit" class="button">New
<button type="submit" class="button">Pause
<button type="submit" class="button">Help
Another way to fix the issue is to use absolute positioning to define the exact placement of your controls div. Then you have to ability to define the exact alignment of the buttons regardless of display: inline-block; or display: block; commands.
http://jsfiddle.net/gRCS6/34/
#game {
border: 1px solid #000000;
background-color:#333333;
width: 250px;
height: 120px;
margin:0px;
position: absolute;
}
#scoreboard {
border: 1px solid #000000;
background-color:#333333;
color: orange;
width: 250px;
height: 40px;
font:36px arial,sans-serif;
text-align: right;
}
#controls {
position: absolute;
top: 172px;
margin-top: 0px;
padding: 0px;
}
button {
border: 1px solid #000000;
margin:0px;
background-color:#333333;
color: orange;
width:81.5px;
height: 40px;
}

Center input type text inside a form inside div inside a wordpress page?

I've created a simple get method form and am having trouble centering the input box. The code works fine out of wordpress, but when I insert into a wordpress page, the input box becomes mis-aligned.
Here's the code I'm inserting on the wordpress page.
<div class="homebox">
<form method="get" action="/home-quote-page.html" form name="quote" rel="nofollow" onsubmit="return ray.ajax()">
<p class="topquotetext">Enter your zip code:</p>
<p><input name="zipcode" class="zipbox" type="text" value="" size="5" maxlength="5"/> </p>
<p><div style="getquote"><input type="image" src="/Photos/startquote.gif" alt="Start Your Quote" name="go" value='Submit'/></div></form></p>
<div id="load" style="display:none;">Finding...Please wait.</div>
</div>
Here's the css. Everything works fine except .zipbox it will allow me to change the color of the box and the height but that's it. No matter what number I input into the width of the box it stays the same width, it also doesn't center inside the div.
.homebox {
text-align: center;
width: 300px;
height: 268px;
background: #2872bd url(/Photos/home-insurance-box.jpg) no- repeat; }
.topquotetext {
font-family: sans-serif, Arial, Verdana;
font-size:16px;
color:#ffffff;
padding-top:70px;
text-align: center;
}
.zipbox {
width: 95px;
height: 25px;
text-align: center;
font-size: 24px;
margin-right: 10px;
margin-left: 10px;
margin-top: 5px;
border: #7F9DB9 1px solid;
background-color: #FFFED2;
}
.getquote {
width: 300px;
text-align: center;
}
Are you pasting this into the default WYSIWYG in WP? If so, WP is stripping out some of your markup. Find a plugin that will allow you to paste in markup, or create a new template and hard-code this section.
Of course it would be centered if you use margin-left: 10px; on the .zipbox and text-align: center would not make element centerd, just text which will be centered. There's nothing wrong with WordPress, it's just how you style the element.
Try this, a bit change of your stylesheet.
.zipbox {
width: 95px;
height: 25px;
display: block;
overflow: hidden;
clear: both;
margin-top: 5px;
margin-left: auto;
margin-right: auto;
font-size: 24px;
border: #7F9DB9 1px solid;
background-color: #FFFED2;
}
And also make sure that the parent element style not affecting the .zipbox and you don't need to wrap the <input /> element in <p></p>, wrap it with <div></div> instead.

CSS: I can't put a button in the middle of a DIV element

I'm using CSS buttons from this tutorial:
http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html
I need to put a button in the middle of a DIV so it's centered. But I can't!
Here's the code of the button:
<a class="button" href="#"><span>Bring world peace</span></a>
And here's CSS:
.clear { /* generic container (i.e. div) for floating buttons */
overflow: hidden;
width: 100%;
}
a.button {
background: transparent url('bg_button_a.gif') no-repeat scroll top right;
color: #444;
display: block;
float: left;
font: normal 12px arial, sans-serif;
height: 24px;
margin-right: 6px;
padding-right: 18px; /* sliding doors padding */
text-decoration: none;
}
a.button span {
background: transparent url('bg_button_span.gif') no-repeat;
display: block;
line-height: 14px;
padding: 5px 0 5px 18px;
}
Here's the code I'm trying to use:
<div align="center"><a class="button" href="#"><span>Bring world peace</span></a></div>
the align attribute for the div element is deprecated. You're better off defining a class for that div, like so:
<div class="centerize">
<a class="button" href="#"><span>Bring world peace</span></a>
</div>
And the CSS:
.centerize {
text-align: center;
}
Note however that setting the text-align will only affect the content inside the div. The div itself (should be) a block element, and depending on where it sits in the document structure, may not be centered itself.
Just to make a little more certain, you can do something like this:
.centerize {
display: block;
margin: 0 auto;
text-align: center;
}
Now you can apply centerize to any element, and that element should take up the entire browser's width and center-align its content.
Modify the button class for these properties:
.button{
margin-left:50%;
margin-right:50%;
position: relative;
}
And wrap your link in the div like this:
<div align="center">
<a class="button" href="#"><span>Bring world peace</span></a>
</div>
The a.button is floated to the left. You could try float: none; on that element. margin: 0 auto; is also useful for center-aligning elements.
Does that help?

Resources