我试图在第四个div中对齐三个div,以创建类似于您在这个页面上看到的内容:http://www.thedistillerydistrict.com/。
我似乎不能让里面的div (#娱乐,#社区,#欢迎)在#HomeMain div内并排排列
这是html中的
<div id = "HomeMain">
<div id="welcome">
<p>Finest Booze around, come taste for yourself Home to many of Toronto's hottest designer boutiques, unique cafes, artisan shops, breathtaking art galleries, performance venues and award-winning restaurants, The Distillery District is the place to see and be seen. An internationally acclaimed pedestrian-only village, The Distillery features more than 70 ground-floor cultural and retail establishments in the restored red brick, Victorian-era buildings of the renowned Gooderham & Worts whiskey distillery. One of Canada's hottest tourist attractions, centrally-located and just a short walk from downtown Toronto there is always something happening at The Distillery.</p>
<div class = "Oldman"></div>
</div>
<div id = "Entertainment">
<img src="images/Entertainment1.jpg" id="EntSlide" width=125 height=70 />
</div>
<div id = "Community">
<img src="images/Victoria1.jpg" id="ComSlide" width=125 height=70 />
</div>
</div>这是CSS
#HomeMain{
width: 100%;
float: left;
overflow:hidden;
margin:0 auto;
padding:5px;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px 5px 5px 5px;
}
#Entertainment #Community{
float: left;
width: 25%;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px 5px 5px 5px;
}
#welcome{
float: left;
width:50%;
position: relative;
border-style: groove;
border-width: 3px;
border-color: white;
border-radius: 5px 5px 5px 5px;
font-weight: bold;
padding:15px;
}发布于 2014-10-15 18:43:06
检查这个小提琴链接http://jsfiddle.net/hek7fLy2/
我所做的就是使用方框大小的css属性来实现所需的结果。另外,我假设你想让2个较小的div中的图像居中,所以这就解决了这个问题。
我没有更改您的HTML代码,但是我只调整了一点css代码,包括错误..。
#HomeMain{
width: 100%;
float: left;
overflow:hidden;
margin:0 auto;
padding:5px;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px 5px 5px 5px;
box-sizing:border-box;
}
#Entertainment, #Community{
float: left;
width: 25%;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px 5px 5px 5px;
box-sizing:border-box;
}
#welcome{
float: left;
width:50%;
position: relative;
border-style: groove;
border-width: 3px;
border-color: white;
border-radius: 5px 5px 5px 5px;
font-weight: bold;
padding:15px;
box-sizing:border-box;
}
img{
display:block;
margin: 0 auto;
}发布于 2014-10-15 18:34:05
检查这个小提琴
首先应该是
#Entertainment,#Community{而不是
#Entertainment #Community{接下来,您的div不对齐是因为您为3 div指定了3px的边框,这使得div跳到下一个line.So,这里我对每个div都使用了box-sizing: border-box属性。
试试..。
发布于 2014-10-15 18:37:28
您忘记了第二条规则中的逗号,为了使其正确,您必须使用box-sizing: border-box;。
#HomeMain {
width: 100%;
float: left;
overflow: hidden;
margin: 0 auto;
padding: 5px;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px;
box-sizing: border-box;
}
#Entertainment,
#Community {
float: left;
width: 25%;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px;
box-sizing: border-box
}
#welcome {
float: left;
width: 50%;
position: relative;
border-style: groove;
border-width: 3px;
border-color: white;
border-radius: 5px;
font-weight: bold;
padding: 15px;
box-sizing: border-box
}<div id="HomeMain">
<div id="welcome">
<p>
Finest Booze around...
</p>
<div class="Oldman"></div>
</div>
<div id="Entertainment">
<img src="http://dummyimage.com/125x70" id="EntSlide">
</div>
<div id="Community">
<img src="http://dummyimage.com/125x70" id="ComSlide">
</div>
</div>
https://stackoverflow.com/questions/26389516
复制相似问题