简体   繁体   English

内联(非内联块)行为元素的最小宽度

[英]min-width on inline (not inline-block) behaving element

I would like to set the min-width on a contenteditable div with some other elements next to it that must stay inline with the div. 我想在一个contenteditable div上设置min-width,旁边有一些其他元素必须与div保持内联。

Every solution I've seen uses inline-block, but I can't use inline-block behavior. 我见过的每个解决方案都使用内联块,但我不能使用内联块行为。 When inline-block starts wrapping, it still behaves like a block element, and I need the div to behave as an inline element. 当内联块开始包装时,它仍然表现得像块元素,我需要div表现为内联元素。 I would imagine the solution would require more than just CSS, but it seems very difficult to set any event for when the div's text changes. 我认为解决方案需要的不仅仅是CSS,但是当div的文本发生变化时,似乎很难设置任何事件。 A solution involving javascript and/or jQuery would be welcome. 欢迎使用涉及javascript和/或jQuery的解决方案。

EDIT: Here's a simplified version of what I'm trying to do. 编辑:这是我正在尝试做的简化版本。 If the user would type more text than the page is wide, there is a difference in behavior between inline-block and block, and that's what I am concerned with. 如果用户输入的文本多于页面宽度,则内联块和块之间的行为会有所不同,这就是我所关注的。

<style type="text/css">
label {
    width: 40px;
    height: 40px;
}
#container {
    font-size: 32px;
}
#content {
    display: inline;
    min-height: 37px; /* doesn't work on inline elements */
    min-width: 80px; /* also doesn't work on inline elements */
}
</style>

<div id="container">
    <input type="radio" />
    <label>
        <span></span>
    </label>
    <span>(A)</span>
    <div id="content" contenteditable="true" unselectable="off">test</div>
</div>

Okay, here's the answer I came up with (in jQuery). 好的,这是我提出的答案(在jQuery中)。 Can anyone give me suggestions on leaving out some of these events that might not change the div's content or place a border around the div? 任何人都可以给我一些关于遗漏一些可能不会改变div内容或在div周围放置边框的事件的建议吗? (I'm also concerned with cut/paste). (我也关注剪切/粘贴)。

$('#content').bind('blur focus load resize scroll click dblclick ' +
        'mousedown mouseup mousemove change ' +
        'select keydown keypress keyup', function () {
    if($(this).width() <= 80) {
        $(this).css("display", "inline-block");
    }
    else {
        $(this).css("display", "inline");
    }
})

Now used to floating 现在习惯floating

as like this 像这样

a{
background:green;
  min-height:200px;
  float:left;
}

live demo http://tinkerbin.com/3Ho3Af9c 现场演示http://tinkerbin.com/3Ho3Af9c

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

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