- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 css,如您所见,它可以工作,但是当文本长度不同时,事情会变得很奇怪:
这是我正在使用的 CSS:
.block-with-text {
/* hide text if it more than N lines */
overflow: hidden;
/* for set '...' in absolute position */
position: relative;
/* use this value to count block height */
line-height: 1.2em;
/* max-height = line-height (1.2) * lines max number (3) */
max-height: 3.6em;
/* fix problem when last visible word doesn't adjoin right side */
text-align: justify;
/* place for '...' */
margin-right: -1em;
padding-right: 1em;
}
和我的html
<div class="row">
<div class="padding">
<img src="img/san-francisco.jpg" style="width: 80px; height: 80px; border-radius:5px;" alt="" />
</div>
<div class="">
<div class="news-header block-with-text">
<h2>{{new.title}}</h2>
</div>
<div class="news-summary block-with-text">
<p>
{{new.summary}}
</p>
</div>
<div class="row news-footer">
<div>
{{new.tags[0]}}
</div>
<div>
{{new.source}}
</div>
</div>
</div>
</div>
如果标题为 3 行,我想将底部文本限制为 2 行文本,如果标题为 2,我想将其设置为 3 行,关于如何实现这一点有什么想法吗?
最佳答案
I want to make the bottom text limit to 2 lines of text if header is 3 lines, if header is 2 I want to have it 3 lines
编辑这个答案以添加在特定情况下——标题和正文具有相同的行高——这可以在纯 CSS 中完成,方法是将标题和正文文本包装在一个五行高的框中,用 溢出:隐藏
:
.row {
width: 300px;
line-height: 20px;
height: 100px;
overflow:hidden;
border: 1px solid
}
.news-header {
font-weight: bold
}
<div class="row">
<div class="news-header">This head will be two lines long. This head will be two lines long.</div>
<div class="news-summary">body text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body text</div>
</div>
<div class="row">
<div class="news-header">This head will be three lines long. This head will be three lines long. This head will be three lines long.</div>
<div class="news-summary">body text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body text</div>
</div>
这不适合大多数布局;任何更复杂的东西都会让你离开纯 CSS 领域并进入 javascript。我不推荐这样做,它很脆弱,可能需要重新设计,但是:
// depending on jQuery here, obviously. Put this somewhere that it will run after the regular DOM layout has completed.
$('.news-header').each(function() {
var LINEHEIGHT=22; // in px. Adjust as needed to match your css
if ($(this).height() === (LINEHEIGHT*2)) {
$(this).next('.news-summary').height(LINEHEIGHT*3);
} else {
$(this).next('.news-summary').height(LINEHEIGHT*2);
};
// note conspicuous failure to handle 4-line, 1-line, etc headers
});
.row {
width: 300px;
line-height: 22px;
border: 1px solid;
}
.news-header {font-weight: bold;}
.news-summary {overflow: hidden;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="news-header">This head will be two lines long. This head will be two lines long.</div>
<div class="news-summary">body text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body text</div>
</div>
<div class="row">
<div class="news-header">This head will be three lines long. This head will be three lines long. This head will be three lines long.</div>
<div class="news-summary">body text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body textbody text body text</div>
</div>
思路是让标题正常布局,测量它的高度,然后以此为基础设置正文的高度。仅当您为标题和正文都设置了行高时,这才有效——此处两者的行高不必相同,但您需要在计算中考虑两者之间的任何差异.
关于html - 如何使用CSS动态分配文本 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36200100/
我的 blockly.js 文件中有以下代码 Blockly.Blocks['account_number'] = { // Other type. init: function() {
首先抱歉我的英语不好,我正在开发 Image Splitter 应用程序并且已经完成,但是现在的要求是当图像被分割(分成几 block /chunks)那么图像 block 的每一 block (ch
#value: 消息的返回值,当发送到一个 block 时,是该 block 中最后一句话的值。所以 [ 1 + 2. 3 + 4. ] value 计算结果为 7。我发现有时很难使用。有没有办法显式
我想构建一个包含 3 div 的响应式导航栏相同的 width和 height . 我申请了 inline-block到每个 block ,我得到一个我不理解的行为。 问题是,第三 block 由 2
我希望使用 Blockly 来允许非技术人员用户指定测试脚本。 它的一部分需要一个文件选择器,但是,我看不到 Blockly 有一个。是吗? 实际上,我找不到完整的标准 block 列表。谁有网址?
仅当您位于父 block 内部时,父 block 的 props.isSelected 才为 true,但当您在该 block 的 innerBlocks 内进行编辑时则不然。 如何从父 block
仅当您位于父 block 内部时,父 block 的 props.isSelected 才为 true,但当您在该 block 的 innerBlocks 内进行编辑时则不然。 如何从父 block
我想创建一个具有不同背景颜色 block 和不同悬停颜色 block 的导航栏 block 。我可以分别创建不同的悬停颜色 block 或不同的背景颜色 block ,但不能一起创建。所以请告诉我如何
我正在使用看到的代码 here定期执行代码: #define DELAY_IN_MS 1000 __block dispatch_time_t next = dispatch_time(DISPATC
为什么 block 必须被复制而不是保留?两者在引擎盖下有什么区别?在什么情况下不需要复制 block (如果有)? 最佳答案 通常,当您分配一个类的实例时,它会进入堆并一直存在,直到它被释放。但是,
我想弄清楚我这样做是否正确: 如果我有一个 block ,我会这样做: __weak MyClass *weakSelf = self; [self performBlock:^{
我想制作一个 4 block 导航菜单,虽然我已经显示了一个 block ,然后单击打开第二个 block ,从第二个开始选择并再次单击出现第三个 block ,第四个 block 相同...这是我的
例如,这样更好吗? try { synchronized (bean) { // Write something } } catch (Int
我想让一只乌龟检查前方小块的颜色并决定移动到哪里。如果前面的补丁不是白色的,那么乌龟向左或向右旋转并移动。我的 If 决策结构中出现错误,显示“此处应为 TRUE?FALSE,而不是 block 列表
我想创建一个 block 对角矩阵,其中对角 block 重复一定次数,非对角 block 都是零矩阵。例如,假设我们从一个矩阵开始: > diag.matrix [,1] [,2] [
我是区 block 链新手。突然我有一个问题,我们是否可以通过区 block 号来访问以太坊区 block 链上之前的区 block 数据。 例如我创建了一个block1、block2。 block
我是区 block 链新手。突然我有一个问题,我们是否可以通过区 block 号来访问以太坊区 block 链上之前的区 block 数据。 例如我创建了一个block1、block2。 block
我创建了一个等距环境,全部使用 Javascript 和 HTML5 (2D Canvas),大部分情况下工作正常。我面临的问题是使用不同高度的图 block ,然后对图 block 上的对象索引进行
这是令我困惑的代码: public Integer getInteger(BlockingQueue queue) { boolean interrupted = false; try
我有一个基于 TPL 数据流的应用程序,它仅使用批处理 block 和操作 block 就可以正常工作。 我已经添加了一个 TransformBlock 以尝试在发布到批处理 block 之前从源中转
我是一名优秀的程序员,十分优秀!