I would like to have the same style for my buttons, links and inputs. I am having a problem with the height and I can not identify the cause.
In this example, my button and my input is 30 pixels high but my link only has 29 pixels.
* {
box-sizing: border-box;
}
html {
font-size: 62.5%;
}
body {
font-size: 2rem;
}
button, input, a {
background: none;
border: 1px solid grey;
color: black;
font-size: 1.6rem;
outline: none;
padding: 5px;
text-decoration: none;
}
<button>Hello</button>
<input type="text" placeholder="Hello" />
Hello
What is this difference?
You need to make sure your font-family is the same for all elements (currently your anchor has a different font) and also make sure your elements are block or inline block, otherwise the padding isn't applied:
* {
box-sizing: border-box;
}
html {
font-size: 62.5%;
}
body {
font-size: 2rem;
}
button,
input,
a {
display: inline-block;
font-family: arial;
background: none;
border: 1px solid grey;
color: black;
font-size: 1.6rem;
outline: none;
padding: 5px;
text-decoration: none;
}
<button>Hello</button>
<input type="text" placeholder="Hello" />
Hello
Related
I have tried several attempts to make the custom checkbox look consistent across all browsers. The only browser which i am facing problem is of Edge.
I am using decimal code for the tickmark which appears proper in all the major browsers. But for Edge i have to change the font family as Edge browser adapts the Segoe UI Symbol Font. When changing the font the appearance of the checkbox changes and it does not look consistent.
Try running the below code without the font family: Segoe UI Symbol; That is how my original checkbox looked.
label {
display: inline-block;
max-width: 100%;
}
input[type='checkbox'] {
display: none;
box-sizing: border-box;
padding: 0;
outline: none;
border: none;
background: transparent;
width: auto;
}
input[type='checkbox']:checked+.tick_mark {
color: #16a0de;
}
input[type='checkbox']+span {
cursor: pointer;
font-weight: normal;
font-size: 11px;
}
.tick_mark {
border: 1px solid #666;
padding: 0px 1px;
color: white;
margin: 6px 4px 6px 0;
font-weight: normal;
font-family: Segoe UI Symbol;
}
<label>
<input name="postSelected" class="NonUnSaved" id="chkBlog" type="checkbox" value="4">
<span class="tick_mark">✔</span>
<span class="btntooltip" data-val="checkboxTest">Text 1</span>
</label>
Try this.
label {
display: inline-block;
max-width: 100%;
}
input[type='checkbox'] {
display: none;
box-sizing: border-box;
padding: 0;
outline: none;
border: none;
background: transparent;
width: auto;
}
input[type='checkbox']:checked+.tick_mark {
color: #16a0de;
}
input[type='checkbox']+span {
cursor: pointer;
font-weight: normal;
font-size: 11px;
}
.tick_mark {
padding: 0px 1px;
color: white;
margin: 6px 4px 6px 0;
font-weight: normal;
font-family: Segoe UI Symbol;
position: relative;
}
input[type='checkbox'] + .tick_mark:before {
content: '\a0';
display: inline-block;
width: 1.1em;
height: 1.1em;
border: 1px solid #222;
margin-right: 0.25em;
line-height: 1;
position: absolute;
top: 1px;
left: -2px;
}
<label>
<input name="postSelected" class="NonUnSaved" id="chkBlog" type="checkbox" value="4">
<span class="tick_mark">✔</span>
<span class="btntooltip" data-val="checkboxTest">Text 1</span>
</label>
I think the simplest way would be to experiment with padding. This makes a better square in Edge:
.tick_mark {
...
padding: 0px 2px;
...
}
You will have to search for how to apply different css to Edge only but i think it's still possible.
You might not be able to make them all exactly the same, but very close.
In a form I have both text input and textarea input, both formatted to meet the graphic guidelines of the site. Using the following css, the textarea field displays the text only on a single row, vertical centered, instead of how I would expect. Also, the text field get the same height of the textarea, and I don't understand why. Now my goal is to have the text field formatting to be completely independent from textarea's. And to have the textarea show multiple lines with wordwrap and an autoresize for vertical only.
input[type=text],
select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-color: white;
width: 100%;
padding: 12px 12px;
margin: 8px 0;
display: inline-block;
border: 1px solid #a0a0a0;
border-radius: 5px;
box-sizing: border-box;
font-size: 16px;
font-weight: normal;
}
input[type=textarea],
select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-color: white;
width: 100%;
padding: 12px 12px;
margin: 8px 0;
display: inline-block;
border: 1px solid #a0a0a0;
border-radius: 5px;
box-sizing: border-box;
font-size: 16px;
font-weight: normal;
height: 4em;
word-wrap: normal;
vertical-align: top;
overflow: auto;
}
textarea.vert {
resize: vertical;
}
<label for="title">Title<font class="red-evidence">*</font></label>
<input type="text" id="title" name="title" placeholder="Write your title here" required>
<label for="content">Content<font class="red-evidence">*</font></label>
<input type="textarea" id="content " name="content " placeholder="Write your content here " required>
So as I told, the above code produces a textarea with a certain height but only a vertical-centered single line of text and no word-wrap, while I need word-wrap and at least two lines and autoresize in vertical. Also, the text field takes the same height of textarea, while its css does not specify that. How can I solve these issues?
If you want to use multiples lines to show the text then use textarea element instead of input.
<textarea id="content " name="content " rows="5" placeholder="Write your content here " required > </textarea>
You can further define your css accordingly
textarea {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-color: white;
width: 100%;
padding: 12px 12px;
margin: 8px 0;
display: inline-block;
border: 1px solid #a0a0a0;
border-radius: 5px;
box-sizing: border-box;
font-size: 16px;
font-weight: normal;
height: 4em;
word-wrap: normal;
vertical-align: top;
overflow: auto;
}
I'm trying to style each button and a.btn to look the same across all browsers. Using the following styles the 2 elements don't line up in Chrome and Firefox.
#wrap {
border: 2px solid red;
}
button::-moz-focus-inner {
padding: 0 !important;
border: 0 none !important;
}
a.btn, button {
display: inline-block;
border: 2px solid transparent;
border-radius: 3px;
color: #fff;
background-color: #777;
padding: 2px 5px;
font-family: sans-serif;
font-size: 16px;
line-height: 16px;
height: 27.2px;
text-decoration: none;
opacity: .85;
cursor: pointer;
box-sizing: border-box;
}
<div id="wrap">
Link
<button>Link</button>
</div>
I've tried changing the vertical-align to bottom, but while that does move the elements into a more aligned state, the text on the button itself looks mis-aligned still (demo below).
#wrap {
border: 2px solid red;
}
button::-moz-focus-inner {
padding: 0 !important;
border: 0 none !important;
}
a.btn, button {
display: inline-block;
border: 2px solid transparent;
border-radius: 3px;
color: #fff;
background-color: #777;
padding: 2px 5px;
font-family: sans-serif;
font-size: 16px;
line-height: 16px;
height: 27.2px;
text-decoration: none;
opacity: .85;
cursor: pointer;
box-sizing: border-box;
vertical-align: bottom;
}
<div id="wrap">
Link
<button>Link</button>
</div>
How can I make both elements display the same way in both Chrome and Firefox?
Erase the height setting from the rule and fine-tune the height only with the paddingparameters:
#wrap {
border: 2px solid red;
}
button::-moz-focus-inner {
padding: 0 !important;
border: 0 none !important;
}
a.btn, button {
display: inline-block;
border: 2px solid transparent;
border-radius: 3px;
color: #fff;
background-color: #777;
padding: 2px 5px;
font-family: sans-serif;
font-size: 16px;
line-height: 16px;
text-decoration: none;
opacity: .85;
cursor: pointer;
box-sizing: border-box;
}
<div id="wrap">
Link
<button>Link</button>
</div>
Chrome and Firefox both use different rendering engines to display html (Chrome uses Blink and Firefox uses Gecko). Different browsers use different rendering engines so I don't think it will look exactly the same across all browsers.
I have been writing some LESS CSS code recently, and was wondering what the best way for format this would be.
Ideally i don't want to reproduce the button classes, and separate them from the input tags, unless that's the best way to go.
.button,
button,
input[type="submit"],
input[type="reset"],
input[type="button"] {
display: inline-block;
height: 38px;
padding: 0 30px;
color: #555;
text-align: center;
font-size: 11px;
font-weight: 600;
line-height: 38px;
letter-spacing: .1rem;
text-transform: uppercase;
text-decoration: none;
white-space: nowrap;
background-color: transparent;
border-radius: 4px;
border: 1px solid #bbb;
cursor: pointer;
box-sizing: border-box;
&:hover,
&:focus {
color: #333;
border-color: #888;
outline: 0;
}
&.button-primary {
color: #FFF;
background-color: #33C3F0;
border-color: #33C3F0;
&:hover,
&:focus {
color: #FFF;
background-color: #1EAEDB;
border-color: #1EAEDB;
}
}
}
I did initially think about doing them like this
.button,
button,
input {
&:[type="submit"],
&:[type="reset"],
&:[type="button"] {}
However doing them like this would mean the button class would also have a type.
Any help would be much appreciated, thanks.
You can solve this by using the extend function in LESS.
button, .button {
// styles
}
input {
&[type="submit"], &[type="reset"], &[type="button"] {
// All styles from .button will also be available here.
&:extend(.button);
}
}
I'm experiencing a strange hover behavior on a link inside a list in Chrome.
I've managed to replicate the issue in this jsFiddle copying the whole html and css from the website.
The problem is on the first element of the side menu, which is the link with "Maria Montessori" in it. What happens is that the hover area is like interrupted in the middle, where the text is. It's like there is something covering the middle part of the button. Try it yourself to understand what I mean.
The relative code is this:
<ul class="page-menu">
<li class="page_item page-item-30">Maria Montessori</li>
<li class="page_item page-item-32">La pedagogia scientifica</li>
...
And the css:
.page-menu {
display: inline-block;
margin-right: 25px;
text-align: center;
width: 210px;
li {
margin-bottom: 10px;
}
li.current_page_item {
a {
background-color: $blue-montessori;
border-bottom: 2px solid $blue-montessori;
color: white;
font-weight: bold;
}
}
li.current_page_parent {
a {
background-color: $blue-montessori;
border-bottom: 2px solid $blue-montessori;
color: white;
font-weight: bold;
}
}
a {
background-color: $grey-light;
border-bottom: 2px solid $grey-light;
color: $grey-dark;
display: block;
font-family: Lato;
font-weight: 300;
line-height: 1.2;
padding: 15px 20px;
text-decoration: none;
text-transform: uppercase;
&:hover {
background-color: $blue-light;
border-bottom: 2px solid $blue-dark;
color: white;
font-weight: 400;
}
}
ul.children {
margin-top: 10px;
li {
margin-bottom: 10px;
margin-left: 10px;
}
li a {
background-color: #f9f9f9;
border-bottom: 2px solid #f9f9f9;
color: $grey-dark;
display: block;
font-family: Lato;
font-size: 12px;
font-weight: 400;
line-height: 1.2;
padding: 10px 20px;
text-decoration: none;
text-transform: uppercase;
&:hover {
background-color: $blue-light;
border-bottom: 2px solid $blue-dark;
color: white;
font-weight: 400;
}
}
li.current_page_item {
a {
background-color: $blue-montessori;
border-bottom: 2px solid $blue-montessori;
color: white;
font-weight: bold;
}
}
}
.page_item_has_children > .children {display: none;} /*hides the submenu*/
.page_item_has_children.current_page_item > .children,
.page_item_has_children.current_page_ancestor > .children {display: block;} /*shows the submenu for the current page or when on its subpages */
}
Inspecting it with developer tools didn't really help and what's strange is that the issue appears to be only on the first element. And in Firefox works fine, anyway.
Your div menu-menu-1-container is overlapping to your first menu because of line height property of your div .nav-menu use padding instead
.nav-menu {
padding: 17px; /* remove line-height property */
}
Updated working Code