This question already has answers here:
How do I add a "search" button in a text input field?
(7 answers)
Closed 9 years ago.
Here's what I've got:
HTML
<div class="combobox">
<input type="text" value="" name="brand" class="text" id="brand">
<span class="dropdown_btn"></span>
</div>
CSS
.combobox {
margin: 0;
padding: 0;
vertical-align: middle;
}
.combobox input {
height: 20px;
line-height: 20px;
margin: 0;
padding: 0;
}
.combobox .dropdown_btn {
width: 18px;
height: 20px;
margin-left: -20px;
display: inline-block;
cursor: pointer;
background-color: blue;
}
But it comes out like this:
I don't know where the gap is coming from; why isn't the text input snug against its container div like the blue button is?
Try setting the vertical-align:top to input
http://jsfiddle.net/KDN8s/4/
.combobox {
margin: 0;
padding: 0;
}
.combobox input {
margin: 0;
padding: 0;
height: 20px;
vertical-align: top;
}
.combobox .dropdown_btn {
width: 20px;
height: 24px;
margin-left: -20px;
display: inline-block;
cursor: pointer;
background-color: blue;
}
<div class="combobox">
<input type="text" value="" name="brand" class="text" id="brand">
<span class="dropdown_btn"></span>
</div>
Try this to add vertical-align: middle; to .combobox .dropdown_btn and remove it from the combobox class:
.combobox .dropdown_btn {
width: 18px;
height: 20px;
margin-left: -20px;
display: inline-block;
cursor: pointer;
background-color: blue;
vertical-align: middle;
}
You need to apply vertical-align: middle to your inline elements:
.combobox {
margin: 0;
padding: 0;
}
.combobox input {
height: 20px;
line-height: 20px;
margin: 0;
padding: 0;
vertical-align: middle;
}
.combobox .dropdown_btn {
width: 18px;
height: 20px;
margin-left: -20px;
display: inline-block;
cursor: pointer;
background-color: blue;
vertical-align: middle;
}
See: JSFiddle
The vertical-align property is not inherited, so you need to specify it to any inline elements that you want to adjust.
.combobox .dropdown_btn {
width: 18px;
height: 20px;
margin-left: -20px;
display: inline-block;
cursor: pointer;
background-color: blue;
vertical-align: middle;
}
http://jsfiddle.net/KDN8s/5/
Related
I want the text to be placed to the right of each icon but it ends up looking like this:
I've tried setting the .panel display to table but it looks like a mess.
.panel {
padding: 0 18px;
background-color: white;
/*#F7F7F7;*/
display: none; //With a function it's then displayed as Block
overflow: hidden;
border: 0.5px solid #ccc;
}
.lock {
float: right;
}
.status {
float: left;
}
.status_icon {
width: 30px;
height: 30px;
margin: 0;
margin-top: 4px;
margin-right: 15px;
cursor: pointer;
vertical-align: baseline;
display: table-cell;
}
.lock_icon {
width: 30px;
height: 30px;
margin: 0;
margin-top: 4px;
margin-right: 15px;
cursor: pointer;
vertical-align: baseline;
display: table-cell;
}
<div class="panel">
<div class="status">
<img src="Iconos/closed.png" alt="Closed" class="status_icon" onclick="stat(event,this);">
<p class="stat_text">Current status: Closed</p>
</div>
<div class="lock">
<img src="Iconos/locked.png" alt="Locked" class="lock_icon" onclick="lock(event,this);">
<p class="lock_text">Current lock: Locked</p>
</div>
</div>
Using display:flex would be best approach to achieve this result. Try this CSS code.
.panel {
padding: 0 18px;
background-color: white;
overflow: hidden;
border: 0.5px solid #ccc;
display: flex;
justify-content: space-between;
}
.lock {
display: flex;
}
.status {
display: flex;
}
.status_icon {
width: 30px;
height: 30px;
margin: 0;
margin-top: 4px;
margin-right: 15px;
cursor: pointer;
}
.lock_icon {
width: 30px;
height: 30px;
margin: 0;
margin-top: 4px;
margin-right: 15px;
cursor: pointer;
}
This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
CSS vertical alignment of inline/inline-block elements
(4 answers)
Closed 4 years ago.
Can anyone please tell me How can I show the icon in the middle of the image left and right side?
I tried many solutions but they not worked.
.slide {
display: inline-block;
font-size: 16px;
line-height: 20px;
padding: 7px 4px;
margin: 5px;
cursor: pointer;
height: 32px;
width: 32px;
background-color: #2874f0;
border-radius: 50%;
color: #fff;
text-align: center;
}
.image {
height: auto;
width: auto;
max-height: 350px;
max-width: 100%;
display: block;
margin: 0 auto;
}
<div style="width:100%" (click)="open_slider()">
<a class="slide">></a>
<img style="" src="https://www.vsss.co.in/Admin/uploads/472075/POLAN.jpg">
<a class="slide"><</a>
</div>
Use vertical-align: middle; to img and .slide for vertical align. And use text-align: center; to parent div for horizontal align.
Here is the working snippet.
.slide {
display: inline-block;
font-size: 16px;
line-height: 20px;
padding: 7px 4px;
margin: 5px;
cursor: pointer;
height: 32px;
width: 32px;
background-color: #2874f0;
border-radius: 50%;
color: #fff;
text-align: center;
vertical-align: middle;
}
.image {
height: auto;
width: auto;
max-height: 350px;
max-width: 100%;
display: block;
margin: 0 auto;
}
img {
display: inline-block;
vertical-align: middle;
}
<div style="width:100%; text-align: center;" (click)="open_slider()">
<a class="slide">></a>
<img style="" src="https://www.vsss.co.in/Admin/uploads/472075/POLAN.jpg">
<a class="slide">
<</a>
</div>
I added a custom styling to a input field by putting it in a label tag.
However it doesn't work as expected. I want it to have a width of 100px and a height of 25px. In addition I want the text to be centered.
HTML:
.fileContainer {
overflow: hidden;
position: relative;
}
.fileContainer [type=file] {
cursor: inherit;
display: block;
font-size: 999px;
filter: alpha(opacity=0);
min-height: 100%;
min-width: 100%;
opacity: 0;
position: absolute;
right: 0;
text-align: right;
top: 0;
}
.fileContainer {
height: 25px;
width: 100px;
border: 1px solid #6C7A89;
border-radius: 20px;
background-color: transparent;
font-size: 14px;
color: #6C7A89;
}
.fileContainer [type=file] {
cursor: pointer;
}
<label class="fileContainer">
Select file
<input name="filetoupload" type="file">
</label>
Fiddle
Try This:
.fileContainer {
position: relative;
}
.fileContainer input {
position: absolute;
z-index: 2;
opacity: 0;
width:100%;
height:100%;
}
.fileContainer {
border: 1px solid #6C7A89;
border-radius: 20px;
padding: 2px 15px;
margin: 2px;
background: transparent;
display: inline-block;
}
<div class="fileContainer">
<input name="filetoupload" type="file"/>
<span>Select file</span>
</div>
It is not happening anything regards to width and height because by default label is an inline element level.
You can add this display: flex; to the .filecontainer to make a block-level element.
and this to center the text inside it :
justify-content: center;
align-items: center;
snippet
.fileContainer {
overflow: hidden;
position: relative;
}
.fileContainer [type=file] {
opacity: 0;
position: absolute;
cursor: pointer;
}
.fileContainer {
height: 25px;
width: 100px;
border: 1px solid #6C7A89;
border-radius: 20px;
background-color: transparent;
font-size: 14px;
color: #6C7A89;
display: flex;
justify-content: center;
align-items: center;
}
<label class="fileContainer">
Select file
<input name="filetoupload" type="file">
</label>
Try This:
.fileContainer {
display: inline-block;<---------Added[Need for set width and height]
line-height: 25px;<------------Added[Center in the vertical axis]
text-align: center;<------------Added[Center in the horizontal axis]
//more code...
}
.fileContainer {
overflow: hidden;
position: relative;
}
.fileContainer [type=file] {
cursor: inherit;
display: block;
font-size: 999px;
filter: alpha(opacity=0);
min-height: 100%;
min-width: 100%;
opacity: 0;
position: absolute;
right: 0;
text-align: right;
top: 0;
}
.fileContainer {
height: 25px;
line-height: 25px;
width: 100px;
border: 1px solid #6C7A89;
border-radius: 20px;
background-color: transparent;
font-size: 14px;
color: #6C7A89;
display: inline-block;
text-align: center;
}
.fileContainer [type=file] {
cursor: pointer;
}
<label class="fileContainer">
Select file
<input name="filetoupload" type="file">
</label>
add this
.fileContainer{display:block; text-align:center;}
plz update your css "fileContainer"
.fileContainer {
overflow: hidden;
position: relative;
}
.fileContainer [type=file] {
cursor: inherit;
min-height: 100%;
min-width: 100%;
opacity: 0;
position: absolute;
right: 0;
text-align: right;
top: 0;
}
.fileContainer {
height:25px;
width:100px;
border:1px solid #6C7A89;
border-radius:20px;
background-color:transparent;
font-size:14px;
color:#6C7A89;
padding-left: 21px;
padding-right: 21px;
padding-top: 5px;
padding-bottom: 5px;
}
.fileContainer [type=file] {
cursor: pointer;
}
.file{
width: 100px;
height: 100px;
text-align: center;
}
<label class="fileContainer">
Select file
<input name="filetoupload" type="file" class="file">
</label>
<br><br><br>
<p>
/* add this css into label css "fileContainer" */ <br>
</p>
<code>
.fileContainer{
padding-left: 21px;
padding-right: 21px;
padding-top: 5px;
padding-bottom: 5px;
}
</code>
* {
margin: 0;
padding: 0;
}
.box {
width: 230px;
border: 1px solid red;
}
input {
width: 30px;
line-height: 20px;
background: #e5e5e5;
border: 0;
text-align: center;
padding: 0 5px;
font-size: 14px;
}
span {
padding: 0 2px;
cursor: pointer;
line-height: 20px;
font-size: 14px;
display: inline-block;
}
<div class="box">
<span>xx</span>
<input type="text" value="322xxx">
I want to know why there is 1px space between bottom of span and bottom of outdiv? can someone help me out?
You need to set vertical-align:top for the display: inline-block span tag
*{
margin: 0;
padding: 0;
}
.box{
width: 230px;
border:1px solid red;
}
input{
width: 30px;
line-height: 20px;
background: #e5e5e5;
border: 0;
text-align: center;
padding: 0 5px;
font-size: 14px;
}
span{
padding: 0 2px;
cursor: pointer;
line-height:20px;
font-size: 14px;
display: inline-block;
vertical-align: top;
}
<div class="box">
<span>xx</span>
<input type="text" value="322xxx">
By default, a span element is an inline level element, which respects the whitespace in the markup. Thats the reason a small space between the input and span. Thanks..
I have this html markup, I would like to center horizontally an icon I have in a sprite, it have 15 % for the icon anc 85% for the info-data class. I would like to align center the icon.
<div class="col-xs-12 mf-item">
<div class="ico icon-theme"></div>
<div class="info-data">Theme</div>
</div>
.mf-item {
background-color: #ffffff;
display: inline-block;
height: auto;
margin-left: 0;
min-height: 30px;
}
.ico {
display: inline-block;
line-height: 30px;
margin: 0 auto;
padding-right: 5px;
text-align: center;
vertical-align: middle;
width: 15%;
}
.info-data {
border-bottom: 1px solid #0f8ccd;
display: inline-block;
line-height: 30px;
margin: 0;
width: 85%;
}
.icon-theme {
background-position: 0 -90px;
height: 30px;
width: 23px;
}
Any help will be appreciate it!!!!
Thanks!
Your are missing your float:left styling. I would do it something like this
* {
box-sizing: border-box;
}
.mf-item {
background-color: #ffffff;
display: inline-block;
height: auto;
margin-left: 0;
min-height: 30px;
width:100%;
}
.ico {
display: inline-block;
height: 30px;
margin: 0 auto;
padding-right: 5px;
text-align: center;
vertical-align: middle;
width: 15%;
float:left;
}
.info-data {
border-bottom: 1px solid #0f8ccd;
display: inline-block;
line-height: 30px;
margin: 0;
width: 85%;
float:left;
}
.icon-theme {
background-position: 0 -90px;
height: 30px;
width: 23px;
display:block;
margin:0 auto;
background-color:red; //your background image imaging
}
<div class="col-xs-12 mf-item">
<div class="ico"><span class="icon-theme"></span></div>
<div class="info-data">Theme</div>
</div>
Try
vertical-align: middle;
that usually does the trick!