简体   繁体   English

为什么内联块以这种方式工作?

[英]Why does inline-block work that way?

I'm fairly new to html and css. 我是html和css的新手。 I need two h3 elements to be displayed in 1 line. 我需要在一行中显示两个h3元素。 I am trying to use display:inline-block , but it works unexpected way for me. 我试图使用display:inline-block ,但它对我来说意想不到的方式。 Here is fiddle example http://jsfiddle.net/4NrXF/31/ . 这是小提琴示例http://jsfiddle.net/4NrXF/31/ Here i provided 4 different options of using inline-block attribute. 在这里,我提供了4种使用内联块属性的不同选项。 I need text "Some text before" to be displayed on the first row, and text "Display text" on the second row. 我需要在第一行显示文本“之前的一些文本”,并在第二行显示文本“显示文本”。 As you see - first option generates only one row, and thats inappropriate for me. 如您所见 - 第一个选项只生成一行,这对我来说不合适。 I thought that 4 option will work correctly, but as you can see that doesnt generate "DISPLAY TEXT" row for some reason. 我认为4选项将正常工作,但正如您所看到的那样,由于某种原因不会生成“DISPLAY TEXT”行。 Why does inline-block work like this? 为什么内联块会像这样工作?
Here is html and css i use: 这是我用的html和css:

Some text before
<h3 class="a"> DISPLAY </h3>
<h3 class="a"> TEXT </h3>

<h3 > DISPLAY </h3>
<h3 > TEXT </h3>

<h3 class="a"> DISPLAY </h3>
<h3 > TEXT </h3>

text before
<h3 > DISPLAY </h3>
<h3 class="a"> TEXT </h3>

.a {display: inline-block}

The "text before" is an inline element. “之前的文本”是内联元素。 If you want it on its own row, you can use your option 4 with "text before" wrapped in a block element, like p 如果你想在它自己的行上,你可以使用你的选项4和“text before”包装在一个块元素中,比如p

<p>Some text before</p>
<h3 class="a"> DISPLAY </h3>
<h3 class="a"> TEXT </h3>

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

相关问题 为什么 margin-top 可以与 inline-block 一起使用,但不能与 inline 一起使用? - Why does margin-top work with inline-block but not with inline? 为什么“内联块”属性不适用于此页面? - Why does “inline-block” property wont work on this page? 为什么inline-block和max-width不能一起使用? - Why does inline-block and max-width not work together? 内联块div的对齐不起作用 - alignment of inline-block div does not work 为什么dir属性不能使用相同方向类型的内联文本但是对内联块文本有效? - Why does dir attribute not work inline text of same directional-type but works on inline-block text? 为什么内联块不能在此代码示例中内联元素? - Why does inline-block not render the elements inline in this code example? 为什么内联块元素的边距会影响同级内联块元素 - Why Does The Margin From An Inline-Block Element Affect A Sibling Inline-Block Element 为什么在溢出时使用内联块的工作方式有所不同:应用了hidden? - Why does inline-block work differently when overflow: hidden is applied? 为什么 flex-direction: row 仅在我将元素设置为 display: inline-block 时才起作用? - Why does flex-direction: row only work when I set the element to display: inline-block? 为什么“内联块”在这个CSS中不能正常工作? - Why “Inline-block” doesn't work properly in this CSS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM