如何删除div标签中的顶部空间

时间:2014-05-05 10:49:17

标签: css css3 margin padding

我在一个分区中放置标题文字。幸运的是,我在该文本上方获得了不必要的空间。当我试图增加文本的大小时,文本向下移动。所以在这里,我想增加我的文字大小,同时我想将其向上移动。是否可以移除顶部空间并向上移动?

我尝试过padding-top:负像素。但这没有用。

HTML:

<div class="stylish">
    <h1> keep you stylish </h1>
</div>

CSS:

.stylish{
    font-family:"Brush Script MT", cursive;
    font-size:1.3em;
}

4 个答案:

答案 0 :(得分:2)

您的问题不是div,而是<h1>标记。试试这个:

h1 {
    margin: 0px;
    padding: 0px;
}

您也可以尝试:

h1 {
    margin: 0;
    padding: 0;
}

答案 1 :(得分:1)

我建议在每个css的开始时重置css:

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

Source

答案 2 :(得分:1)

h1
{
    margin-top: 0px;
    padding-top: 0px;
}

或者你也可以试试这个

h1
{
    margin: 0px 0px 0px 0px;//top left bottom right
    padding: 0px 0px 0px 0px;
}

和.stylish必须有填充:0px;即;

.stylish
{
padding:0px;
}

<强>原因:

默认情况下,每个标记如<H1>,<P> ...带有最小边距和填充因此为了减少间隙,我们需要给出margin = 0px; padding = 0px external

有关边距和填充的更多信息,请参阅

http://www.htmldog.com/guides/css/beginner/margins/

http://webdesign.about.com/od/faqsandhelp/f/bl_faq5_7a.htm

http://html.net/tutorials/css/lesson10.php

答案 3 :(得分:0)

试试这个

.stylish
{
    margin: 0px;
    padding: 0px;
}

如果它不起作用,您可能还需要为其父元素设置边距和填充为零

但是对于你来说,白色空间是div父母的边缘..

所以将父母边距设置为0px;