简体   繁体   English

如何显示 <p> 在一个 <div> 具有内联块显示属性的元素?

[英]How to display a <p> within a <div>element with the display property of inline-block?

This is what I am currently working on... 这就是我目前正在努力的...

它看起来像什么

 .scake_one { color: #cc3300; display: inline-block; } .scake_two { color: #cc3300; display: inline-block; } .scake_three { color: #cc3300; display: inline-block; } 
 <div class="scake_one"> <h1>CAKE ONE</h1> <p>Lorem ipsum etiam porttitor ultrices <br>tortor tempus vehicula.</p> </div> <div class="scake_two"> <h1>CAKE TWO</h1> <p>Lorem ipsum eu quisque velit <br>quam convallis massa tellus.</p> </div> <div class="scake_three"> <h1>CAKE THREE</h1> <p>Lorem ipsum sed mauris aenean <br>pretium pulvinar.</p> </div> 

I was able to use this property well with an other section that had < h1 > and < li > elements. 我能够将这个属性与其他具有< h1 >< li >元素的部分一起使用。 I was able to used inline-block because they are block level elements? 我能够使用内联块,因为它们是块级元素? I saw this info on the w3 site http://www.w3schools.com/htmL/html_blocks.asp I also saw that < div > tags are also block level elements. 我在w3网站上看到了这个信息http://www.w3schools.com/htmL/html_blocks.asp我还看到< div >标签也是块级元素。 I can't seem to understand why it isn't working. 我似乎无法理解为什么它不起作用。

Here you go! 干得好! You need float-left, and the width needs to tell it to take up a third of the screen. 你需要浮动左边,宽度需要告诉它占据屏幕的三分之一。

Also, just as a style thing, you can give all of your "scake" the same class name, because the CSS styling is the same for each one. 另外,作为一种风格的东西,你可以给你所有的“scake”相同的类名,因为CSS样式对于每一个都是相同的。 Then if you change the style on one, it'll update it for all of them. 然后,如果您更改一个样式,它将为所有这些更新它。

 .scake { color: #cc3300; display: inline-block; float: left; max-width: 32%; margin-left: .5%; margin-right: .5%; } 
 <div class="scake"> <h1>CAKE ONE</h1> <p>Lorem ipsum etiam porttitor ultrices <br>tortor tempus vehicula.</p> </div> <div class="scake"> <h1>CAKE TWO</h1> <p>Lorem ipsum eu quisque velit <br>quam convallis massa tellus.</p> </div> <div class="scake"> <h1>CAKE THREE</h1> <p>Lorem ipsum sed mauris aenean <br>pretium pulvinar.</p> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM