CSS differences between Firefox and Chrome - vertical height [closed] - html

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm having some trouble getting Firefox and Chrome to display a small section of CSS properly.
I've broken it down as much as possible and created a Codepen to illustrate the problem.
When viewed in Firefox, everything displays as intended (vertically centered). With Chrome, the labels are slightly too high, by one or two pixels.
Everything I've tried so far (adjusting padding, changing floats, adding inline-block, adding margins) will always display incorrectly in one of the two browsers.
What I'd like to know then is what the root cause of the issue is. I use a CSS reset (normalise.css) which is added to the Pen.
Link: Codepen
<div class="editbox">
<div class="object objecthover edit">
<label class="t">Edit</label>
</div>
<div class="object objecthover lock">
<label class="text_label">Lock</label>
<label class="gems index-gems">50 </label>
</div>
</div>
.editbox {
position: absolute;
height: 60px;
width: 192px;
background-color: #516580;
padding-top: 12px;
left: 0px;
}
* {
box-sizing: border-box;
}
.edit, .save {
min-width: 50px;
padding: 7px;
}
.editbox label {
-moz-user-select: none;
color: #FFF;
height: 35px;
}
.editbox .object {
position: relative;
border: 2px solid #FFF;
display: inline-block;
padding: 4px;
margin-left: 4px;
height: 35px;
text-align: center;
}
div.lock {
width: 130px;
height: 35px;
padding: 5px 1px 5px 0px;
}
.lock .text_label {
display: inline-block;
}
.editbox label {
-moz-user-select: none;
color: #FFF;
height: 35px;
}
.lock label.index-gems {
padding: 0px;
}
label.index-gems {
color: #FFF;
height: 27px;
padding: 4px;
}
.editbox .lock::after, .editbox .make_bid::after {
content: "";
position: absolute;
top: 33px;
height: 0px;
width: 0px;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-top: 8px solid #FFF;
}

Trying to vertically align text using padding is unreliable. Two better ways are
use display: table-cell and vertical-align: middle
set the line-height of your element to the same as the height.
The first option handles multi-line text where the second doesn't, but introducing table cells can lead to other layout issues. If you're only ever dealing with a single line of text, the second option is more straightforward.
Here's an example of using line-height to vertically align text:
div {
display:inline-block;
border:1px solid #abc;
}
.a {
line-height: 20px;
height: 20px;
}
.b {
line-height: 30px;
height: 30px;
}
.c {
line-height: 40px;
height: 40px;
}
.d {
line-height: 50px;
height: 50px;
}
.e {
line-height: 60px;
height: 60px;
}
<div class="a">text</div>
<div class="b">text</div>
<div class="c">text</div>
<div class="d">text</div>
<div class="e">text</div>

Related

How to fix div alignment issue?

I’m working on a website in which at the bottom you can see the three social media accounts it has, but with the following code, this is the output, but I don’t know what’s causing it.
As you can clearly see, there is a grey box going over the three boxes, and I don’t know how to fix this.
.container {
width: 600px;
height: 190px;
background-color: #ff7675;
padding-top: 20px;
padding-left: 15px;
padding-right: 15px;
}
#st-box {
float: left;
width: 180px;
height: 160px;
background-color: white;
border: solid black;
}
#nd-box {
float: left;
width: 180px;
height: 160px;
background-color: white;
border: solid black;
margin-left: 20px;
}
#rd-box {
float: right;
width: 180px;
height: 160px;
background-color: white;
border: solid black;
}
<div class="container">
<div id="st-box">
<iframe></iframe>
</div>
<div id="nd-box">
<iframe></iframe>
</div>
<div id="rd-box">
<iframe></iframe>
</div>
</div>
What can I do?
You should style your iframes. Here is some code that will help you on your way.
iframe {
display: block;
width: 100%;
border: 0;
}
The iframes inside your inner divs are causing these strange-looking borders. You can style them with css aswell.
For example, you might want to give them:
border:0;
width:100%;
The browser adds a default border to iframe. Give border: 0 to the iframe. Check screenshot.
iframe { border: 0; }

text not showing over border html/css

I'm trying to make a simple button. But instead of <button>, I'm using <div> and <p>, but the result will show up as only border, and the text won't show up over the border.
Am I doing something wrong?
Screenshot of the button:
.Something4 {
margin-top: -72px;
margin-left: 335px;
font-size: 20px;
width: 110px;
height: 60px;
border: 1px solid #E12976;
border-radius: 20px;
}
.Something4 p2 {
margin-left: 335px;
width: 100px;
height: 50px;
}
<div onclick="location.href='Login.php';" style="cursor: pointer;" class="Something4">
<p2 style="font-family: Sans-serif;font-size:16px;font-style:normal;">Login</p2>
</div>
I copied your code into codepen.com.
margin-top: -72px; is moving your button off the screen.
The second margin-left: 335px; in the p2 section is moving the text out of your button.
Try removing all your margins and see how it looks:
.Something4 {
font-size: 20px;
width: 110px;
height: 60px;
border: 1px solid #E12976;
border-radius: 20px;
}
.Something4 p2 {
width: 100px;
height: 50px;
}
Keep in mind the margin inside the p2 tag will not replace the margin on the border itself, and having negative margins might not always do what you think.
I would highly recommend using semantic markup to describe the content of your page. This helps make your content accessible and work as expected across a variety of devices and use cases that you might not be capturing.
So use an anchor tag <a> to link to \login.php, and then you can choose to style that similar to a button if you'd like.
body {
padding: 15px;
background: #211f1f;
}
a.login-button {
color: salmon;
border: 1px solid salmon;
padding: 10px 15px;
border-radius: 20px;
text-decoration: none;
}
Login

Strange gap between two buttons [duplicate]

This question already has answers here:
How to remove the space between inline/inline-block elements?
(41 answers)
Closed 8 years ago.
I'm experiencing a strange behaviour with the HTML button tag. It seems that when I place two buttons side by side, they have a 4px gap between them appearing out of nowhere.
Here is a fiddle which shows the issue.
As you can see from the image below, FireBug shows that the gap is neither a margin or a padding (since a padding would be shown in purple).
As a note: I'm using the latest version of Firefox on Windows 8.1 and I tried also with the CSS Reset from Eric Mayer, but the gap is still there.
It's not a really important problem, but it would be nice to know if it's normal or not and what causes it.
The problem is that in inline-block elements the whitespace in HTML becomes visual space on screen. Some solutions to fix it:
Use font-size: 0 to parent container(you have to define font-size to child elements):
.buttons {
width: 304px;
margin: 0 auto;
z-index: 9999;
margin-top: 40px;
font-size: 0;
}
button {
background-color: transparent;
border: 1px solid dimgray;
width: 150px;
height: 40px;
cursor: pointer;
}
<div class="buttons">
<button>Button1</button>
<button>Button2</button>
</div>
Another one is to use negative margin-left: -4px
.buttons {
width: 304px;
margin: 0 auto;
z-index: 9999;
margin-top: 40px;
}
button {
background-color: transparent;
border: 1px solid dimgray;
width: 150px;
height: 40px;
cursor: pointer;
margin-left: -4px;
}
<div class="buttons">
<button>Button1</button>
<button>Button2</button>
</div>
Last but i don't like it at all is to use html comments as spacers
between gaps:
.buttons {
width: 304px;
margin: 0 auto;
z-index: 9999;
margin-top: 40px;
}
button {
background-color: transparent;
border: 1px solid dimgray;
width: 150px;
height: 40px;
cursor: pointer;
}
<div class="buttons">
<button>Button1</button><!--
--><button>Button2</button>
</div>
All above will work. Good luck :)
It's because you have whitespace between button elements. Change your HTML to:
Fiddle
<div class="buttons">
<button>Button1</button><button>Button2</button>
</div>
If you just want to display one line between these buttons, add margin: -1px.
Fiddle
button {
background-color: transparent;
border: 1px solid dimgray;
width: 150px;
height: 40px;
margin: -1px;
cursor: pointer;
}
Additional Tweaks:
In Firefox, when you click on a button, it displays a weird dotted border like below:
Fiddle
To get rid of this, add this to your CSS:
button::-moz-focus-inner {
border: 0;
}
One more thing(Firefox): when you click on the button, the text moves. To prevent this add this to your CSS:
Fiddle
button:active {
padding: 0;
}
It can be corrected by
button {
background-color: transparent;
border: 1px solid dimgray;
width: 150px;
height: 40px;
cursor: pointer;
float:left;
}
As others have said, it is the whitespace between your elements. If you're using PHP, you could do something like this:
<div class="buttons">
<button>Button1</button><?php
?><button>Button2</button>
</div>
Otherwise, you could do this:
<div class="buttons">
<button>Button1</button><
button>Button2</button>
</div>
Or this, as suggested from the comments:
<div class="buttons">
<button>Button1</button><!--
--><button>Button2</button>
</div>
if you float: right; or float: left; you will see no space.
jsfiddle

Cannot Get Hover to Work over a Wrapper Div

I need your help.
I can't seem to be able to get the hover working properly over a wrapper/container DIV
CSS:
#myhover:hover {
border: 1px solid red;
}
HTML:
<div id="myhover" style="background: #ffffff;
width: 177px; height: 20px; border: 1px solid #808080;">
<div style="float: left;">
<input id="refdocs" style="padding-left: 4px; padding-right: 3px;
height: 15px; width: 158px; border: none;" type="text">
</div>
<div style="line-height:18px; font-size: 11pt; color: #779297;">+</div>
</div>
Because inline styles are the most specific in the cascade, they can over-ride things you didn't intend them to. Move your #myhover styles into a style sheet then it should work fine.
for example:
#myhover {
background: #ffffff;
width: 177px;
height: 20px;
border: 1px solid #808080;
}
jsfiddle: http://jsfiddle.net/va8Bz/
Your style attribute is overriding your stylesheet selectors. It's more specific.
You have three options here:
Move your styles out of the style attribute.
Move your styles out of the style attribute.
Add !important to the style declarations that should override the ones in your style attribute.
I suggest you move your styles out of the style attribute into a stylesheet.
Example: http://jsfiddle.net/Y7NW9/
You need to stick all your CSS in a stylesheet instead of using inline styles.
What you're trying to accomplish can be done with less markup too:
<div class="container">
<input class="refdocs" type="text">
<div class="icon">+</div>
</div>
Then in your CSS stylesheet:
.container {
display: inline-block;
position: relative;
}
.input-wrapper {
float: left;
}
.refdocs {
border: 1px solid #808080;
padding: 2px;
padding-right: 14px;
margin: 0;
}
.refdocs:hover {
border: 1px solid red;
}
.icon {
font-size: 11pt;
position: absolute;
top: 3px;
right: 5px;
}
Here's a working demo
I solved this for you in your previous question:
#add {
float: right;
width: 20px;
height: 20px;
cursor: pointer;
text-align: center;
}
#add:hover {
color: #f00;
}
http://jsfiddle.net/kUSBM/
Please respond to the questions or accept answers.

IE is not displaying absolute positioned elements out of floated elements inside a relative positioned element [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Here is the sample code to replicate the issue I'm facing while trying to position elements above their parents:
<html>
<body>
<style>
dl {
border: 1px solid red;
width: 200px;
padding-top: 40px;
margin: 0;
position: relative;
overflow: auto;
}
dt {
border: 1px solid blue;
margin: 0;
padding: 0;
width: 98px; float: left;
display: block;
}
dd {
border: 1px solid green;
margin: 0;
padding: 0;
height: 38px;
position: absolute;
top: 0px;
left: 0px;
width: 198px;
}
</style>
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
</body>
</html>
I'm trying to structure dl elements and have dd displayed on top of everything and later will display different dd -s there by user selection with javascript and that is all easy.
Currenty in ie9 in quirks mode the elements are not displayed if elements are floated side by side. If they are not floated it works as expected. Does this have a meaningful explanation or a fix that will make the dd elements display above all other elements like in other browsers (tested chrome, ff, opera, safari) ?
this is solved and it is related to dimensions of subelements and dimensions of outer element and if they are fitting inside the parent or not. This is only happening in quirks mode
Your method is not quite right. Some modifications are needed.
http://jsfiddle.net/7Jjaj/
<ul>
<li>Coffee<span>- black hot drink</span></li>
<li>Milk<span>- white cold drink</span></li>
</ul>
* { margin: 0; padding: 0; }
ul {
overflow: hidden;
width: 300px;
padding: 40px;
list-style: none;
border: 1px solid red; }
ul li {
position: relative;
float: left;
width: 148px;
border: 1px solid blue; }
ul li span {
position: absolute; left: -1px; top: -40px;
display: block; width: 148px; height: 38px; line-height: 38px;
border: 1px solid green;
}