How to reduce gap

Here is my code …



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">

#rightbox{
	float:right;
	margin:0 35px 0 0;
	padding:0;
	width:460px;
}


.darkcolor{
	color:#003150;
}


.graytext{
	float:left;
	color:#80766e;
	font-weight:bold;
	margin:0 0 0 45px;
	padding:0 0 0 45px;
}

.clear{
	clear:both;
}


#rightbox p{
	float:left;
	margin:0 0 19px 0;
	padding:0;
	clear:both;
	font-family:Arial;
	text-align:left;
	width:410px;
}
</style>
</head>

<body>
<div id="rightbox">
<h2 class="darkcolor">Lorem ipsum dolor sit amet</h2>
<p class="clear">Proin faucibus fermentum mattis. Morbi at viverra massa. Donec ut eros nulla. Proin volutpat, lectus ac dapibus consequat, massa felis porttitor enim, id sollicitudin odio mi et libero.</p>
<p class="graytext">Phasellus ante sem-hendrerit fermentum </p>
<p class="clear">Duis consectetur enim felis. In hac habitasse platea dictumst. Nullam dignissim dignissim nulla, ut molestie est aliquam cursus. Ut vitae ultrices lacus. Duis a diam risus.<br />
Nullam interdum euismod nibh, ac dictum metus <br />
Maecenas pellentesque, diam at suscipit mollis, turpis masss<br />
Nulla facilisi. Praesent nisi ligula, eleifend eu egest <br />
Fusce leo mi, ultricies sed sollicitudin eu, pretium vel felis pretium vel<br />
</p>
</div>
</body>
</html>

I want to reduce gap as shown here …

You set the bottom margin of .graytext to zero, but you set a bottom margin of 19px for #rightbox p. The rule with the ID selector is more specific, so it will override the rule with the class selector.

You can add this to enforce the zero margin,

#rightbox p.graytext {margin-bottom:0}

#rightbox p{
	float:left;
	margin:-10px 0 19px 0;
	padding:0;
	clear:both;
	font-family:Arial;
	text-align:left;
	width:410px;
}

???

This will affect all the paragraph .

instead of modifying the existing css …can i append this only in the intended paragraph ?

I don’t want to modify but I am open to append or add to the CSS…because this CSS could be used elesewhere in the same page…so I just don’t want to modify …but I want to append a style only to the needed paragraph.

so, what can i do now ?

you are modifying the existing CSS…can you overwrite the CSS at the needed place ?

<p class="graytext" style="margin-bottom:0">...</p>

You could make a class and apply that to the paragraph you want to change:


#rightbox  p.puller {margin-top: -15px;}


<p class="graytext puller">Phasellus ante sem-hendrerit fermentum </p>
<p class="clear puller">Duis consectetur enim felis. In hac habitasse platea dictumst. Nullam dignissim dignissim nulla, ut molestie est aliquam cursus. Ut vitae ultrices lacus. Duis a diam risus.<br />
Nullam interdum euismod nibh, ac dictum metus <br />
Maecenas pellentesque, diam at suscipit mollis, turpis masss<br />
Nulla facilisi. Praesent nisi ligula, eleifend eu egest <br />
Fusce leo mi, ultricies sed sollicitudin eu, pretium vel felis pretium vel<br />
</p>

I wouldn’t go for inline styling unless it’s for testing purposes :slight_smile:

I took a look at your code and this is how I would develop your paragraphs of text.

It doesn’t require any negetive margins at all to make this work. I saw that you had </br> set to some of the paragraphs of text, all you would need to do is seperate those words with <p></p>element and set a padding to seperate the paragraphs of text being so close together.

Your markup wasn’t really making any sense at all. So, I recreated it. (Clear) should only be applied to floats. - http://reference.sitepoint.com/css/clear

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>
            Untitled Document
        </title>
        <style type="text/css">
* {
    margin: 0; /* CSS global reset */
    padding: 0; }
 
body {
    font-family: arial, sans-serif; /* Apply these styles to the body since you had them assigned to your rightbox anyways which is the container. */
    text-align: left;
    font-weight: bold;
    line-height: 1.3em; }
 
#right_box {
    width: 460px; /*Apply's styling to the rightbox element */ /*Set width */
    margin: 0 35px 0 0; /* margin-right:35px; I would apply long-hand styling because you only have one value applied to element */ }
 
.top_header { color: #003150; }
 
.rightbox_section_2 {
    color: #80766e; /* This styles the color of the text */
        </style>
    </head>
    <body>
        <div id="right_box">

            <h2 class="top_header">
                Lorem ipsum dolor sit amet
            </h2>
            <p class="rightbox_section_1">
                Proin faucibus fermentum mattis. Morbi at viverra massa. Donec ut eros nulla. Proin volutpat, lectus ac dapibus consequat, massa
                felis porttitor enim, id sollicitudin odio mi et libero.
            </p>
            <p class="rightbox_section_2">
                Phasellus ante sem-hendrerit fermentum
            </p>
            <p class="rightbox_section_3">

                Duis consectetur enim felis. In hac habitasse platea dictumst. Nullam dignissim dignissim nulla, ut molestie est aliquam cursus. Ut
                vitae ultrices lacus. Duis a diam risus.
                Nullam interdum euismod nibh, ac dictum metus
                Maecenas pellentesque, diam at suscipit mollis, turpis masss
                Nulla facilisi. Praesent nisi ligula, eleifend eu egest
                Fusce leo mi, ultricies sed sollicitudin eu, pretium vel felis pretium vel
            </p>
        </div>
    </body>
</html>

Here is your answer
p {margin:0; padding:0;}

Which will dump the default padding and margins.

EDIT actually, margin:0; works by itself. You have to realise that browsers apply a default margin and padding to paragraphs, and that is all you are seeing, and it shouldn’t take two threads to discover this.

Actually Dr John padding is not applied to paragraphs. Only margins.

cute solution :slight_smile:

This works …Thanks

How this works ? is it just saying that there is no margin from the paragraph beneath it ?

As I said above, you have two rules that affect the bottom margin of the ‘graytext’ paragraph:

.graytext{margin:0 0 0 45px}
#rightbox p{margin:0 0 19px 0}

The second one is more specific and will override the first one, so the paragraph gets a bottom margin of 19px.

Using a style attribute trumps the rules in the style sheet, so style="margin-bottom:0" forces the bottom margin to be zero for that particular element.

As others have noted above, this is not a good idea from a maintenance point of view, since you tie your presentation tightly to the markup. But as a temporary fix it’s okay. (Your CSS isn’t very maintenance friendly anyway, with presentational IDs and class names etc.)

The vertical distance between to adjacent elements is determined by the bottom margin/padding of the first element and the top margin/padding of the second element. Since all vertical paddings and top margins involved are already set to zero, we only have to worry about the bottom margin of the first of the two elements.

Interesting. Didn’t know that. I that documented somewhere?

What Ryan means (I hope!) is that contemporary browsers don’t use any padding for paragraphs in their user agent style sheets.

If you add padding declarations in your own CSS, it will, of course, apply even for paragraphs.

Yeah, i’m sure he means that. But i was wondering if the fact that they don’t use any padding for paragraphs in their UA sheets is documented.

It not something you should ever rely on, anyway. If it’s important (or even !important :)) to you to have full control over margins and padding, you must declare them explicitly.

It’s a part of my reset anyways :smiley:

That’s why there was an edit…

But best it in to check your particular browser, just in case. So setting both to zero is fail-safe.

Yes :). I meant unless it’s manually set then no paddings are applied. Dr JOhns statement implied regular <p> styles generated by the browser stylesheet

Once again, i dare to ask: is it documented somewhere that contemporary browsers don’t use any padding for paragraphs in their user agent style sheets? It’s the first time i ever heard that mentioning :smiley: