css - HTML/CSS 文本移动 div

标签 css html

我刚刚在学习 CSS,我有一个汽车销售网站的元素,但我试图在一个 div 中定位文本,段落代码没问题,但是当我放入 H1 标签时,它会将整个 div 向下移动? (见下文)。

https://www.dropbox.com/s/px0zv5xw8vqpvpd/Screenshot%202014-03-12%2001.38.02.png

<div id="bottom">

<h1> Welcome to JJMurray Car Sales </h1>

<p class="hometext">
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>

和CSS:

#bottom{background-color:#d6d6d6;width:100%;height: 450px;

h1
{
text-align: left;
    margin-left: 20px;
    margin-right: 20px;
}

p.hometext
{
font-size: 14px;
font-family: calibri;
text-align:left;
  width: 600px;
    float: left;
    margin-left: 20px;
    margin-right: 20px;

最佳答案

heading标签默认占用一定的margin。 该默认边距使其周围出现空格。 所以,首先尝试给 h1 标签 margin:0; 然后,你可以看到它在默认情况下实际占用了多少空间。

因为它是 block 元素,您可以指定 maring: top left bottom right;

关于css - HTML/CSS 文本移动 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22340344/

相关文章:

html - :after element's content not taking background:inherit; in IE8

javascript - 悬停时从 Chart.js 中删除数据文本

html - R knitr - 用于小文本的 kable 表格 html 格式

.net - 在 .NET 中将 RTF 转换为 HTML

javascript - 选择选项 1 时禁用选项 2

javascript - 访问隐藏在 IFRAME 后面的元素

html - 我的 div 不会出现,但其他人会

html - Chrome - 网站底部的空白

javascript - 自定义 HTML 输入组件

javascript - 日期选择器的 ngMaterial 在 Angular JS 中不起作用