CSS. Placeholder and textbox with different font sizes - html

I have an input field with the font size 45px. This field should have a placeholder with a font size 18px and vertical alignment of the placeholder should be the middle. I've tried the following code, but it doesn't work in Chrome and Opera.
Could you help me to find a solution without JavaScript.
<input type="text" placeholder="Start typing your postal code..." />
input {
width: 300px;
border: 2px solid red;
padding: 0px 5px;
line-height: 100px;
font-size: 45px;
}
::-webkit-input-placeholder {
font-size: 18px;
vertical-align: middle !important;
line-height: 100px !important;
color:#000;
text-align:center;
}
::-moz-placeholder {
font-size: 18px;
vertical-align: middle;
line-height: 100px;
color: #000;
text-align: center;
}
:-ms-input-placeholder {
font-size: 18px;
vertical-align: middle;
line-height: 100px;
color: #000;
text-align: center;
}
:-moz-placeholder {
font-size: 18px;
vertical-align: middle;
line-height: 100px;
color: #000;
text-align: center;
}

I think you need to add input before your pseudo element. Try this:
input::-webkit-input-placeholder {
font-size: 18px;
vertical-align: middle;
line-height: 100px;
color: #000;
text-align: center;
}
input::-moz-placeholder {
font-size: 18px;
vertical-align: middle;
line-height: 100px;
color: #000;
text-align: center;
}
input:-ms-input-placeholder {
font-size: 18px;
vertical-align: middle;
line-height: 100px;
color: #000;
text-align: center;
}
input::placeholder {
font-size: 18px;
vertical-align: middle;
line-height: 100px;
color: #000;
text-align: center;
}
EDIT
Styling placeholders seems limited. But a way to do it might be to use transform: translate(0, -50%);
input::placeholder {
font-size: 18px;
line-height: 100px;
text-align: center;
transform: translate(0, -50%);
}

Related

Vertically center text next to a custom checbox? [duplicate]

This question already has answers here:
How do I vertically align text in a div?
(34 answers)
Closed 2 years ago.
I have found a few posts related to this subject, but no answers seem to be working in my scenario, I am assuming due to my custom class for the checkbox.
Essentially I just want the text next to the checkbox to always vertically align with it, but the vertical alignment behavior is different based on whether the checkbox is checked or not.
I have made the font-size, height, and line-height equivalent for the text and checkbox, which seems to not have made a difference. I have also tried content: "\200b"; in the css but that also seems to not make a difference.
Also, I am unable to use "newer" html/css things because this is for an application that uses an older version of html/css before flexbox.
.lvl1Name {
line-height: 22px;
height: 22px;
font-size: 22px;
}
.checkboxBig {
-webkit-appearance: none;
width: 22px;
line-height: 22px;
height: 22px;
font-size: 22px;
background: white;
border-radius: 0px;
border: 2px solid #144b68;
line-height: 10px;
padding-left: 1px;
text-align: center;
}
.checkboxBig:hover {
background: #80AED1;
}
.checkboxBig:checked {
background: #DAE5EB;
}
.checkboxBig:checked:after {
content: "\2713";
font-size: 22px;
padding-left: 1px;
text-align: center;
color: #144b68;
line-height: 22px;
}
.checkboxBig:checked:hover {
background: #80AED1;
}
<div>
<input class="checkboxBig" type="checkbox">
<span class="lvl1Name">Testing</span>
</div>
You could use flexbox. In the snippet, I added a class of checkbox-wrapper to allow for targeting the div, and used align-items to center it.
.checkbox-wrapper {
display:flex;
align-items:center;
}
.lvl1Name {
line-height: 22px;
height: 22px;
font-size: 22px;
}
.checkboxBig {
-webkit-appearance: none;
width: 22px;
line-height: 22px;
height: 22px;
font-size: 22px;
background: white;
border-radius: 0px;
border: 2px solid #144b68;
line-height: 10px;
font-size: 30px;
padding-left: 1px;
text-align: center;
}
.checkboxBig:hover {
background: #80AED1;
}
.checkboxBig:checked {
background: #DAE5EB;
}
.checkboxBig:checked:after {
content: "\2713";
font-size: 30px;
padding-left: 1px;
text-align: center;
color: #144b68;
line-height: 9px;
}
.checkboxBig:checked:hover {
background: #80AED1;
}
<div class="checkbox-wrapper">
<input class="checkboxBig" type="checkbox">
<span class="lvl1Name">Testing</span>
</div>
Additionally, you could position the .lvl1Name if flex isn't an option. For that class, add a position:relative and a negative top value:
.lvl1Name {
position:relative;
top:-7px;
line-height: 22px;
height: 22px;
font-size: 22px;
}
In your case, with the same font-size, line-height and height just add vertical-align: bottom; to the checkbox.
.lvl1Name {
font-size: 22px;
}
.checkboxBig {
vertical-align: bottom;
-webkit-appearance: none;
width: 22px;
line-height: 22px;
height: 22px;
font-size: 22px;
background: white;
border-radius: 0px;
border: 2px solid #144b68;
line-height: 10px;
padding-left: 1px;
text-align: center;
}
.checkboxBig:hover {
background: #80AED1;
}
.checkboxBig:checked {
background: #DAE5EB;
}
.checkboxBig:checked:after {
content: "\2713";
font-size: 22px;
padding-left: 1px;
text-align: center;
color: #144b68;
line-height: 22px;
}
.checkboxBig:checked:hover {
background: #80AED1;
}
<div>
<input class="checkboxBig" type="checkbox">
<span class="lvl1Name">Testing</span>
</div>
Please try using position: absolute and top property on .lvlName class and set position: realtive property on the parent element.
position property sets how an element is positioned in a document.
For more about position property see mdn
.lvl1Name {
line-height: 22px;
height: 22px;
font-size: 22px;
position: absolute;
top: 5px;
}
.main-div {
position: relative;
}
.lvl1Name {
line-height: 22px;
height: 22px;
font-size: 22px;
position: absolute;
top: 5px;
}
.checkboxBig {
-webkit-appearance: none;
width: 22px;
line-height: 22px;
height: 22px;
font-size: 22px;
background: white;
border-radius: 0px;
border: 2px solid #144b68;
line-height: 10px;
padding-left: 1px;
text-align: center;
}
.checkboxBig:hover {
background: #80AED1;
}
.checkboxBig:checked {
background: #DAE5EB;
}
.checkboxBig:checked:after {
content: "\2713";
font-size: 22px;
padding-left: 1px;
text-align: center;
color: #144b68;
line-height: 22px;
}
.checkboxBig:checked:hover {
background: #80AED1;
}
.main-div {
position: relative;
}
<div class="main-div">
<input class="checkboxBig" type="checkbox">
<span class="lvl1Name">Testing</span>
</div>
You can add a class to the div containing both the elements and use flex box css.
.container{
display: flex;
align-items: center;
}
.lvl1Name {
line-height: 22px;
height: 22px;
font-size: 22px;
}
.checkboxBig {
-webkit-appearance: none;
width: 22px;
line-height: 22px;
height: 22px;
font-size: 22px;
background: white;
border-radius: 0px;
border: 2px solid #144b68;
line-height: 10px;
font-size: 30px;
padding-left: 1px;
text-align: center;
}
.checkboxBig:hover {
background: #80AED1;
}
.checkboxBig:checked {
background: #DAE5EB;
}
.checkboxBig:checked:after {
content: "\2713";
font-size: 30px;
padding-left: 1px;
text-align: center;
color: #144b68;
line-height: 9px;
}
.checkboxBig:checked:hover {
background: #80AED1;
}
<div class="container">
<input class="checkboxBig" type="checkbox">
<span class="lvl1Name">Testing</span>
</div>
If flex box is not something that you are looking for, then you can use vertical-align.
.lvl1Name {
line-height: 22px;
height: 22px;
font-size: 22px;
vertical-align: middle;
}
.checkboxBig {
-webkit-appearance: none;
width: 22px;
line-height: 22px;
height: 22px;
font-size: 22px;
background: white;
border-radius: 0px;
border: 2px solid #144b68;
line-height: 10px;
font-size: 30px;
padding-left: 1px;
text-align: center;
vertical-align: middle;
}
.checkboxBig:hover {
background: #80AED1;
}
.checkboxBig:checked {
background: #DAE5EB;
}
.checkboxBig:checked:after {
content: "\2713";
font-size: 30px;
padding-left: 1px;
text-align: center;
color: #144b68;
line-height: 9px;
}
.checkboxBig:checked:hover {
background: #80AED1;
}
<div>
<input class="checkboxBig" type="checkbox">
<span class="lvl1Name">Testing</span>
</div>
Try using the display:flex in the div. Using flexbox usually helps to solve a lot of problems like this.

Span positioning on different browsers

I have next html element:
<span class="ember-power-select-multiple-option">
<span aria-label="remove element" class="ember-power-select-multiple-remove-btn">×</span>
самбука
</span>
With these styles:
.ember-power-select-multiple-option {
padding-left: 2px;
padding-right: 5px;
margin: 2px;
font-size: 13px;
font-family: CenturyGothic;
height: 21px;
-webkit-font-smoothing: antialiased;
border-radius: 10px;
border: none;
color: #fff!important;
line-height: 19px;
background-color: #FFB000;
padding: 0 4px;
display: inline-block;
float: left;
}
.ember-power-select-multiple-remove-btn {
width: 15px;
height: 15px;
display: inline-block;
line-height: 13px;
padding: 0;
text-align: center;
vertical-align: text-bottom;
color: #fff;
opacity: 1!important;
font-size: 15px;
font-family: sans-serif;
}
I'm trying to achieve next: span with text and another span in it with "X" symbol. All it must be vertical aligned to middle. Now I have this at MacOS X Chrome (and it looks OK to me) and at Windows7 Chrome. How can I make they looks the same? And I sure exists a better way to centering span than I used.
UPDATE:
In addition, I cannot change html because it is a part of an addon.
You had repeated properties such as padding which will override the first one in the same class. Plus using bothinline-block and float:left will not do the effect desired on float so just use inline-block.
I've a made a few tweaks to your code:
Snippet
body {
box-sizing: border-box;
}
.ember-power-select-multiple-option {
margin:2px;
font-size: 13px;
font-family: CenturyGothic;
height: 21px;
-webkit-font-smoothing: antialiased;
border-radius: 10px;
border: none;
color: #fff;
line-height: 17px;
background-color: #FFB000;
padding: 0 4px;
display: inline-block;
}
.ember-power-select-multiple-remove-btn {
width: 15px;
height: 15px;
display: inline-block;
line-height: 17px;
padding: 0;
vertical-align: middle;
color: #fff;
font-size: 15px;
font-family: sans-serif;
}
<span class="ember-power-select-multiple-option">
<span aria-label="remove element" class="ember-power-select-multiple-remove-btn">×</span>
самбука
</span>
Your symbol 'x' is vertically aligned, but is docked to top of symbols line. It's such a symbol.
Try to use ×
This simbol with this style work for me
.ember-power-select-multiple-remove-btn {
vertical-align: middle;
}
Threre is a question about which symbol to use
Which font for CSS "x" close button?
I have just replaced the vertical-align: text-bottom; to vertical-align: middle; And I have check this in Windows7 Chrome,IE & FF and looks aligned to me. please check in MAC also.
.ember-power-select-multiple-option {
padding-left: 2px;
padding-right: 5px;
margin: 2px;
font-size: 13px;
font-family: CenturyGothic;
height: 21px;
-webkit-font-smoothing: antialiased;
border-radius: 10px;
border: none;
color: #fff!important;
line-height: 19px;
background-color: #FFB000;
padding: 0 4px;
display: inline-block;
float: left;
}
.ember-power-select-multiple-remove-btn {
width: 15px;
height: 15px;
display: inline-block;
line-height: 13px;
padding: 0;
text-align: center;
vertical-align: middle;
color: #fff;
opacity: 1!important;
font-size: 15px;
font-family: sans-serif;
}
<span class="ember-power-select-multiple-option">
<span aria-label="remove element" class="ember-power-select-multiple-remove-btn">×</span>
самбука
</span>
Hope this helps you.
Here is a solution that make use of display: inline-flex;
How does that look in Mac?
.ember-power-select-multiple-option {
padding: 0px 4px 1px;
margin: 2px;
-webkit-font-smoothing: antialiased;
border-radius: 10px;
border: none;
background-color: #FFB000;
display: inline-flex;
align-items: center;
height: 21px;
}
.ember-power-select-multiple-option .text {
display: inline-block;
font-size: 13px;
font-family: CenturyGothic;
border-radius: 10px;
border: none;
color: #fff!important;
height: 16px;
line-height: 14px;
}
.ember-power-select-multiple-remove-btn {
display: inline-block;
padding: 0;
color: #fff;
opacity: 1!important;
font-size: 14px;
font-family: sans-serif;
margin-right: 4px;
height: 16px;
line-height: 14px;
}
<span class="ember-power-select-multiple-option">
<span aria-label="remove element" class="ember-power-select-multiple-remove-btn">x</span>
<span class="text">самбука</span>
</span>
I solved my problem in unexpected way.
First of all, I have update addon to newest version, and structure was changed.
<li class="ember-power-select-multiple-option">
<span role="button" aria-label="remove element" class="ember-power-select-multiple-remove-btn">×</span>
самбука
</li>
Also I set:
vertical-align: middle;
font-family: verdana;
for ember-power-select-multiple-remove-btn class and it looks great. So I assumed that span in another span was not very good structure =).
Now it looks next on both OS.

Button background not filling completely on Firefox

So I have a button, but here's the issue. On Firefox only does it not completely fill up. As seen here
This is what it should look like
I'm not really sure what to do. Here's the CSS
.button-panel .button {
-webkit-appearance: none;
border: none;
cursor: pointer;
height: 55px;
font-size: 27px;
letter-spacing: 0.05em;
text-align: center;
width: 100%;
font-family: 'Avenir Next';
display: inline-block;
font-weight: 300;
background-color: #6699FF;
outline: 3px solid #6699FF;
line-height: 59px;
}
And a demo http://jsfiddle.net/h7PXe/
Reason why it showing up is that you use line-height bigger than height of element.
Here you can see how box model is woking and were are outlines:
http://i.stack.imgur.com/Q6J6n.png
You can achieve the same look without using basic properties (then it will work in every browser)
.button-panel .button {
display: inline-block;
padding: 7px 0 5px;
border: 3px solid #6699FF;
width: 100%;
font-family: 'Avenir Next';
font-size: 27px;
font-weight: 300;
letter-spacing: 0.05em;
text-align: center;
background-color: #6699FF;
cursor: pointer;
}
http://jsfiddle.net/h7PXe/1/
Do height: 100%. You need to do this or else the browser won't know what to set the height to.
.button-panel .button {
-webkit-appearance: none;
border: none;
cursor: pointer;
height: 55px;
font-size: 27px;
letter-spacing: 0.05em;
text-align: center;
width: 100%;
font-family: 'Avenir Next';
display: inline-block;
font-weight: 300;
background-color: #6699FF;
outline: 3px solid #6699FF;
line-height: 59px;
height: 100%
}
And a demo.

Issue with getting text into the centre of div

I have made some buttons to link people from my site to social media pages and the text in the Google Plus one is too low and I would like it to go higher in the div but I am struggling to do this, my code is here on JS fiddle.
The buttons aren't complete yet, I just want to know how to get the text higher, cheers
.GooglePlus {
color: black;
font-size: 35px;
border-radius: 100px;
padding: 2px;
font-family: Garamond;
font-weight: bold;
height: 40px;
width: 40px;
background-color: #D8D8D8;
text-align: center;
vertical-align: central;
}
a:hover .GooglePlus {
background-color: #FE2E2E;
color: white;
}
Just add line-height:27px; to adjust g+
Code full class:
.GooglePlus {
color: black;
font-size: 35px;
border-radius: 100px;
padding: 2px;
font-family: Garamond;
font-weight: bold;
height: 40px;
width: 40px;
background-color: #D8D8D8;
text-align: center;
vertical-align: middle;
line-height:27px;
}
If i understand you correctly you are just trying to move the text inside of those circle backgrounds higher.
If this is the case you can cheat it with line height as done in this fiddle
http://jsfiddle.net/9dj9u/2/
Which leaves the resulting CSS affected.
.FaceBook {
color: black;
font-size: 35px;
border-radius: 100px;
padding: 2px;
font-family: Calibri;
font-weight: bold;
height: 40px;
width: 40px;
background-color: #D8D8D8;
text-align: center;
line-height:1.1;
}
.GooglePlus {
color: black;
font-size: 35px;
border-radius: 100px;
padding: 2px;
font-family: Garamond;
font-weight: bold;
height: 40px;
width: 40px;
background-color: #D8D8D8;
text-align: center;
vertical-align: middle;
line-height:0.8;
}
Just adjust line-height in percentage values: line-height: 50%, keep increasing or decreasing till you get there, you might also want to adjust padding, and box-sizing... and remove vertical-align
Remember, this isn't quite exact science, because you do not intend the g and the f to stand next to each other like they do in a sentence, watch this: fg, notice how the g normally is indeed lower than the f.
i included the correct vertical-align value and adjusted the height and width
.FaceBook {
color: black;
font-size: 35px;
border-radius: 100px;
padding: 5px;
font-family: Calibri;
font-weight: bold;
height: 40px;
width: 40px;
background-color: #D8D8D8;
text-align: center;
}
a:hover .FaceBook {
background-color: #4c66a4;
color: white;
}
#footer .FaceBook {
display: inline-block;
}
.GooglePlus {
color: black;
font-size: 35px;
border-radius: 100px;*/
border-bottom: 2px solid black;
padding: 2px;
font-family: garamond;
font-weight: bold;
height: 50px;
width: 50px;
background-color: #D8D8D8;
text-align:center ;
vertical-align: text-bottom;
padding: 0px;
}
a:hover .GooglePlus {
background-color: #FE2E2E;
color: white;
}
#footer .GooglePlus {
display: inline-block;
}
#plus {
font-size: 20px;
padding:0px 0px;
}
a {
text-decoration: none;
}

Why isn't this text centering vertically / horizontally?

I'm trying to center this text horizontally and vertically, ideally based on percentages (for responsive-ness). I can't figure out why this isn't working.
Fiddle: http://jsfiddle.net/PTSkR/144/
Code:
<div class="row-fluid card-box">
<div class="span2 card-box-controls-container">
<div class="card-box-controls">
<a >edit</a>
<a >delete</a>
</div>
</div>
</div>
.card-box .card-box-controls-container {
height: 160px;
vertical-align: middle;
display: inline-block;
text-align: center;
color: black;
font-size: 14px !important;
}
.card-box .card-box-controls-container .card-box-controls {
vertical-align: middle;
display: inline-block;
text-align: center;
color: black;
font-size: 14px;
}
.card-box .card-box-controls a {
cursor: pointer !important;
color: gray;
text-decoration: none;
margin: 0;
vertical-align: middle;
font-size: 14px;
}
.card-box {
background-color: #f5f5f5;
color: black;
margin-right: 0px;
margin-bottom: 15px;
margin-top: 15px;
padding: 5px 0 5px 0;
}
You can use display:table, for example:
.card-box .card-box-controls-container {
height: 160px;
vertical-align: middle;
display:table;
text-align: center;
color: black;
font-size: 14px !important;
width: 100%;
}
.card-box .card-box-controls-container .card-box-controls {
vertical-align: middle;
display: table-cell;
text-align: center;
color: black;
font-size: 14px;
}
.card-box .card-box-controls a {
cursor: pointer !important;
color: gray;
text-decoration: none;
margin: 0;
vertical-align: middle;
font-size: 14px;
}
.card-box {
background-color: #f5f5f5;
color: black;
margin-right: 0px;
margin-bottom: 15px;
margin-top: 15px;
padding: 5px 0 5px 0;
}
pls view the demo. and you can use display:inline-block, for example:
.card-box .card-box-controls-container {
height: 160px;
text-align: center;
color: black;
font-size: 14px !important;
}
.card-box .card-box-controls-container:after{
content:"";
display: inline-block;
height: 100%;
vertical-align: middle;
width: 0px;
background: red;
}
.card-box .card-box-controls-container .card-box-controls {
vertical-align: middle;
display: inline-block;
text-align: center;
color: black;
font-size: 14px;
position: relative;
}
.card-box .card-box-controls a {
cursor: pointer !important;
color: gray;
text-decoration: none;
margin: 0;
vertical-align: middle;
font-size: 14px;
}
.card-box {
background-color: #f5f5f5;
color: black;
margin-right: 0px;
margin-bottom: 15px;
margin-top: 15px;
padding: 5px 0 5px 0;
}
pls view the demo.
There are other ways, pls click here and here.
You can use line-height: 160px on .card-box .card-box-controls-container if you want to center only one line.
http://jsfiddle.net/PTSkR/146/
There's no easy way to vertically align content in html or css more info #
http://blog.themeforest.net/tutorials/vertical-centering-with-css/