How to hide the border HTML CSS Select? [duplicate] - html

This question already has answers here:
How to remove border of drop down list : CSS
(4 answers)
Closed 2 years ago.
I want select without border before and after option selected.
I have tried below css code but unfortunately without success.
.custom-select{
font-family: Raleway;
font-size: 18px;
color: grey;
min-height: 75px;
width: 99%;
height: auto;
}
select{
min-width: 40px;
min-height: 40px;
width: 99%;
border: 0;
border-width: 0px;
box-shadow: 5px 5px 10px rgba(0, 40, 0, 0.5);
border-radius: 5px;
box-sizing: content-box;
}
select option:checked{
background-color: grey;
border-width: 0px;
box-sizing: content-box;
border: 0;
}
select:active{
background-color: grey;
border-width: 0px;
box-sizing: content-box;
border: 0;
}
<div class="cutom-select">
<select>
<option>India</option>
<option>India</option>
<option>India</option>
</select>
</div>
Please suggest me where am I doing mistake?
Thanx.

Here try this:
.cutom-select select:focus{
outline: none !important;
}
working example:
.custom-select{
font-family: Raleway;
font-size: 18px;
color: grey;
min-height: 75px;
width: 99%;
height: auto;
}
select{
min-width: 40px;
min-height: 40px;
width: 99%;
border: 0;
border-width: 0px;
box-shadow: 5px 5px 10px rgba(0, 40, 0, 0.5);
border-radius: 5px;
box-sizing: content-box;
}
select option:checked{
background-color: grey;
border-width: 0px;
box-sizing: content-box;
border: 0;
}
select:active{
background-color: grey;
border-width: 0px;
box-sizing: content-box;
border: 0;
}
.cutom-select select:focus{
outline: none !important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="cutom-select">
<select>
<option>India</option>
<option>India</option>
<option>India</option>
</select>
</div>

set select:focus {outline: none;}

Note that that is not a border! it is an outline. To remove it you have to use outline: none;. To know more about outlines take a look here.
something like this
.custom-select{
font-family: Raleway;
font-size: 18px;
color: grey;
min-height: 75px;
width: 99%;
height: auto;
}
select{
min-width: 40px;
min-height: 40px;
width: 99%;
border: 0;
border-width: 0px;
box-shadow: 5px 5px 10px rgba(0, 40, 0, 0.5);
border-radius: 5px;
box-sizing: content-box;
outline: none; /* <-------[added line] (if it doesn't work like this adding !important) */
}
select option:checked{
background-color: grey;
border-width: 0px;
box-sizing: content-box;
border: 0;
}
select:active{
background-color: grey;
border-width: 0px;
box-sizing: content-box;
border: 0;
}
<div class="cutom-select">
<select>
<option>India</option>
<option>India</option>
<option>India</option>
</select>
</div>
Be careful! this code always removes the outline (also when the element is not focuses). To remove it only when focused you should use :focus.
Note that Outline differs from borders! Unlike border, the outline is drawn outside the element's border, and may overlap other content. Also, the outline is NOT a part of the element's dimensions; the element's total width and height is not affected by the width of the outline.
In some browsers (like google chrome) outline is set as default, when selected, on some elements like select or button
Note also (from w3school) that outline has the following properties.
dotted - Defines a dotted outline dashed - Defines a dashed
outline solid - Defines a solid outline double - Defines a
double outline groove - Defines a 3D grooved outline ridge -
Defines a 3D ridged outline inset - Defines a 3D inset outline
outset - Defines a 3D outset outline none - Defines no outline
hidden - Defines a hidden outline

Related

Minimal CSS for form elements and links to have same height

A problem that seems to pop up again and again in my projects is styling form elements and links to have the same height.
Here's an simple example (fiddle):
HTML:
<select><option>one</option></select>
<input type="text">
<button>foo</button>
test
CSS:
select,
input,
button,
a {
padding: 0.5rem;
margin: 0.25rem;
border: 1px solid red;
}
All elements receive the exact same styling with a padding, a margin and a border. But they all differ slightly in height and I don't really understand why.
Can someone
explain where the difference comes from? Chrome inspector tells me that the actual inner element of each has different sizes - shouldn't it be the same?
tell me what minimal changes I need to do to my CSS to achieve what I want without styling each of the elements slightly different? My goal is to pick the padding, margin and border sizes freely (using variables) and still have consistent heights.
Updated fiddle with solution
The minimal version:
You'll need to add the additional rules like below:
select,
input,
button,
a {
padding: 0.5rem;
margin: 0.25rem;
border: 1px solid red;
display: inline-block; /*new*/
font: inherit; /*new*/
}
But that will still not guarantee they receive the same height for certain input types in certain browsers. You can also reset the appearance but I would not recommend to do it globally, unless it's required by design.
-webkit-appearance: none;
appearance: none;
The non-minimal version:
*,
*:before,
*:after {
box-sizing: border-box;
}
::-moz-focus-inner {
border-style: none;
padding: 0;
}
::-webkit-file-upload-button {
font: inherit;
-webkit-appearance: button;
}
::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
height: auto;
}
::-webkit-search-cancel-button,
::-webkit-search-decoration {
-webkit-appearance: none;
}
button,
input,
optgroup,
select,
textarea {
font-family: inherit;
font-size: 1rem;
line-height: 1.15;
margin: 0;
}
button,
input {
overflow: visible;
}
button,
select {
text-transform: none;
}
[type="checkbox"],
[type="radio"] {
padding: 0;
}
[type="search"] {
outline-offset: -2px;
-webkit-appearance: textfield;
}
[type="color"],
[type="date"],
[type="datetime"],
[type="datetime-local"],
[type="email"],
[type="month"],
[type="number"],
[type="password"],
[type="search"],
[type="tel"],
[type="text"],
[type="time"],
[type="url"],
[type="week"],
select,
textarea,
button,
[type="button"],
[type="reset"],
[type="submit"] {
display: inline-block;
vertical-align: middle;
height: calc(2.25rem + 2px);
color: #333;
border: 1px solid #ccc;
border-radius: 3px;
}
[type="color"],
[type="date"],
[type="datetime"],
[type="datetime-local"],
[type="email"],
[type="month"],
[type="number"],
[type="password"],
[type="search"],
[type="tel"],
[type="text"],
[type="time"],
[type="url"],
[type="week"],
select,
textarea {
max-width: 100%;
padding: 0.5rem;
background-clip: padding-box;
background-color: #fff;
box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.1);
}
[type="color"]:focus,
[type="date"]:focus,
[type="datetime"]:focus,
[type="datetime-local"]:focus,
[type="email"]:focus,
[type="month"]:focus,
[type="number"]:focus,
[type="password"]:focus,
[type="search"]:focus,
[type="tel"]:focus,
[type="text"]:focus,
[type="time"]:focus,
[type="url"]:focus,
[type="week"]:focus,
select:focus,
textarea:focus {
border-color: rgb(30, 144, 255);
box-shadow: 0 0 2px rgba(30, 144, 255, 0.8);
outline: 0;
}
button,
[type="button"],
[type="reset"],
[type="submit"] {
padding: 0.5rem 0.75rem;
background-color: #f7f7f7;
box-shadow: 0 1px 0 #ccc;
cursor: pointer;
-webkit-appearance: button;
}
button:hover,
[type="button"]:hover,
[type="reset"]:hover,
[type="submit"]:hover {
background-color: #fafafa;
border-color: #999;
}
button:focus,
[type="button"]:focus,
[type="reset"]:focus,
[type="submit"]:focus {
border-color: rgb(30, 144, 255);
box-shadow: 0 0 2px rgba(30, 144, 255, 0.8);
outline: 0;
}
button:active,
[type="button"]:active,
[type="reset"]:active,
[type="submit"]:active {
background-color: #eee;
border-color: #999;
box-shadow: inset 0 2px 5px -3px rgba(0, 0, 0, 0.5);
}
button:disabled,
[type="button"]:disabled,
[type="reset"]:disabled,
[type="submit"]:disabled {
background-color: #f7f7f7;
color: #a0a5aa;
border-color: #ddd;
box-shadow: none;
text-shadow: 0 1px 0 #fff;
cursor: default;
}
select {
-moz-appearance: textfield;
-webkit-appearance: textfield;
}
select::-ms-expand {
display: none;
}
select[multiple],
select[size]:not([size="1"]) {
height: auto;
padding: 0;
}
select[multiple] option,
select[size]:not([size="1"]) option {
padding: 0.5rem;
}
select:not([multiple]):not([size]),
select:not([multiple])[size="1"] {
padding-right: 2rem;
background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z'/%3E%3Cpath fill='none' d='M0 0h24v24H0V0z'/%3E%3C/svg%3E") right 0.25rem center no-repeat;
}
textarea {
height: auto;
overflow: auto;
}
<select>
<option>one</option>
</select>
<input type="text" placeholder="text">
<button>foo</button>
Most of the code above doesn't answer the question directly or even unrelated, and it doesn't include the <a> tag. But in a real web application, it's likely end up having more or less the same amount of CSS.
(Tested with Chrome only)
explain where the difference comes from?
It comes from user agent stylesheet which apply different style as default for each tag.
Those styles change according to the browser.
tell me what minimal changes I need to do to my CSS
input, select and button tags have a default font size which doesn't inherit from your body font-size declaration. Set their font-size value to inherit.
input, select, button {
font-size: inherit;
}
a tag is inline by default. Set its value to inline-block.
Also, set its box-sizing value to border-box.
a {
display: inline-block;
box-sizing: border-box;
}
select has a biggest height content because of its the dropdown icon.
You could fix it by removing its default appearance, but I wouldn't recommend it.
select {
-webkit-appearance: none;
}
Demo
body {
font-size: 16px
}
select,
input,
button,
a {
padding: 0.5rem;
margin: 0.25rem;
border: 1px solid red;
vertical-align: top;
}
input,
select,
button {
font-size: inherit;
}
a {
display: inline-block;
box-sizing: border-box;
}
/* Bad practice */
select {
-webkit-appearance: none;
}
<select>
<option>Select</option>
</select>
<input type="text" value="Input">
<button>Button</button>
Link
An other solution would be to use height + line-height properties for centering your elements and give them the same height.
body {
font-size: 16px
}
select,
input,
button,
a {
height: 40px;
line-height: 40px;
display: inline-block;
vertical-align: top;
margin: 0.25rem;
padding: 0 0.5rem;
border: 1px solid red;
font-size: inherit;
box-sizing: border-box;
}
<select>
<option>Select</option>
</select>
<input type="text" value="Input">
<button>Button</button>
Link
1. From what I understand, the CSS specification for form elements is very loose, so it can be difficult to apply styles at the same time to many different kinds of form elements. Because of this, these different elements all apply your style rules differently.
2. I was able to make the elements all have the same height with one more CSS rule inside the second set of selectors for your form elements:
body {
font-size: 16px;
}
select,
input,
button,
a {
padding: 0.5rem;
margin: 0.25rem;
border: 1px solid red;
font: 1rem "Helvetica", sans-serif;
}
You could change this font to whatever you like and it should still work. What this style primarily accomplishes is to "normalize" everything, especially the "a" element. The "a" element appears to want to keep its initial font-family and some form of its initial font-size. So, with the font style, you can make sure every element is inheriting the body's font size with the 1rem and that each element has a consistent font.

HTML textarea shows dynamic text half the height

HTML <textarea> shows dynamic text half its height when it first loads [when the page loads] like this:
When you focus and start typing or pushing left or right arrow keys, then it shows the text to its full height as it should like this.
How to make the dynamic text appear at its full height when it first loads without having to focus on the <textarea> and push right/left arrow keys? Here is the HTML and CSS codes:
textarea {
height: 55px;
background-color: #009688;
font-size: 55px;
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: none;
border-bottom: 2px solid white;
}
<textarea id="location" style="overflow:hidden"></textarea>
Thank you.
I think it is because the padding/margin you have added. Try running by removing the padding/margin and see if that works for you.
You want the height to include the padding and border size as you have used box-sizing so your height should be the size of the font plus top and bottom padding and border
In this case that is 55px (font) + 24px (12px top and 12px bottom padding) + 2px (border - you have no top and 2px bottom) = 81px
textarea {
height: 81px;
background-color: #009688;
font-size: 55px;
line-height:55px; /* added this just to ensure the line height is the same as the font size */
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: none;
border-bottom: 2px solid white;
}
<textarea id="location" style="overflow:hidden">someText</textarea>
Please check the updated one. Added line-height and updated attribute to rows=1 instead of giving height to textarea.
textarea {
min-height: 55px;
background-color: #009688;
font-size: 55px;
line-height: 60px;
width: 100%;
padding: 0 20px;
margin: 8px 0;
box-sizing: border-box;
border: none;
border-bottom: 2px solid white;
}
<textarea id="location" rows="1" style="overflow:hidden"></textarea>
Just increase height as height and font-size is same:
textarea {
height: 80px;
background-color: #009688;
font-size: 55px;
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
border: none;
border-bottom: 2px solid white;
}
Adjust font-size and padding like
padding: 12px 12px;
and
font-size: 40px;
Try this: I just remove the padding. You can also add the padding just add more height
Explanation:
The size of font and the height of textarea is the same PLUS you have a padding.
textarea {
height: 55px;
background-color: #009688;
font-size: 55px;
width: 100%;
/*padding: 12px 20px;*/
margin: 8px 0;
box-sizing: border-box;
border: none;
border-bottom: 2px solid white;
}
<textarea id="location" style="overflow:hidden">Prefilled</textarea>

How to create a border in css that doesn't change size?

So I have this code:
<h1 id="result" style="color:black; font-family: Bradley Hand; font-size:50px; position:absolute; top:17%; left:60%">
text
</h1>
How can I make a border that if I put a longer text in, my border will keep its position and change its size, to make my text still in the border? Thanks!
Just adding border: 1px solid black (for example) to what you have works perfectly fine. The h1 element will grow and shrink to fit it's content and the border will do so as well:
const result = document.getElementById('result');
const sentence = "HELLO! IT LOOKS LIKE THIS IS WORKING FINE...";
let index = 0;
setInterval(() => {
index = (index % sentence.length) + 1;
result.innerHTML = sentence.slice(0, index);
}, 250);
#result {
position:absolute;
top: 10%;
left: 10%;
padding: 0 .5rem;
font-family: Sans-Serif;
font-size: 2rem;
line-height: 3rem;
color: black;
border: 3px solid black;
border-radius: 3px;
min-height: 3rem;
}
<h1 id="result"></h1>
Anyway, I suspect you may be referring to the border changing your element's dimension:
#bar1 {
width: 50%;
height: 1rem;
background: red;
margin: .25rem;
}
#bar2 {
width: 50%;
height: 1rem;
background: cyan;
margin: .25rem;
border: 3px solid black;
}
<div id="bar1"></div>
<div id="bar2"></div>
That's because by default, your element's width and height are actually a sum of the specified width and height properties, plus padding plus border, as you can see from the example above.
If that's the case, you have two options to keep the dimensions just as specified with width and height:
Using box-sizing: border-box. That will make padding and border included in the element's total width and height.
Using box-shadow instead of border. You can use the inset property to draw the shadow to the inside of the element instead of to the outside.
#bar1 {
width: 50%;
height: 1rem;
background: red;
margin: .25rem;
}
#bar2 {
width: 50%;
height: 1rem;
background: cyan;
margin: .25rem;
border: 3px solid black;
box-sizing: border-box;
}
#bar3 {
width: 50%;
height: 1rem;
background: yellow;
margin: .25rem;
box-shadow: inset 0 0 0 3px black;
}
#bar4 {
width: 50%;
height: 1rem;
background: lime;
margin: .25rem;
box-shadow: 0 0 0 3px black;
}
<div id="bar1"></div>
<div id="bar2"></div>
<div id="bar3"></div>
<div id="bar4"></div>
Note the 4th bar, the one with the outer box-shadow looks bigger, but if you inspect it, its dimensions are exactly the same as those in the other 3 bars.
Can you just add border: solid 1px black; to the style attribute, like this?
<h1 id="result" style="border: solid 1px black; color:black; font-family: Bradley Hand; font-size:50px; position:absolute; top:17%; left:60%">text</h1>
Fiddle: https://jsfiddle.net/myingling/LL57yd8j/
Here's some reading on CSS borders: https://www.w3schools.com/css/css_border.asp

Firefox button and text input bug

I have this really weird problem, button and input have a same CSS (except background), but Firefox renders those differently. There are no problems in IE or Chrome.
#searchInput {
width: 80%;
margin: 0 auto;
display: block;
height: 40px;
border: 1px solid #D8D8D8;
font-size: 1rem;
padding: 10px;
text-align: center;
}
#searchButton {
width: 80%;
margin: 4px auto;
display: block;
height: 40px;
border: 1px solid #D8D8D8;
font-size: 1rem;
padding: 10px;
text-align: center;
background: #F2F2F2;
cursor: pointer;
}
I have also included container CSS, where they both are.
.section {
width: 100%;
display: inline-block;
margin: 10px auto;
background-color: #FAFAFA;
border-radius: 5px;
border: 1px solid #D8D8D8;
padding: 30px;
position: relative;
}
.toggleIcon {
width: 28px;
height: 20px;
top: 0;
right: 10px;
position: absolute;
border-radius: 5px;
background: #FAFAFA;
margin-top: 10px;
padding: 10px;
border: 1px solid #D8D8D8;
cursor: pointer;
box-sizing: content-box;
}
HTML:
<div id='search' class='section'> <a href="#sidebarNav" class='toggle'><img class = 'toggleIcon' src = 'img/icons/glyphicons_158_show_lines.png' alt = 'Open navigation'></a>
<img id='logo' src='img/logo.png'>
<form id='searchForm'>
<input type='text' id='searchInput' name='searchInput'>
<button type='submit' id='searchButton' name='searchButton' value='Search'>
<img src='img/icons/glyphicons_027_search.png' alt='Search'>
</button>
</form>
<div id='searchResults'></div>
</div>
NB! I use PageSlide for navigation and search is using AJAX
Based on your last comment...
Margin doesn't cause my problems, problem is that input is much wider
and higher
You have to add box-sizing:border-box property to your input#searchInput
Like:
#searchInput {
....
box-sizing: border-box;
-moz-box-sizing: border-box; /* Firefox */
}
Working Example: http://jsfiddle.net/XLyBR/1/
Your margin differs in the searchInput and searchButton css classes
Also what about the default css line-height on these elements - do they differ - try specifying line-height.
Wing
BTW - it would help if you tell us how the rendering differs

CSS form ie7 bug with margin left and float

This css code has troubles for ie7. In ie6 is a total absolute mess.
The problem is that the input textbox gets bellow label.
Only work around is to float the div left but has problems then with sizing..
fieldset.label_side > label {
width: 100px;
position: relative;
float: left;
left: 0;
padding: 18px 20px 8px;
border-right: 1px solid #eee;
clear: left;
line-height: normal;
}
fieldset label{
font-size: 13px;
font-weight: bold;
padding: 15px 20px 10px;
margin-right: 10px;
display: inline-block;
color: #333;
}
fieldset.label_side > div {
width: auto;
margin-left: 140px;
padding: 15px 20px;
border-left: 1px solid #eee;
clear: right;
display: block;
}
.box-block fieldset input{
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
}
input.text{
width: 100% !important;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
border : solid #eee 1px;
background-color: #fbfbfb;
line-height: 32px;
display: inline;
height: 32px;
padding: 0px 0 0 5px;
}
UPDATE
I found that the problem is because of the input width 100%.. I am looking how to fix it.
IE6 and IE7 don't play nice when the display is set to "inline-block";
Try adding the following to your label's CSS rule:
fieldset label{
display:-moz-inline-stack;
display:inline-block;
zoom:1;
*display:inline;
}
I would probably have a conditional sheet for IE browsers (usually how I deal with this problem). Here's a site that exlains the problem in better details than I ever could: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
May be you have to write vertical-align:top in your label & input . Write like this:
label, input{
vertical-align:top;
}
One solution that may work (it works for me) is to apply negative margin at input (textbox)... or fixed width for ie7 or to drop ie7 support.
I had the same problem and i hated to have extra divs for border etc!
So here is my solution which seems to work!
You should use a ie7 only stylesheet to avoid the starhacks.
input.text{
background-color: #fbfbfb;
border : solid #eee 1px;
width: 100%;
-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
height: 32px;
*line-height:32px;
*margin-left:-3px;
*margin-right:-4px;
display: inline;
padding: 0px 0 0 5px;
}