1. <legend id='plygJ'><style id='plygJ'><dir id='plygJ'><q id='plygJ'></q></dir></style></legend>
      • <bdo id='plygJ'></bdo><ul id='plygJ'></ul>

    2. <tfoot id='plygJ'></tfoot>
      <i id='plygJ'><tr id='plygJ'><dt id='plygJ'><q id='plygJ'><span id='plygJ'><b id='plygJ'><form id='plygJ'><ins id='plygJ'></ins><ul id='plygJ'></ul><sub id='plygJ'></sub></form><legend id='plygJ'></legend><bdo id='plygJ'><pre id='plygJ'><center id='plygJ'></center></pre></bdo></b><th id='plygJ'></th></span></q></dt></tr></i><div id='plygJ'><tfoot id='plygJ'></tfoot><dl id='plygJ'><fieldset id='plygJ'></fieldset></dl></div>

      <small id='plygJ'></small><noframes id='plygJ'>

    3. CSS:扩展 &lt;div&gt;从右到左显示文字

      CSS: Expanding a lt;divgt; from right to left to reveal text(CSS:扩展 lt;divgt;从右到左显示文字)
        <bdo id='rYYn9'></bdo><ul id='rYYn9'></ul>
          <tbody id='rYYn9'></tbody>

            1. <i id='rYYn9'><tr id='rYYn9'><dt id='rYYn9'><q id='rYYn9'><span id='rYYn9'><b id='rYYn9'><form id='rYYn9'><ins id='rYYn9'></ins><ul id='rYYn9'></ul><sub id='rYYn9'></sub></form><legend id='rYYn9'></legend><bdo id='rYYn9'><pre id='rYYn9'><center id='rYYn9'></center></pre></bdo></b><th id='rYYn9'></th></span></q></dt></tr></i><div id='rYYn9'><tfoot id='rYYn9'></tfoot><dl id='rYYn9'><fieldset id='rYYn9'></fieldset></dl></div>
            2. <tfoot id='rYYn9'></tfoot>

                <legend id='rYYn9'><style id='rYYn9'><dir id='rYYn9'><q id='rYYn9'></q></dir></style></legend>

                <small id='rYYn9'></small><noframes id='rYYn9'>

                本文介绍了CSS:扩展 &lt;div&gt;从右到左显示文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想设置一个固定的<div>,包含一个图标,当鼠标悬停在上面时会从右向左展开(<div> 展开,而不是图标),在图标左侧显示一段文字.图标的位置保持不变.这是一个草图来帮助说明我想做的事情:

                I'd like to set up a fixed <div>, containing an icon, which expands from right to left when being hovered over (the <div> expands, not the icon), revealing a piece of text on the left side of the icon. The icon's position stays unchanged. Here's a sketch to help illustrate what I'd like to do:

                在悬停时更改 <div> 的大小没有问题,我只需添加一个宽度更大的类(包括为展开动画制作的过渡).但我在元素的定位上挣扎.我将图标和文本(在 <span> 内)放在单独的 <div> 中,并尝试使用 flex 安排所有内容.在展开/悬停状态下,事情看起来应该是这样,但是一旦 <div> 再次缩小,包含图标和文本的两个 div 会尝试共享剩余的小空间,因此图标被截断,文本被压扁.

                Changing the size of the <div> on hover is no issue, I simply add a class with a larger width (including a transition to animate the expansion). But I struggle with the positioning of the elements. I placed both the icon and the text (inside a <span>) in separate <div> and tried arranging everything using flex. In the expanded/hover state things look the way they should, but once the <div> shrinks down again, the two divs containing the icon and the text try sharing the little space that is left and hence the icon gets cut off and the text gets squished.

                如果有人能帮我弄清楚如何按照我想要的方式进行设置,我将不胜感激.

                Would appreciate if someone could help me figure out how set this up the way I'd like it to be.

                这是我到目前为止得到的一个 jsFiddle:Button-GrowOnHover

                Here's a jsFiddle of what I got so far: Button-GrowOnHover

                加上代码本身:

                $(document).ready(function() {
                  var button = $("#myButton");
                
                  button.mouseenter(function() {
                    $(this).addClass("grow");
                  });
                  button.mouseleave(function() {
                    $(this).removeClass("grow");
                  });
                });

                .button-container {
                  position: fixed;
                  top: 5%;
                  right: 5%;
                  width: 100px;
                  padding: 5px;
                  background-color: tomato;
                  display: flex;
                  justify-content: space-between;
                  overflow: hidden;
                  transition: width 1s;
                }
                
                .button-container.grow {
                  width: 300px
                }
                
                .button-text-container {
                  display: flex;
                  align-items: center;
                  justify-content: center;
                  background-color: lightblue;
                }
                
                .button-icon-container {
                  height: 100%;
                  display: flex;
                  align-items: center;
                  justify-content: center;
                }

                <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                <div class="button-container" id="myButton">
                
                  <div class="button-text-container">
                    <span>Here comes some text.</span>
                  </div>
                
                  <div class="button-icon-container">
                    <img src="https://placeholder.pics/svg/100x100/7AFFA6/000000/ICON">
                  </div>
                
                </div>

                推荐答案

                如果您依赖 flexbox order 并且您可以将宽度更改移动到文本而不是父容器:

                You can do this with only CSS if you rely on flexbox order and you can move the width changes to the text instead of the parent container:

                .button-container {
                  position: fixed;
                  top: 5%;
                  right: 5%;
                  padding: 5px;
                  background-color: tomato;
                  display: flex;
                  justify-content: space-between;
                  overflow: hidden;
                }
                
                
                .button-text-container {
                  order:-1;
                  display: flex;
                  align-items: center;
                  justify-content: center;
                  background-color: lightblue;
                  white-space:nowrap; /*Keep text always one line*/
                  overflow:hidden;
                  width:0;
                  transition: width 1s;
                }
                
                .button-icon-container {
                  height: 100%;
                  display: flex;
                  align-items: center;
                  justify-content: center;
                }
                .button-icon-container:hover + .button-text-container {
                  width:200px;
                }

                <div class="button-container" id="myButton">
                  <div class="button-icon-container">
                    <img src="https://placeholder.pics/svg/100x100/7AFFA6/000000/ICON">
                  </div>
                  
                  <div class="button-text-container">
                    <span>Here comes some text.</span>
                  </div>
                </div>

                这篇关于CSS:扩展 &lt;div&gt;从右到左显示文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Move link image 5px up on hover(悬停时将链接图像向上移动 5px)
                How do I inspect CSS pseudo classes with firebug?(如何使用 firebug 检查 CSS 伪类?)
                Why doesn#39;t CSS hover work on table rows when the cells inside the rows have class names?(当行内的单元格具有类名时,为什么 CSS 悬停在表格行上不起作用?)
                Hover image - display div over it(悬停图像 - 在其上显示 div)
                How to apply a CSS class on hover to dynamically generated submit buttons?(如何在悬停时将 CSS 类应用于动态生成的提交按钮?)
                Differences between CSS3 :hover and :focus?(CSS3 :hover 和 :focus 的区别?)
                  <tbody id='gatRg'></tbody>

                  • <bdo id='gatRg'></bdo><ul id='gatRg'></ul>

                    <small id='gatRg'></small><noframes id='gatRg'>

                    <legend id='gatRg'><style id='gatRg'><dir id='gatRg'><q id='gatRg'></q></dir></style></legend>
                      • <tfoot id='gatRg'></tfoot>

                        <i id='gatRg'><tr id='gatRg'><dt id='gatRg'><q id='gatRg'><span id='gatRg'><b id='gatRg'><form id='gatRg'><ins id='gatRg'></ins><ul id='gatRg'></ul><sub id='gatRg'></sub></form><legend id='gatRg'></legend><bdo id='gatRg'><pre id='gatRg'><center id='gatRg'></center></pre></bdo></b><th id='gatRg'></th></span></q></dt></tr></i><div id='gatRg'><tfoot id='gatRg'></tfoot><dl id='gatRg'><fieldset id='gatRg'></fieldset></dl></div>