[英]How to change my code for making layout like a pictures in css
的HTML
<div id="header"><h1>Scott's Favorite Things</h1>
<div id="header2"><h2>Cars, Sports, and Music</h2></div>
</div>
的CSS
div#header{
border:5px;
border-color: red;
border-style: solid;
}
h1{
float:right;
clear: both;
}
div#header2 h2{
float: right;
clear: both;
}
div#header2{
border:5px;
border-color: orange;
border-style: solid;
margin: 5px;
}
在这里,我发布了指向我想要的东西的链接:
您必须通过CSS为每个div创建一个嵌套的HTML结构样式。
HTML:
<div class="main-wrapper">
<div class="head-wrapper">
Lorem Ipsum
<div class="small-head-wrapper">
Lorem Ipsum
</div>
</div>
<div class="content-wrapper">
Your Main Content
</div>
</div>
CSS:
.main-wrapper {
border: solid 5px green;
}
.main-wrapper .head-wrapper {
text-align: right;
border: solid 5px red;
padding: 5px;
}
.main-wrapper .head-wrapper .small-head-wrapper {
border: solid 5px orange;
}
.main-wrapper .content-wrapper {
border: solid 5px blue;
}
只需使用text-align: right
而不是float: right
并从h1
和h2
删除默认margin
。
看一下这段代码:
div#header { border: 5px; border-color: red; border-style: solid; } div#header h1 { /* Added header to h1 because I dont want to style every h1 */ text-align: right; /* Changed from float to text-align */ clear: both; margin: 0; /* remove the default margin */ } div#header2 h2 { text-align: right; /* Changed from float to text-align */ clear: both; margin: 0; /* remove the default margin */ } div#header2 { border: 5px; border-color: orange; border-style: solid; margin: 5px; }
<div id="header"> <h1>Scott's Favorite Things</h1> <div id="header2"> <h2>Cars, Sports, and Music</h2> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.