div的CSS内联定位
我正在尝试创建一个分为 3 个 div 的标头 它们都将被设置为显示:inline-block 左侧标题部分将包含一个口号和一个徽标,但我不希望该口号出现在该处 徽标的右侧
问题是我的徽标 div 和我的口号 div 总是一个放在另一个的上面。
据我了解,内联元素将放置在最后一个内联元素旁边 在同一个块中,请注意 header-left div 的宽度为 250px,并且每个 子 div 的宽度为 100px,那么为什么它们不一个挨着一个放置呢?
我的标记:
<div id="header">
<div id="header-left">
<div id="logo" />
<div id="slogan">
<span> Buy For U</span>
</div>
</div>
</div>
我的CSS:
div#header
{
border: 1px solid black ;
height: 200px;
}
div#header div#header-left
{
display: inline-block;
height: 100%;
width: 250px;
}
div#header div#header-left div#logo
{
display: inline-block;
background: url("Google-Desktop-64.png") no-repeat center;
background-size: 25%;
height: inherit;
width: 100px;
}
div#header div#header-left div#slogan
{
display: inline-block;
height: inherit;
width:100px;
}
i'm attempting to create an header which is divided into 3 divs
they will all be set to display: inline-block
the left header part will contain a slogan and a logo which i wan't the slogan to be at
the right of the logo
the problem is my logo div and my slogan div are always placed one on top of the other .
to my understanding an inline element would be placed next to the last inline element
with in the same block , notice that the header-left div has 250px width and each of the
child div's have 100px width so why are they not placed one next to the other ?
my markup :
<div id="header">
<div id="header-left">
<div id="logo" />
<div id="slogan">
<span> Buy For U</span>
</div>
</div>
</div>
my css :
div#header
{
border: 1px solid black ;
height: 200px;
}
div#header div#header-left
{
display: inline-block;
height: 100%;
width: 250px;
}
div#header div#header-left div#logo
{
display: inline-block;
background: url("Google-Desktop-64.png") no-repeat center;
background-size: 25%;
height: inherit;
width: 100px;
}
div#header div#header-left div#slogan
{
display: inline-block;
height: inherit;
width:100px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一切都很好。只需正确关闭徽标的
即可。 “自动关闭”标签。
我还建议使用
作为徽标(并使其成为主页的链接),而不仅仅是背景。空的
标签在验证过程中很容易出错。
everything's fine. just close the logo's
<div>
properly. "self-closing" tags.i also suggest using an
<img>
for the logo (and make it a link to homepage) rather than just a background. empty<div>
tags are prone to errors during validation.奇怪的是,您的 #header 的宽度为 200 像素,子 #header-left 的宽度为 250 像素,但除此之外,我认为最好使用浮动。这意味着两个 div 彼此相邻:
并且您需要在 html/css 中明确:
以及 html:
It is stange that your #header has a width of 200 pixels and the child #header-left 250 pixels, but apart from that I think it's better to use a float. This means that the two divs are next to each other:
And you nead a clear in your html/css:
And the html: