[英]HTML elements are contained to each other
I have a problem with some HTML elements. 我对某些HTML元素有疑问。 I have an image and a title in a <header>
tag - they should both move independently to each other, however when I move the img element down 40px with the margin-top attribute - the title seems to move down 40px with it. 我在<header>
标记中有图像和标题-它们应该彼此独立移动,但是当我使用margin-top属性将img元素下移40px时-标题似乎也随之下移40px。 So I add margin-top: -20px;
所以我添加margin-top: -20px;
to move it back up and it seems to stay put. 将其移回原处,并且似乎保持不变。
Here's my code: 这是我的代码:
The header file: 头文件:
<div class="page">
<header>
<div class="titlesec">
<img class="circular" src="themes/default/image.jpg" />
<a class="logo" href="<?php echo base_url(); ?>">
<?php echo site_name(); ?>
</a>
</div>
<div class="split"></div>
</header>
The footer file: 页脚文件:
<footer>
<p>© Copyright <?php date("Y"); ?> Duncan Hill</p>
</footer>
</div>
</body>
</html>
and my css: 和我的CSS:
.page {
width: 80%;
margin-left: 10%;
margin-right: 10%;
}
.logo {
font-family: 'Helvetica Neue';
font-weight: 100;
font-size: 56px;
text-decoration: none;
color: #555555;
margin-top: -20px;
}
.split {
height: 1px;
background-color: #CCCCCC;
}
.circular {
margin-top: 40px;
width: 80px;
height: 80px;
border-radius: 150px;
-webkit-border-radius: 150px;
-moz-border-radius: 150px;
}
.titlesec {
height: 150px;
}
Any help is appreciated immensely! 任何帮助,我们将不胜感激!
img
and a
are inline tags. img
和a
是内联标签。 Which means they are in the same line. 这意味着它们在同一行。 Adding margin-top manipulates this line, and affects therefore both of them. 添加margin-top会操纵这条线,因此会同时影响它们。
Depending on what you want to do, you could solve this with surounding both elements with their own div
. 根据您要执行的操作,可以通过用自己的div
包围两个元素来解决此问题。 Then you can style the divs independently. 然后,您可以独立设置div的样式。 Maybe a float on those divs comes in handy, too. 也许这些div上的浮动元素也会派上用场。
Close your "page" DIV. 关闭您的“页面” DIV。 It seems that your not properly closing your html tags. 看来您未正确关闭html标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.