简体   繁体   English

如何将xul元素倾斜到可变大小的居中元素的右侧?

[英]How do I lean a xul element to the right side of a variably sized centered element?

<edit>I decided to clean this question up a little bit, for easier reading.</edit> <edit>我决定稍微清理一下这个问题,以便于阅读。</ edit>

I have a centered <menulist> , of variable width ( maxwidth="200" ), next to which I want to lean a couple of <toolbarbuttons> in an <hbox> . 我有一个居中的<menulist> ,可变宽度( maxwidth="200" ),旁边我想在<hbox>中使用几个<toolbarbuttons> <hbox> These elements are part of a xul <page> element. 这些元素是xul <page>元素的一部分。

The following image shows what my current result is and what my actual goal is: 下图显示了我当前的结果以及我的实际目标:

目前的结果和目标

The vertical red line is merely drawn to indicate the center of the window. 仅绘制垂直红线以指示窗口的中心。

The current result was achieved with the following css and xul: 目前的结果是通过以下css和xul实现的:

css: CSS:

page {
  -moz-appearance: none;
  background-color: #fff;
  text-align: center;
}

toolbarbutton {
  list-style-image: url( 'chrome://codifiertest/skin/icons.png' );
}
toolbarbutton .toolbarbutton-icon {
  width: 16px;
  height: 16px;
}

toolbarbutton.add {
  -moz-image-region: rect( 0px, 16px, 16px, 0px );
}

toolbarbutton.edit {
  -moz-image-region: rect( 0px, 32px, 16px, 16px );
}

toolbarbutton.delete {
  -moz-image-region: rect( 0px, 48px, 16px, 32px );
}

toolbarbutton.config {
  -moz-image-region: rect( 0px, 64px, 16px, 48px );
}

xul: XUL:

<?xml version="1.0" encoding="utf-8"?>

<?xml-stylesheet type="text/css" href="chrome://global/skin/"?>
<?xml-stylesheet type="text/css" href="chrome://codifiertest/skin/index.css"?>

<!DOCTYPE page>

<page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      xmlns:html="http://www.w3.org/1999/xhtml">

  <div xmlns="http://www.w3.org/1999/xhtml">

    <h1>Title</h1>

    <vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
          pack="start"
          align="center">

      <stack maxwidth="200">
        <hbox pack="center" align="center">
          <menulist maxwidth="200">
            <menupopup>
              <menuitem label="Item" value=""/>
            </menupopup>
          </menulist>
        </hbox>
        <hbox left="200">
          <toolbarbutton class="add"/>
          <toolbarbutton class="edit"/>
          <toolbarbutton class="delete"/>
        </hbox>
      </stack>

    </vbox>

  </div>

</page>

icons.png: icons.png:

使用过的图标


You can also download this as an installable bootstrapped test example: 您也可以将其下载为可安装的自举测试示例:

http://extensions.codifier.nl/test/downloads/test@extensions.codifier.nl.xpi http://extensions.codifier.nl/test/downloads/test@extensions.codifier.nl.xpi

Be aware that the example xpi install will immediately open a new tab with the example xul file after install. 请注意,示例xpi install将在安装后立即打开带有示例xul文件的新选项卡。 And as a disclaimer : the file is downloadable from an insecure location (my own domain), so be sure you validate what you downloaded before you install (ie save the xpi to disk first, before installing). 作为免责声明 :该文件可从不安全的位置(我自己的域)下载,因此请确保在安装之前验证下载的内容(即在安装之前先将xpi保存到磁盘)。


So, the goal is to always have the <menulist> horizontally centered to the page and the <hbox> with <toolbarbutton> s lean to right side of the <menulist> , no matter its width. 所以,我们的目标是总有<menulist>水平居中的页面和<hbox><toolbarbutton>精益到右侧<menulist> ,不管它的宽度。

Is this doable with xul and perhaps some additional css? 这可以用xul和一些额外的CSS吗?

I've actually gotten it to work by mixing in more (x)html: 我实际上通过混合使用更多(x)html来实现它:

css: CSS:

#container {
  position: relative;
}

#container > span {
  position: absolute;
  left: 100%;
}

altered xul/(x)html: 改变xul /(x)html:

<html:div id="container"> <!-- no more xul:stack -->
  <hbox pack="center" align="center">
    <menulist maxwidth="200">
      <menupopup>
        <menuitem label="Item" value=""/>
      </menupopup>
    </menulist>
  </hbox>
  <html:span> <!-- additional span -->
    <hbox>
      <toolbarbutton class="add"/>
      <toolbarbutton class="edit"/>
      <toolbarbutton class="delete"/>
    </hbox>
  </html:span>
</html:div>

... but I'd really rather want to see a pure xul solution though, if anyone knows one. ...但我真的很想看到一个纯xul的解决方案,如果有人知道的话。

Thank you, in advance, for looking into this. 提前谢谢您对此进行调查。

I think this should be the solution: 我认为这应该是解决方案:

page.xul page.xul

<?xml-stylesheet type="text/css" href="page.css"?>
<!DOCTYPE page>
<page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      xmlns:html="http://www.w3.org/1999/xhtml">
    <vbox>
        <hbox>
            <hbox>
                <menulist>
                    <menupopup>
                        <menuitem label="Item" value=""/>
                    </menupopup>
                </menulist>
            </hbox>
            <hbox>
                <button class="add"/>
                <button class="edit"/>
                <button class="delete"/>
            </hbox>
        </hbox>
        <hbox>
            <hbox>
                <menulist>
                    <menupopup>
                        <menuitem label="Item" value=""/>
                    </menupopup>
                </menulist>
            </hbox>
            <hbox>
                <button class="add"/>
                <button class="edit"/>
                <button class="delete"/>
            </hbox>
        </hbox>
    </vbox>
</page>

page.css: page.css:

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
page {
    -moz-appearance: none;
    background-color: #fff;
    text-align: center;
    background-image: url( 'dot.png' );
    background-position: top center;
    background-repeat: repeat-y;
}
page > vbox {
    -moz-box-flex: 1;
}
page > vbox {
    padding-left: 90px;
    -moz-box-align: center;
    -moz-box-pack: start;
}
.buttonsgroup {
    -moz-appearance: toolbox;
}
button {
    -moz-appearance: toolbarbutton;
    list-style-image: url( 'icons.png' );
    min-width: 27px !important; 
    width: 27px;
    height: 16px;
    margin: 0px 0px 0px 0px;
}
button.add {
  -moz-image-region: rect( 0px, 16px, 16px, 0px );
}
button.edit {
  -moz-image-region: rect( 0px, 32px, 16px, 16px );
}
button.delete {
  -moz-image-region: rect( 0px, 48px, 16px, 32px );
}
button.config {
  -moz-image-region: rect( 0px, 64px, 16px, 48px );
}

Here is how it looks (on FF 36, Kubuntu 15.04): 这是它的外观(在FF 36,Kubuntu 15.04):

在此输入图像描述

Hope that helps. 希望有所帮助。

There should be an answer that states the actual solution to the problem rather than it only being in the comments. 应该有一个答案说明问题的实际解决方案,而不仅仅是在评论中。 This answer is based on information from Ondřej Doněk's .xpi which was placed as downloadable in a comment to the answer that user provided . 这个答案是基于来自OndřejDoněk的.xpi信息,该信息可以在评论中下载到用户提供的答案中

The easy solution: 简单的解决方案:
All you have to do to make the original code work is change: 要使原始代码正常工作,您需要做的就是改变:

<hbox left="200">

to

<hbox right="-66">

MDN says that for elements immediately within XUL <stack> elements, the attribute right : MDN说对于XUL <stack>元素中的元素,属性right

specifies the pixel position of the right edge of the element relative to the right edge of the stack. 指定元素右边缘相对于堆栈右边缘的像素位置。

Based on the fact that using a negative number such as right="-66" works, we can deduce that what it is actually telling the stack to do is: enlarge such that the right edge of the <stack> is 66 pixels to the right of where it was and place the element with its right edge at the right edge of the stack. 基于使用诸如right="-66"类的负数的事实,我们可以推断它实际上告诉堆栈要做的是:放大使得<stack>的右边缘是66像素到右边的位置,将元素的右边缘放在堆叠的右边缘。

If Ondřej Doněk's answer is updated to include information about using a negative number for the right attribute, then this community wiki answer can be deleted. 如果更新了OndřejDoněk的答案以包含有关对right属性使用负数的信息,则可以删除此社区维基答案。

Your CSS looks good. 你的CSS看起来不错。 You can solve this with pure attributes of XUL. 你可以用XUL的纯属性来解决这个问题。 You can use: pack, orient, align, flex ... 你可以使用: pack, orient, align, flex ...

Try play with the xul-periodic-table example: 尝试使用xul-periodic-table示例:

https://github.com/alijc/xul-periodic-table/blob/master/layout.xul https://github.com/alijc/xul-periodic-table/blob/master/layout.xul

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

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