Using the following css
.prenom { width: 200px; background-image: url('/Images/Prénom.jpg') ;background-repeat: no-repeat;display: block;background-position: left top;}
I get this
I want this
where the background image would be on top and OUTSIDE of the textbox
Do I need to create a different object for my image or can i set a css property to have a padding on top for the textbox
Thanks
I would suggest to attach it to different object in your HTML. The advantage is that you probably get less problems to make a consistent experience across browsers.
Try this,
.prenom { width: 200px;
display: block;
position:relative
}
.prenom:after{
content:url('/Images/Prénom.jpg');
display:block;
position:relative;
top: -30px;
left:0;
}
-30px can be change to adjust the image
You can try
.prenom {
width: 200px;
display: block;
background:url('/Images/Prénom.jpg') 0 -10px no-repeat;
}
The value -10px can be modified to suit your requirement.
You looking for something like this?
HTML
<div>
<form>
<label for="text1">Random Text</label>
<input type="text" name="text1" />
</form>
</div>
CSS
label{
display:block;
}
http://jsfiddle.net/Xero1212/u56qF/5/
Related
I made the input box bigger (like 500 by 500 pixels), but the text would start from the middle, not the top. I tried putting the padding to zero but it doesn't seem to work. This is under the form tag.
Here's my html code:
<form>
<input class="postbox" value="Hello."><br>
</form>
and this is my css code:
.postbox{
padding:0;
height:500;
width:500;}
you stretched the input-line to 500px, not the form.
As Alvaro Menéndez noticed, you might want to use a textarea, not an input.
Use something like
<form>
<textarea class="postbox" placeholder="Hello"></textarea><br>
</form>
<style>
.postbox {
padding:0;
height:500px;
width:500px;
}
</style>
http://pascha.org/test/2.php
Something like this might do it, i have removed the height and padded the input out
.postbox{
padding-bottom:450px;
width:500px;
}
You can do that by using the padding-bottom property
HTML
<input type="text" value="test"/>
CSS
input {
padding: 10px 10px 100px;
width: 300px;
border: 1px solid red;
}
JSFiddle: http://jsfiddle.net/LeoAref/ko9ahz0L/
How do I make a header cover the contents and span the entire page length? When I use this css
#header {
display: inline-block;
background-color: #015367;
}
#login {
color: #b92c2c;
font-size: 1.25em;
margin-left: 18em;
position: relative;
top: 16px;
text-decoration: none;
}
#search-form {
margin-left: 0.5em;
margin-right: 15em;
position: relative;
top: 18px;
}
.lfloat {
float: left;
}
.rfloat {
float: right;
}
with this html
<body>
<div id="header">
<div id="page-nav" class="rfloat">
<a id="login" class="lfloat" href="/login">login</a>
<form id="search-form" class="rfloat" action="search.py" method="get">
<input id="searchbox" type="text" name="q" placeholder="search"/>
</form>
</div>
</div>
</body>
I get this result (in firefox)
What do I need to change to get a proper header (like stackoverflow, facebook, etc)?
Since you used float for the elements inside #header, then you only need to add this.
#header {
background-color: #015367;
overflow:hidden;
}
Before overflow:hidden
Notice the black border, the #header isn't wrapping the contents.
After overflow:hidden
Check it out : http://jsfiddle.net/AliBassam/vpRc2/
Adjust the top so that elements are positioned the way you like, position:relative; has no use here, just use floats and margins.
Add this to your CSS to zero out the margin on the body:
body {
margin: 0;
}
See DEMO.
I would also suggest you remove your position and top properties from #login and #search-form, and use margin to position them instead.
inline-block ??
#header {
float:left;
width:100%;
clear:both;
}
I suspect you are trying to just extend the header box to contain the login form.
The effect you are experiencing is due to the use of floating elements in the header tag. Floated elements are taken out of the normal flow of the document, this is why the parent element cannot detect their actual occupation of space.
There is an easy fix to this just add a overflow:hidden; to the style of header div. This would fix the problem but it is not considered to be the right way to do it. The overflow is not meant to be used in such a manner. Instead my advice to you is to use the "clearfix" method.
Here is link for the actual code: http://www.webtoolkit.info/css-clearfix.html
All you have to do is to add this code as a class to the header element.
I hope this helps :)
I have an object like this:
<div class="myObject">My Object</div>
I want to display a image in front of that <div>'s box, I thought code like this will work:
.myObject {
background-image: url(foo.png);
background-position: 0px -20px;
}
But, unfortunately, this does not work.
How can I accomplish this goal using CSS?
PS: What I want is just to display that image outside that tag's box, don't tell me to do like this:
.myObject {
padding-left: 10px;
background-image: url(foo.png);
background-position: 0px 0px;
}
Thank you.
You can't position a background image on an element outside the box.
To place an image to the left of an element, using pure CSS, the :before pseudo-element can be used:
Demo: http://jsfiddle.net/2HEpn/
.myObject:before {
content: " ";
background-image: url("/favicon.ico"); /* a 16x16 image, for example */
width: 16px;
height: 16px;
display: inline-block; /* pseudo-elements are inline by default */
}
you might need to place it relativly inside the object as i understand from u to the div
#img{
position:absolute;
top:0px;
left:-30px;
}
.myobject{
position:relative;
width:30px;
}
I have another small problem with centering elements. I thought about the previous questions that I've asked, but I can't seem to find the answer on this problem. I have the following example code to demonstrate my problem.
<div id="main" style="width: 960px;">
<form>
<label>Test</label>
<input type="text" value="Test" id="inputfield" />
</form>
....
</div>
Now I tried to treat it as a block-element using width and margin to position it correctly, but somehow it failed. Do I need to use an id field or is it recommanded that I put a div around every input text field (using #main input[type=text]{...})?
For this case, the best way would be assigning specific rule as per the id #inputfiled
Add this in the CSS Demo
#inputfield { display: block; margin: 0 auto; }
Relying on attribute selectors like input[type="text"] is very risky in terms of cross-browser compatibility.
Updates
In case you want to center all input elements, but not other, you can use a name selector
input,select,textarea { /* These three elements round up all the input types */
display: block;
margin: 0 auto;
}
when centering this way, you need to add width
input{
display:block;
margin:0 auto;
width:100px;
}
Use the following css and make sure you add a width.
<style type="text/css">
#inputfield {
display: block;
margin: 0 auto;
width: 200px;
}
</style>
I have a website design that includes text input fields that look like this:
Input Field http://img401.imageshack.us/img401/4453/picture1ts2.png
I'm wondering what the best solution for creating this input field is.
One idea I have is to always have a div around the input with a background image and all the borders disabled on the input field and specified width in pixels, such as:
<div class="borderedInput"><input type="text" /></div>
I have tried to discourage them from using this format, but they won't be discouraged, so it looks like I'm going to have to do it.
Is this best or is there another way?
--
Trial:
I tried the following:
<style type="text/css">
input.custom {
background-color: #fff;
background:url(/images/input-bkg-w173.gif) no-repeat;
width:173px;
height:28px;
padding:8px 5px 4px 5px;
border:none;
font-size:10px;
}
</style>
<input type="text" class="custom" size="12" />
but in IE (6 & 7) it does the following when you type more than the width:
Over Length http://img240.imageshack.us/img240/1417/picture2kp8.png
I'd do it this way:
<style type="text/css">
div.custom {
background:url(/images/input-bkg-w173.gif) no-repeat;
padding:8px 5px 4px 5px;
}
div.custom input {
background-color: #fff;
border:none;
font-size:10px;
}
</style>
<div class="custom"><input type="text" class="custom" size="12" /></div>
You just have to adjust the padding values so everything fits correctly.
It is - in my eyes- definitely the best solution since in any other case you're working with a whole input field. And the whole input field is - by definition - a box where users can enter text.
If you can rely on JavaScript you could wrap such div-Elements around your input fields programatically.
Edit:
With jQuery you could do it this way:
$( 'input.custom' ).wrap( '<div class="custom"></div>' );
CSS:
div.custom {
background:url(/images/input-bkg-w173.gif) no-repeat;
padding:8px 5px 4px 5px;
}
input.custom {
background-color: #fff;
border:none;
font-size:10px;
}
And your HTML:
<input class="custom" ... />
You don't need the div element, you can assign a background to the input directly.
Edit: Here is the working code. I tested it, but you'll have to adjust it for your needs. As far as I can tell, everything here is needed.
input {
background: #FFF url(test.png) no-repeat bottom right;
width: 120px;
height: 20px;
line-height:20px;
padding:0;
text-indent:3px;
margin:0;
border: none;
overflow:hidden;
}
Edit2: I'm not quite sure why I'm getting downvoted, but this method should work unless you need an image bigger than the input element itself. In that case, you should use the extra div element. However, if the image is the same size as the input, there is no need for the extra markup.
Edit3: Ok, after bobince pointed out a problem, I'm getting a little closer. This will be work in IE6&7 and it's close in FF, but I'm still working on that part.
input {
background: #FFF url(test.png) no-repeat 0px 0px;
background-attachment:fixed;
width: 120px;
height: 20px;
line-height:20px;
padding:0px;
text-indent:3px;
margin:0;
border: none;
}
body>input {
background-position:13px 16px;
}
Edit4: Ok, I think I got it this time, but it requires use of a CSS3 selector, so it won't validate as CSS 2.1.
input {
background: #FFF url(test.png) no-repeat 0px 0px;
background-attachment:fixed;
width: 120px;
height: 20px;
line-height:20px;
padding:0px;
text-indent:3px;
margin:0;
border: none;
}
body>input {
background-position:13px 16px;
}
body>input:enabled {
background-position:9px 10px;
}
body>input will target everything except for IE6, body>input:enabled will target any form elements that aren't disabled for all browsers except for IE 6, 7, & 8. However, because :enabled is a CSS3 selector, it doesn't validate as CSS2.1. I wasn't able to find an appropriate CSS2 selector that would allow me to separate IE7 from the other browsers. If not validating (yet, until the validator switches to CSS3) is a problem for you, then I think your only option is the extra div element.
Have you evaluated using background image like this:
<style type="text/css">
input{
background-color: #AAAAAA;
background-image: url('http://mysite.com/input.gif');
border: 0px;
font-family: verdana;
font-size: 10px;
color: #0000FF;
}
I have done this a few times. I have the background image inside a div and use css to position the input field accordingly.
Have a peek at the following site I created that used this technique and use the code: http://www.ukoffer.com/ (Right hand side Newsletter)
AFAIK, the background scrolling problem can be solved either in Firefox and friends, OR Internet Exploder; but not make everyone happy at once.
I would normally have said to style the input directly, but now that I think of it that div example doesn't sound too bad and should take care of your background image scrolling problem.
In that case you'd set a div as position:relative, and put the input inside it with proper padding and width (or 100% width if padding is 0), background transparent, and put an image on the div.
okoman has gotten the CSS aspect correct. May I suggest using a <label> to improve the semantic structure of the markup?
<label id="for-field-name" for="field-name">
<span class="label-title">Field Name <em class="required">*</em></span>
<input id="field-name" name="field-name" type="text" class="text-input" />
</label>
<style type="text/css">
label, span.label-title { display: block; }
</style>
Not only is this more accessible, but it provides numerous hooks that you can use for any type of DOM manipulation, validation or field-specific styling in the future.
Edit: If you don't want the label title displayed for some reason, you can give it a class of 'accessibility' and set the class to display: none; in the CSS. This will allow screen readers to understand the input but hide it from regular users.
The easiest way to get rid of the overflow without JavaScript is simple:
Create a 3 spans, and set their heights to the height of the
image.
Cut the image into 3 parts, ensuring you cut the image such that
the left and right round parts will be on the 1st and 3rd images
respectively.
Set the background of the 1st span to the image
with the left border, and set it to no-repeat.
Set the background
of the third span to the image with the right border and set it to
no-repeat.
Put the input inside the middle span, remembering to
set its height to the height of the spans, and its background to the
2nd image, and repeat-x only.
That will ensure that the input
will seem to expand horizontally once the input is being filled. No
overlapping, and no JS needed.
HTML
Assuming the image height is 60px, the width of the first and third span is 30px,
<span id="first">nbsp;</span><br />
<span id="second"><input type="text" /></span><br />
<span id="third">nbsp;</span>
CSS
span#first{background:url('firstimage') no-repeat; height:60px; width:30px;}
span#third{background:url('thirdimage') no-repeat; height:60px; width:30px;}
span#second input{background:url('second image') repeat-x; height:60px;}
That should resolve your issue.