更改可折叠头部的文本位置(Jquery移动可折叠)

时间:2021-06-20 20:14:44

I am creating a website for mobile devices using jQueryMobile. I have a simple Collapsible that looks like this:

我正在为使用jQueryMobile的移动设备创建一个网站。我有一个简单的可折叠的看起来像这样:

<div data-role="collapsible">
    <h3>Section</h3>
    <p>I am the Content how are you?</p>
</div>

I managed to change the height of the header but after changing it the Text of the Header is no longer align with the Collapsible Icon.

我成功地改变了标题的高度,但在更改后,标题的文本不再与可折叠的图标对齐。

Is there a way to change the HeaderText Position Horizontally so it aligns with the Icon?

是否有一种方法可以水平地改变HeaderText位置,使它与图标对齐?

Because i can change the Position Vertically using text-align: center

Here is the FIDDLE with what i have tried so far.

因为我可以使用文本对齐方式垂直改变位置:这里的中心是我迄今为止尝试过的东西。

1 个解决方案

#1


3  

You can use the line-height property to center the headline text vertically:

您可以使用行高度属性将标题文本垂直居中:

.ui-collapsible-inset .ui-collapsible-heading .ui-btn {
    line-height: 10vh;
}

If you set the line-height of an element the same as the elements height, than the text will be vertically centered. In this specific case this would be a good solution, because you only have one line of text (one word).

如果将元素的行高度设置为与元素高度相同,则文本将以垂直居中。在这个特定的情况下,这将是一个很好的解决方案,因为您只有一行文本(一个字)。

.ui-collapsible .ui-btn {
  height: 10vh !important;
}

.ui-collapsible-inset .ui-collapsible-heading .ui-btn {
  color: red !important;
  /*margin-top:100px !important;*/
  line-height: 10vh;
}

.ui-collapsible-heading .ui-btn .ui-btn-text {
  color: red !important;
  /*top: 10% !important;*/
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://jsfiddle.net/0p92aec2/1/%22https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>

<div data-role="page">
  <div data-role="content">
    <div data-role="collapsible">
      <h3>Section</h3>
      <p>I am the Content how are you?</p>
    </div>
  </div>
</div>

#1


3  

You can use the line-height property to center the headline text vertically:

您可以使用行高度属性将标题文本垂直居中:

.ui-collapsible-inset .ui-collapsible-heading .ui-btn {
    line-height: 10vh;
}

If you set the line-height of an element the same as the elements height, than the text will be vertically centered. In this specific case this would be a good solution, because you only have one line of text (one word).

如果将元素的行高度设置为与元素高度相同,则文本将以垂直居中。在这个特定的情况下,这将是一个很好的解决方案,因为您只有一行文本(一个字)。

.ui-collapsible .ui-btn {
  height: 10vh !important;
}

.ui-collapsible-inset .ui-collapsible-heading .ui-btn {
  color: red !important;
  /*margin-top:100px !important;*/
  line-height: 10vh;
}

.ui-collapsible-heading .ui-btn .ui-btn-text {
  color: red !important;
  /*top: 10% !important;*/
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://jsfiddle.net/0p92aec2/1/%22https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>

<div data-role="page">
  <div data-role="content">
    <div data-role="collapsible">
      <h3>Section</h3>
      <p>I am the Content how are you?</p>
    </div>
  </div>
</div>