I cannot get text in the center of input button. I read articles that suggests adding line-height, but this doesn't help.
I have tried it in three different ways.
HTML:
<button type="submit" class="button validate">Submit</button>
<input type="submit" class="button validate" value="Submit"></input>
<input type=" button " class="button validate " value="Submit"></input>
CSS:
.button {
background: url(http://tax.allfaces.lv/templates/tax/images/btn1.png) no-repeat;
cursor: pointer;
border: none;
display: inline-block;
line-height: 29px;
vertical-align: middle;
text-align: center;
width: 110px;
height: 29px;
color: white;
padding: 0;
font-size: 14px;
margin: 0;
}
JSFIddle: http://jsfiddle.net/M7nv6/
EDIT:
Comments below suggested that text is centered vertically. It doesn't look so, because of image shadow. I cannot change image background, it is creted by designer and have to use it.
Adding padding-bottom helped.
you should use padding-bottom for that. But here is the point you cant use paddings with height or width everything goes fine without height!
.button {
background: url(http://tax.allfaces.lv/templates/tax/images/btn1.png) no-repeat;
cursor: pointer;
border: none;
display: inline-block;
line-height: 29px;
vertical-align: middle;
text-align: center;
width: 110px;
color: white;
padding: 0 0 8px;
font-size: 14px;
margin: 0;
}
You may test this:
.button {
background: url(http://tax.allfaces.lv/templates/tax/images/btn1.png) no-repeat;
cursor: pointer;
border: none;
display: inline-block;
line-height: 0px;
text-align: center;
width: 110px;
height: 29px;
color: white;
padding: 0;
padding-bottom: 7px;
font-size: 14px;
margin: 0;
}
text IS centered vertically however your image have shadow and your button (in image) is really smaller in height than 29px.
change line-height to smaller (25px?) and align text to top
Since you're using background-image with shadow you could add a bottom padding like so: padding: 0 0 5px; (adjust to your needs).
Maybe it'd be better to replace the complete image with css. You can get almost the same result with about the same amount of code, saving some (in this case, 1) http requests.
As you are using a background image you may as well use padding to align it. BUT i would consider not using a background image and instead using pur CSS
DEMO http://jsfiddle.net/M7nv6/
.button {
color: rgba(255, 255, 255, 1);
text-decoration: none;
background-color: rgba(219, 87, 5, 1);
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
-webkit-box-shadow: 0px 9px 25px rgba(0, 0, 0, .7);
-moz-box-shadow: 0px 9px 25px rgba(0, 0, 0, .7);
box-shadow: 0px 9px 25px rgba(0, 0, 0, .7);
display: inline-block;
line-height: 29px;
vertical-align: middle;
text-align: center;
width: 110px;
height: 29px;
color: white;
padding: 0;
font-size: 14px;
margin: 0;
border:none;
}
You could also move the background so it fits your text:
.button {
background: url(http://tax.allfaces.lv/templates/tax/images/btn1.png) no-repeat 0px 4px;;
cursor: pointer;
border: none;
display: inline-block;
line-height: 29px;
vertical-align: middle;
text-align: center;
width: 110px;
height: 29px;
color: white;
padding: 0;
font-size: 14px;
margin: 0;
}
Related
This question already has answers here:
How do I combine a background-image and CSS3 gradient on the same element?
(20 answers)
Closed 5 years ago.
I would like to display image to the left (border same as left border of white section to the left of blue box). Now Image will be visible only when remove background-image: linear-gradient(#a4c2e8,#e2eaf2);
But I want to preserve the gradient effect. How to do that ?
.quate_sidebar {
list-style: outside none none;
margin: -6px;
margin-top: 5px;
padding: 30px;
padding-right: 126px;
padding-bottom: 5px;
}
.quate_sidebar li {
position: relative;
display: inline-block;
padding: 15px 25px;
padding-bottom: 0px;
margin-bottom: 10px;
margin-left: 14px;
background-image: linear-gradient(#a4c2e8, #e2eaf2);
/* text styles */
text-decoration: none;
color: #4174c5;
font-size: 13px;
font-family: initial;
font-weight: 100;
border-radius: 3px;
box-shadow: 0px 1px 4px -2px #333;
display: block;
margin: 5.5px 0;
padding: 10px 10px 10px 50px;
}
.quate_icon_1 {
background: url(img/get_quate/get_quate_icon_1.png)no-repeat scroll 15px center;
}
<ul class="quate_sidebar">
<li class="quate_icon_1">Csab </li>
<li class="quate_icon_1">Maryy</li>
</ul>
Please refer the code here:
https://jsfiddle.net/edp5o27u/
Use the following in .quate_sidebar li:
background-image: url('http:/placehold.it/30'), linear-gradient(#a4c2e8, #e2eaf2); background-repeat: no-repeat, repeat;
See also this fiddle
If you add the icon background image to the <a> element, then you can keep the gradient background image on the <li> element.
.quate_sidebar li {
position: relative;
display: inline-block;
padding: 15px 25px;
padding-bottom: 0px;
margin-bottom: 10px;
margin-left: 14px;
background-image: linear-gradient(#a4c2e8, #e2eaf2);
/* text styles */
text-decoration: none;
color: #4174c5;
font-size: 13px;
font-family: initial;
font-weight: 100;
border-radius: 3px;
box-shadow: 0px 1px 4px -2px #333;
display: block;
margin: 5.5px 0;
padding: 10px 10px 10px 50px;
}
a.quate_icon_1 {
background: url(img/get_quate/get_quate_icon_1.png)no-repeat scroll 15px center;
}
Here is my CSS for the element shown in the attached image.
.ClsInpBestAnz {
border-radius: 0px;
margin: 5px 5px 0px 10px;
width: 45px;
color: #822;
text-align: right;
display: block;
font-size: 1.8em;
}
How can i resize the buttons?
Thank you for your help..
You can find the updated css here
.ClsInpBestAnz {
border-radius: 0px;
margin: 5px 15px 0px 10px;
width: 50px;
color: #822;
text-align: left;
display: block;
font-size: 1.8em;
}
https://jsfiddle.net/ajrek251/
Alternatively, you can take a look at the Jquery UI spinner plugin.
I am trying to change the height and position of an anchor <a> on hover.
The CSS I am using is:
.options {
background: linear-gradient(#FFFFFF, #dbe2e8);
display: table-cell;
vertical-align: middle;
text-align: center;
width: 115px;
height: 35px;
border: 1px solid black;
border-bottom: none;
border-radius: 8px 8px 0px 0px;
-moz-border-radius: 8px 8px 0px 0px;
}
.options:hover {
height: 39px;
top: -4px;
}
I must be doing something wrong. I have tried the :hover part with just the top: -4px; and this works, however the height: 39px; does nothing.
Thanks
Add position: relative also because top, right, bottom and left properties work only when applied with position relative, absolute or fixed.
.options {
background: linear-gradient(#FFFFFF, #dbe2e8);
display: table-cell;
vertical-align: middle;
text-align: center;
width: 115px;
height: 35px;
border: 1px solid black;
border-bottom: none;
border-radius: 8px 8px 0px 0px;
-moz-border-radius: 8px 8px 0px 0px;
position: relative;
}
.options:hover {
height: 39px;
top: -4px;
}
Link
While Muhammad Usman's answer works just fine, I'd like to offer an alternative.
If you replace the top:-4px with translateY(-4px) that will work regardless of the "position" property of the element and/or the "top" property.
(Useful if for example the "top" property is a percentage or set dynamically by JS and you want to move it by 4 pixels no matter what the top is)
.options {
background: linear-gradient(#FFFFFF, #dbe2e8);
display: table-cell;
vertical-align: middle;
text-align: center;
width: 115px;
height: 35px;
border: 1px solid black;
border-bottom: none;
border-radius: 8px 8px 0px 0px;
-moz-border-radius: 8px 8px 0px 0px;
}
.options:hover {
height: 39px;
transform:translateY( -4px);
}
I have the following HTML code:
<div class="dispLoginSearch"> <!-- LOGIN AND SEARCH -->
<div class="loginBox">
<p>Log in to <span>My</span> <span>M</span> | Sign Up</p>
<div style="width: 100%; padding: 0; margin: 0; overflow: hidden; height: 38px;" class="brClear">
<input type="text" placeholder="Username" id="txtUsername" class="txtUsername styledTB floatLeft" />
<input type="password" placeholder="Password" id="pwPassword" class="txtPassword styledTB floatLeft" />
Login
</div>
Forgot login/password
</div>
</div>
CSS:
.dispLoginSearch
{
width: 40%;
height: 180px;
vertical-align: middle;
float: right;
padding-right: 3%;
background: #FFFFFF;
overflow: hidden;
text-align: center;
margin: 0 auto;
}
.loginBox {
margin-top: 3%;
border: 1px solid #d4d4d4;
display: block;
width: 100%;
font: 16px sans-serif;
padding: 0 0 0 15px;
border-radius: 5px;
-webkit-font-smoothing: antialiased;
text-align: left;
overflow: auto;
}
.loginBox p {
margin: 5px 0 0;
font-size: 20px;
line-height: 35px;
}
.txtUsername{
width: 38%;
margin-right: 2%;
height: 30px;
}
.txtPassword {
width: 38%;
margin-right: 2%;
height: 30px;
}
.floatLeft
{
float: left;
}
.logBtn
{
width: 10%;
height: 30px;
line-height: 30px;
}
.styledBtn
{
background: #d75813;
display: block;
box-shadow:
0px 5px #BC490A,
0px 8px 10px rgba(148, 148, 148, 0.5);
text-align: center;
vertical-align: middle;
}
.styledTB {
padding-left: 5px;
background: #E8E8E8;
opacity: 1;
border: none;
outline: none;
right: 35px;
box-shadow:
0px 5px #BBB,
0px 8px 10px rgba(148, 148, 148, 0.5);
}
If I keep the logBtn at 10% it stays in the same line but the letter gets cut off almost:
If I increase the percentage to 12%, instead of expanding on the same line to fill up the DIV, it goes to the next line:
For some reason I am not able to use the 100% of the width from the parent DIV. I used float: right on the forgot login/password link and that's how far it goes. For some reason the right side of the DIV is completely not accessible.
How do I resolve the issue?
The inline style will be removed when I have resolved the issue.
Your problem comes from the horizontal paddings you are adding onto the inputs. Those are added to the percentage width and percentage margin you have put on the inputs.
try using the box-sizing: border-box; property on the inputs so the paddings won't get added to the specified width and margins
Some explaination about box-sizing can be found here
SOLVED:
I have a demo which works on jsFiddle, but the same one doesn't work on other site. You will see the .right_side_header class overflow onto the next line, which is under the main_container-->header--->class. Why is this so? It is 763px, I've double checked the pixels for every box, but it overflows. Can someone please tell me why? If you inspect the element, and uncheck the width of 763px, it doesn't overflow.
Here's the code for some of the header css:
.header {
display: block;
padding-top: 33px;
padding-left: 30px;
padding-right: 30px;
margin-left:auto;
margin-right:auto;
width: 900px;
}
.right_side_header {
display: inline-block;
vertical-align: top;
padding-top: 35px;
width: 763px;
}
img.globe {
display: inline;
}
#globe-logo {
display: inline;
position: relative;
z-index: 9000;
}
span.letter_logo {
font-family: HelveticaBlack;
font-size: 41px;
height: 41px;
line-height: 1;
margin-left: auto;
margin-right: auto;
text-align: center;
text-shadow: 1px 1px 0px rgba(245, 245, 245, 0.35), -1px -1px 0px rgba(245, 245, 245, 0.35);
}
div.letter_logo_container {
text-align: center;
display: block;
line-height: 1;
width: 621px;
}
and here is the code for the nav_bar css:
div.nav_phone {
height: 18px;
padding-top: 3px;
width: 621px;
display: inline-block;
}
span.sales_ph_num {
font-family: HelveticaItalic;
font-size: 11.5px;
color: #c10d24;
text-shadow: 1px 1px 0px rgba(245, 235, 236, 0.4), -1px -1px 0px rgba(245, 235, 236, 0.4);
}
div.sales_ph_num {
text-align: center;
display: inline-block;
vertical-align: top;
width: 110px;
}
.nav_bar {
background-image: url("132/nav_bar.png");
background-repeat: no-repeat;
height: 18px;
width: 621px;
position: relative;
}
div#links {
line-height: 1;
position: absolute;
top: 50%;
left: 119px;
margin: -6px auto 0 auto;
font: 12px HelveticaMedium;
text-align: center;
text-shadow: 1px 1px 0px rgba(237, 237, 237, 0.5), -1px -1px 0px rgba(237, 237, 237, 0.5);
}
#Products {
margin-left: 36px;
}
#Terms, #Terms_Nav {
margin-left: 36px;
}
a.Terms, a.Terms:visited, #Home a, #Home a:visited, a#About, a#About:visited,
#About a, #About a:visited {
text-decoration: none;
color: #000000;
cursor:pointer;
}
li#line_break {
margin-top: 12px;
}
#About {
text-decoration: none;
color: #000000;
margin-left: 36px;
margin-right: 35px;
}
and this is the main_body css:
html, body {
width: 100%;
height: 100%;
background-color: #fafafa;
-webkit-overflow-scrolling: touch;
position: relative;
overflow-x: hidden;
}
.main_container {
max-width: 960px;
margin-left: auto;
margin-right: auto;
background-color: #ffffff;
-webkit-border-radius: 8px 8px 8px 8px;
-moz-border-radius: 8px 8px 8px 8px;
-o-border-radius: 8px 8px 8px 8px;
border-radius: 8px 8px 8px 8px;
position: absolute;
left: -9999em;
}
and theres a css that does a reset:
* {
margin: 0;
padding: 0;
}
Thank you for any help.
Remove the top: -61px; from div.ad_banner.
Also if you are having a loading screen I would recommend having some kind of simple animation just so it doesn't look like the page has died.
You have limited your right_side_header class to 763px, also your sales_ph_num class is limited to 110px.
But on jsfiddle you have set 900px and 137px respectevly.
Just set same values like you did on jsfiddle. =))
SOLUTION:
ok this issue was bugging me for awhile, and i don't understand why this is. i noticed some extra 1 or 2 pixels of whitespace between the sales_ph_num div and the nav_bar div, there shouldn't have been any. then i saw that i was using inline-block, searched on SO for inline-block and unaccounted whitespace, and there you go. i had used inline block with 2 or 3 divs, and it was adding extra whitespace, which was making the content overflow since every box had a width.
if you have two divs side by side, with one div as inline, and the other inline-block, and you place the div tags in html on separate lines, white space is added:
<div class="container_1000px">
<div class="container">
My content.
</div>
<div class="next_container">
Next content.
</div>
</div>
.container_1000px
{
width: 1000px;
}
.container
{
display: inline;
width:960px;
}
.next_container
{
display: inline-block
width: 40px;
}
this will overflow because extra whitespace is added between the inline and inline-blocked div.
the solution is to place each divs on one line.
<div class="container_1000px"><div class="container">My content.</div><div class="next_container">Next content.</div></div>
and no extra whitespace will be added. thanks again.
Can anyone explain to me why this happens and why it should/shouldn't?