Css: How to get rid of this extra space after and before the text?

Here is the image:

http://i.stack.imgur.com/vXr5f.png

HTML is in php, which looks like this:

print "<p class = 'Back'>Epic Fail</p>"; print "<p>You forgot to put in your Username or Password.</p>"; 

The CSS for the Back and p class is as follows:

 p.Back { font-size: 200px; display: block; text-align: left; font-style: oblique; } p { font-size: 20px; color: #292421; font-family: Times; } 

This is all wrapped with a div tag that has 25px padding, why is there so much free space? This is a problem because it creates a scrollbar that I don’t want, and it doesn’t look very good.

EDIT: Here's the div:

 #login { background: #E0DFDB; width: 1200px; margin: auto; } 

I am using the latest version of Google Chrome ("Sorry I didn’t specify") The scrollbar is successfully deleted, removing the registration from the login login and line height. However, there is still a space, and I completely ran through all my code to see if I added anything to the p tag, but I could not find anything. Is there a website where I can upload all my code to show you guys?

RESULT:

Thanks guys, I decided to use the web developer tool that came with Chrome Chrome and IT TURNS OUT: MARGIN DEFAULT, WHICH GOT AT 200PX ?? !! so all i had to do was just set the p field to auto

+4
source share
3 answers

This is because, by default, Chrome uses the style from -webkit-margin-before: 1em; -webkit-margin-after: 1em -webkit-margin-before: 1em; -webkit-margin-after: 1em to p . In your example, this would create a 200px mark above and below the element. The margin: auto parameter or any other margin value overrides this default value.

Other browsers use the p elements differently by default: for example. Firefox uses margin: 1em 0 , which has the same effect.

Fields are not displayed on jsfiddle because they use a reset stylesheet that gives p margin: 0 elements.

+3
source

Not sure what you are trying to accomplish, but a combination

  • padding on div and
  • extra line-height

may cause excess.

Currently adding

  • 50px from padding (25px top and bottom)
  • 50px from line-height (which is 50px more than font-size )

I tried your current code in a fiddle and it seems to work fine (drag the panel to the left to see the whole screen)

http://jsfiddle.net/jasongennaro/aNRhN/

Perhaps there is other code that is being inserted with PHP?

Or you have other styles applied to p .

+1
source

I created the version of JSFiddle code you posted - see http://jsfiddle.net/RukbS/

In my JSFiddle, I don’t see the massive empty space under "Epic Fail", which is in your screenshot, so I assume that there is something in the code that you are using that you did not show us.

Not seeing your code actually in action, it's hard to understand what the difference is between it and the version I created, but looking at the screenshot, it looks very much like the paragraph “Epic Fail” ended in two lines.

The only way I could get my test to reproduce this is to put <br><br> right after the word “Fail”. I assume you are not doing this.

You might want to consider adding the line-height attribute from the stylesheet. Actually, this is not very much (since in any case it will depend on the font size), and this is what can cause what you see. If you really need some free space around the text, use padding or margin ; it is easier to control than line-height .

You did not indicate which browser you are using, which shows this effect. Perhaps you see something that only appears in some browsers. Most browsers these days have a good debugging tool that can help isolate such issues. In Firefox, you need to install the Firebug plugin; Most other modern browsers have a built-in Developer Tools feature.

Open the Firebug / Dev Tools window and use it to find the "Epic Fail" element. This will allow you to examine the size and shape of the element and what styles apply to it. This will almost certainly give you the information you need to solve the problem.

I know that I did not give you an answer that directly solves the problem, but I hope that some of the things that I have indicated here will lead you in the right direction to finding the problem.

+1
source

All Articles