Html 对齐问题-相互下方的块

Html 对齐问题-相互下方的块,html,css,Html,Css,你知道如何强制我的H1文本被放置在蓝色类别按钮下面吗?现在它就在它旁边。非常感谢 在你的航向左边划出一条直线,应该可以 #article h1 { font-size: 33px; color:#555; font-style:italic; clear:left; } 请参见您应该清除:两者都是。另一种方法是创建一个clear:tware,但此实例中不需要这样做 演示: 创建一个清除:两个div将其置于h1元素和浮动元素之间,在本例中为.category

你知道如何强制我的H1文本被放置在蓝色类别按钮下面吗?现在它就在它旁边。非常感谢


在你的航向左边划出一条直线,应该可以

#article h1 {
    font-size: 33px;
    color:#555;
    font-style:italic;
    clear:left;
}

请参见您应该
清除:两者都是。另一种方法是创建一个
clear:tware
,但此实例中不需要这样做

演示:

创建一个
清除:两个
div
将其置于
h1
元素和浮动元素之间,在本例中为
.category

这对于插入需要清除元素的位置很有帮助,直接清除元素是不合适的。

编辑类别。类别来自:

.category {
float: left;  /* REMOVE */
text-align: center;
font-size: 12px;
color: white;
padding: 8px 18px;
margin: 18px 0 0 0px;
text-decoration: none;
-webkit-transition: background 0.3s ease;
-moz-transition: background 0.3s ease;
-ms-transition: background 0.3s ease;
-o-transition: background 0.3s ease;
transition: background 0.3s ease;
background: rgba(71, 186, 255, 0.8);
}


一个简单的解决方案是在你的分类按钮后添加一个

元素。但这不是很优雅。如果类别需要超过70px怎么办?为类别设置所需的最大宽度。Es 200px
#article h1 {
    font-size: 33px;
    color:#555;
    font-style:italic;
    clear:left;
}
h1 
{
    clear:both;
}
.category {
float: left;  /* REMOVE */
text-align: center;
font-size: 12px;
color: white;
padding: 8px 18px;
margin: 18px 0 0 0px;
text-decoration: none;
-webkit-transition: background 0.3s ease;
-moz-transition: background 0.3s ease;
-ms-transition: background 0.3s ease;
-o-transition: background 0.3s ease;
transition: background 0.3s ease;
background: rgba(71, 186, 255, 0.8);
}
.category {
max-width:70px; /* EDITED */
text-align: center;
font-size: 12px;
color: white;
padding: 8px 18px;
margin: 18px 0 0 0px;
text-decoration: none;
-webkit-transition: background 0.3s ease;
-moz-transition: background 0.3s ease;
-ms-transition: background 0.3s ease;
-o-transition: background 0.3s ease;
transition: background 0.3s ease;
background: rgba(71, 186, 255, 0.8);
}