Vertical centering of text of select-element
up vote
0
down vote
favorite
I've created a small codepen to test how to align span,div, input and select elements evenly inside a container. After alot of trial and error it's working across Chrome, Firefox and Edge.
https://codepen.io/anon/pen/QJQaVX
But the problem now is the select-box. The text which shows the actual selection is moved to bottom-line of the inner text. This is also visible in the inspector. Surprisingly Edge is showing the expected behaviour and centers the text. But Chrome and Firefox won't.
I've tried setting line-height without success. Even display:flex
is not changing anything.
Is there any proper solution for this problem?
css microsoft-edge
add a comment |
up vote
0
down vote
favorite
I've created a small codepen to test how to align span,div, input and select elements evenly inside a container. After alot of trial and error it's working across Chrome, Firefox and Edge.
https://codepen.io/anon/pen/QJQaVX
But the problem now is the select-box. The text which shows the actual selection is moved to bottom-line of the inner text. This is also visible in the inspector. Surprisingly Edge is showing the expected behaviour and centers the text. But Chrome and Firefox won't.
I've tried setting line-height without success. Even display:flex
is not changing anything.
Is there any proper solution for this problem?
css microsoft-edge
Probably because you have given aheight
to theoption
. I tried to remove it and it does center.
– Gurtej Singh
Nov 22 at 0:26
Correct, it looks like your height option is cause problems. I'd recommend removing the Option out of the CSS rule which gives it a height.
– Robert Perez
Nov 22 at 0:29
Unfortunately not for me. I've removedoption
from the selector and still get the same result.
– Auskennfuchs
Nov 22 at 0:31
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've created a small codepen to test how to align span,div, input and select elements evenly inside a container. After alot of trial and error it's working across Chrome, Firefox and Edge.
https://codepen.io/anon/pen/QJQaVX
But the problem now is the select-box. The text which shows the actual selection is moved to bottom-line of the inner text. This is also visible in the inspector. Surprisingly Edge is showing the expected behaviour and centers the text. But Chrome and Firefox won't.
I've tried setting line-height without success. Even display:flex
is not changing anything.
Is there any proper solution for this problem?
css microsoft-edge
I've created a small codepen to test how to align span,div, input and select elements evenly inside a container. After alot of trial and error it's working across Chrome, Firefox and Edge.
https://codepen.io/anon/pen/QJQaVX
But the problem now is the select-box. The text which shows the actual selection is moved to bottom-line of the inner text. This is also visible in the inspector. Surprisingly Edge is showing the expected behaviour and centers the text. But Chrome and Firefox won't.
I've tried setting line-height without success. Even display:flex
is not changing anything.
Is there any proper solution for this problem?
css microsoft-edge
css microsoft-edge
asked Nov 22 at 0:22
Auskennfuchs
1338
1338
Probably because you have given aheight
to theoption
. I tried to remove it and it does center.
– Gurtej Singh
Nov 22 at 0:26
Correct, it looks like your height option is cause problems. I'd recommend removing the Option out of the CSS rule which gives it a height.
– Robert Perez
Nov 22 at 0:29
Unfortunately not for me. I've removedoption
from the selector and still get the same result.
– Auskennfuchs
Nov 22 at 0:31
add a comment |
Probably because you have given aheight
to theoption
. I tried to remove it and it does center.
– Gurtej Singh
Nov 22 at 0:26
Correct, it looks like your height option is cause problems. I'd recommend removing the Option out of the CSS rule which gives it a height.
– Robert Perez
Nov 22 at 0:29
Unfortunately not for me. I've removedoption
from the selector and still get the same result.
– Auskennfuchs
Nov 22 at 0:31
Probably because you have given a
height
to the option
. I tried to remove it and it does center.– Gurtej Singh
Nov 22 at 0:26
Probably because you have given a
height
to the option
. I tried to remove it and it does center.– Gurtej Singh
Nov 22 at 0:26
Correct, it looks like your height option is cause problems. I'd recommend removing the Option out of the CSS rule which gives it a height.
– Robert Perez
Nov 22 at 0:29
Correct, it looks like your height option is cause problems. I'd recommend removing the Option out of the CSS rule which gives it a height.
– Robert Perez
Nov 22 at 0:29
Unfortunately not for me. I've removed
option
from the selector and still get the same result.– Auskennfuchs
Nov 22 at 0:31
Unfortunately not for me. I've removed
option
from the selector and still get the same result.– Auskennfuchs
Nov 22 at 0:31
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
I have updated the code for you and play with the padding & content box. this will work across all the browser.
Check out this codepen
<div id="container1">
<input id="textbox" type="text" value="Test" />
<span>TestText</span>
<div>TestText</div>
<select id="dropdown">
<option>Test</option>
</select>
</div>
#container1 input[type="text"],
#container1 select,
#container1 span,
#container1 div {
padding: 1em;
border: 1px solid #ccc;
line-height: 16px;
height: 16px;
font-size: 14px;
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
display: inline-block;
margin: 10px 10px 0px 20px;
}
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Danoram
Nov 22 at 8:14
Thank you for your solution. This is working but I have one issue with it. The positioning inside the container is only working with margin. When I change to margin to 0 and use padding of the container again, the select box is moved up slightly. codepen.io/anon/pen/KrQjWZ I don't get why this has to be so difficult or why the form-controls behave differently than any other element :-(
– Auskennfuchs
Nov 22 at 10:11
1
This issue can resolve with using flex property and also we have to use px for line height and height. Check out this codepen
– Sumit Patel
Nov 22 at 12:17
add a comment |
up vote
0
down vote
I've tested your code and found that the font-family: inherit in input, select, textarea is extra.
Inherits this property from its parent element. The inherit keyword specifies that a property should inherit its value from its parent element.
From: https://www.w3schools.com/cssref/pr_font_font-family.asp
Your input, select,div are already in the container class, the font-family is inherited by default.
You could modfiy your code as follow.
HTML.
<div class="container">
<input type="text" value="TestText">
<span>TestText</span>
<div>TestText</div>
<select>
<option>Test</option>
</select>
</div>
CSS.
input, select, span, div {
line-height: 1.15em;
height: 1.15em;
box-sizing: content-box;
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
I have updated the code for you and play with the padding & content box. this will work across all the browser.
Check out this codepen
<div id="container1">
<input id="textbox" type="text" value="Test" />
<span>TestText</span>
<div>TestText</div>
<select id="dropdown">
<option>Test</option>
</select>
</div>
#container1 input[type="text"],
#container1 select,
#container1 span,
#container1 div {
padding: 1em;
border: 1px solid #ccc;
line-height: 16px;
height: 16px;
font-size: 14px;
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
display: inline-block;
margin: 10px 10px 0px 20px;
}
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Danoram
Nov 22 at 8:14
Thank you for your solution. This is working but I have one issue with it. The positioning inside the container is only working with margin. When I change to margin to 0 and use padding of the container again, the select box is moved up slightly. codepen.io/anon/pen/KrQjWZ I don't get why this has to be so difficult or why the form-controls behave differently than any other element :-(
– Auskennfuchs
Nov 22 at 10:11
1
This issue can resolve with using flex property and also we have to use px for line height and height. Check out this codepen
– Sumit Patel
Nov 22 at 12:17
add a comment |
up vote
2
down vote
I have updated the code for you and play with the padding & content box. this will work across all the browser.
Check out this codepen
<div id="container1">
<input id="textbox" type="text" value="Test" />
<span>TestText</span>
<div>TestText</div>
<select id="dropdown">
<option>Test</option>
</select>
</div>
#container1 input[type="text"],
#container1 select,
#container1 span,
#container1 div {
padding: 1em;
border: 1px solid #ccc;
line-height: 16px;
height: 16px;
font-size: 14px;
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
display: inline-block;
margin: 10px 10px 0px 20px;
}
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Danoram
Nov 22 at 8:14
Thank you for your solution. This is working but I have one issue with it. The positioning inside the container is only working with margin. When I change to margin to 0 and use padding of the container again, the select box is moved up slightly. codepen.io/anon/pen/KrQjWZ I don't get why this has to be so difficult or why the form-controls behave differently than any other element :-(
– Auskennfuchs
Nov 22 at 10:11
1
This issue can resolve with using flex property and also we have to use px for line height and height. Check out this codepen
– Sumit Patel
Nov 22 at 12:17
add a comment |
up vote
2
down vote
up vote
2
down vote
I have updated the code for you and play with the padding & content box. this will work across all the browser.
Check out this codepen
<div id="container1">
<input id="textbox" type="text" value="Test" />
<span>TestText</span>
<div>TestText</div>
<select id="dropdown">
<option>Test</option>
</select>
</div>
#container1 input[type="text"],
#container1 select,
#container1 span,
#container1 div {
padding: 1em;
border: 1px solid #ccc;
line-height: 16px;
height: 16px;
font-size: 14px;
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
display: inline-block;
margin: 10px 10px 0px 20px;
}
I have updated the code for you and play with the padding & content box. this will work across all the browser.
Check out this codepen
<div id="container1">
<input id="textbox" type="text" value="Test" />
<span>TestText</span>
<div>TestText</div>
<select id="dropdown">
<option>Test</option>
</select>
</div>
#container1 input[type="text"],
#container1 select,
#container1 span,
#container1 div {
padding: 1em;
border: 1px solid #ccc;
line-height: 16px;
height: 16px;
font-size: 14px;
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
display: inline-block;
margin: 10px 10px 0px 20px;
}
edited Nov 22 at 9:03
Yoram de Langen
3,87611626
3,87611626
answered Nov 22 at 7:44
Sumit Patel
1846
1846
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Danoram
Nov 22 at 8:14
Thank you for your solution. This is working but I have one issue with it. The positioning inside the container is only working with margin. When I change to margin to 0 and use padding of the container again, the select box is moved up slightly. codepen.io/anon/pen/KrQjWZ I don't get why this has to be so difficult or why the form-controls behave differently than any other element :-(
– Auskennfuchs
Nov 22 at 10:11
1
This issue can resolve with using flex property and also we have to use px for line height and height. Check out this codepen
– Sumit Patel
Nov 22 at 12:17
add a comment |
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Danoram
Nov 22 at 8:14
Thank you for your solution. This is working but I have one issue with it. The positioning inside the container is only working with margin. When I change to margin to 0 and use padding of the container again, the select box is moved up slightly. codepen.io/anon/pen/KrQjWZ I don't get why this has to be so difficult or why the form-controls behave differently than any other element :-(
– Auskennfuchs
Nov 22 at 10:11
1
This issue can resolve with using flex property and also we have to use px for line height and height. Check out this codepen
– Sumit Patel
Nov 22 at 12:17
1
1
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Danoram
Nov 22 at 8:14
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– Danoram
Nov 22 at 8:14
Thank you for your solution. This is working but I have one issue with it. The positioning inside the container is only working with margin. When I change to margin to 0 and use padding of the container again, the select box is moved up slightly. codepen.io/anon/pen/KrQjWZ I don't get why this has to be so difficult or why the form-controls behave differently than any other element :-(
– Auskennfuchs
Nov 22 at 10:11
Thank you for your solution. This is working but I have one issue with it. The positioning inside the container is only working with margin. When I change to margin to 0 and use padding of the container again, the select box is moved up slightly. codepen.io/anon/pen/KrQjWZ I don't get why this has to be so difficult or why the form-controls behave differently than any other element :-(
– Auskennfuchs
Nov 22 at 10:11
1
1
This issue can resolve with using flex property and also we have to use px for line height and height. Check out this codepen
– Sumit Patel
Nov 22 at 12:17
This issue can resolve with using flex property and also we have to use px for line height and height. Check out this codepen
– Sumit Patel
Nov 22 at 12:17
add a comment |
up vote
0
down vote
I've tested your code and found that the font-family: inherit in input, select, textarea is extra.
Inherits this property from its parent element. The inherit keyword specifies that a property should inherit its value from its parent element.
From: https://www.w3schools.com/cssref/pr_font_font-family.asp
Your input, select,div are already in the container class, the font-family is inherited by default.
You could modfiy your code as follow.
HTML.
<div class="container">
<input type="text" value="TestText">
<span>TestText</span>
<div>TestText</div>
<select>
<option>Test</option>
</select>
</div>
CSS.
input, select, span, div {
line-height: 1.15em;
height: 1.15em;
box-sizing: content-box;
}
add a comment |
up vote
0
down vote
I've tested your code and found that the font-family: inherit in input, select, textarea is extra.
Inherits this property from its parent element. The inherit keyword specifies that a property should inherit its value from its parent element.
From: https://www.w3schools.com/cssref/pr_font_font-family.asp
Your input, select,div are already in the container class, the font-family is inherited by default.
You could modfiy your code as follow.
HTML.
<div class="container">
<input type="text" value="TestText">
<span>TestText</span>
<div>TestText</div>
<select>
<option>Test</option>
</select>
</div>
CSS.
input, select, span, div {
line-height: 1.15em;
height: 1.15em;
box-sizing: content-box;
}
add a comment |
up vote
0
down vote
up vote
0
down vote
I've tested your code and found that the font-family: inherit in input, select, textarea is extra.
Inherits this property from its parent element. The inherit keyword specifies that a property should inherit its value from its parent element.
From: https://www.w3schools.com/cssref/pr_font_font-family.asp
Your input, select,div are already in the container class, the font-family is inherited by default.
You could modfiy your code as follow.
HTML.
<div class="container">
<input type="text" value="TestText">
<span>TestText</span>
<div>TestText</div>
<select>
<option>Test</option>
</select>
</div>
CSS.
input, select, span, div {
line-height: 1.15em;
height: 1.15em;
box-sizing: content-box;
}
I've tested your code and found that the font-family: inherit in input, select, textarea is extra.
Inherits this property from its parent element. The inherit keyword specifies that a property should inherit its value from its parent element.
From: https://www.w3schools.com/cssref/pr_font_font-family.asp
Your input, select,div are already in the container class, the font-family is inherited by default.
You could modfiy your code as follow.
HTML.
<div class="container">
<input type="text" value="TestText">
<span>TestText</span>
<div>TestText</div>
<select>
<option>Test</option>
</select>
</div>
CSS.
input, select, span, div {
line-height: 1.15em;
height: 1.15em;
box-sizing: content-box;
}
answered Nov 23 at 8:01
Jenifer Jiang
161
161
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422259%2fvertical-centering-of-text-of-select-element%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Probably because you have given a
height
to theoption
. I tried to remove it and it does center.– Gurtej Singh
Nov 22 at 0:26
Correct, it looks like your height option is cause problems. I'd recommend removing the Option out of the CSS rule which gives it a height.
– Robert Perez
Nov 22 at 0:29
Unfortunately not for me. I've removed
option
from the selector and still get the same result.– Auskennfuchs
Nov 22 at 0:31