在卡片内,我有一个堆栈,其中包含 1)图像和 2)容器内的文本。如何使容器宽度与卡片宽度一致?
Card(
clipBehavior: Clip.antiAlias,
child: Stack(
children: <Widget>[
Positioned.fill(child: Image.network(
image_url,
fit: BoxFit.fitWidth,
),
),
Positioned(
bottom: 0,
child: Container(
padding: new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
decoration: new BoxDecoration(color: Colors.black12),
child: Row(
children: <Widget>[
Text("test1"),
Text("test2"),
Text("test3"),
],
),
),
),
],
)
);
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建一个“事件”小部件,该小部件由排列在列中的两个文本小部件组成。事件小部件的宽度由第一个文本小部件(标题)确定。第二个文本(详细信息)应受标题宽度的限制并换行到下一行。这就是我想要的: https: //i.stack.imgur.com/0bbNr.png
我尝试过这种布局,但列的宽度设置为详细文本的宽度(最大的子项)
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text("Title"),
Text("Some longer text that should wrap")
]
)
Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个全宽度DataTable,Flutter左侧有一个固定宽度的列,另外两列应该将剩余的列分开。
但是,即使左侧标题文本被截断,中间列和右侧列也不会占用剩余宽度,如下所示:
当文本太宽而无法在单行中显示时,我还想将文本换行到单元格中,但Wrap无法按预期工作。
我该如何解决我的问题?
这是代码:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Column(children: [
Expanded(
child: Container(
constraints: BoxConstraints.expand(width: double.infinity),
child: SingleChildScrollView(
child: DataTable(
headingRowHeight: 32,
dataRowHeight: 24,
columns: [
DataColumn(
label: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: 20,
minWidth: 20,
),
child: Text('Short column'),
),
),
DataColumn(label: Text('Long column')),
DataColumn(label: Text('Long column')),
],
rows: [
DataRow(
cells: [ …Run Code Online (Sandbox Code Playgroud) 我正在编写一个 C# 程序,并使用固定宽度的字体来显示所有内容。在这种字体下,每个 Unicode 字符要么占用 1 个字符宽度,要么占用 2 个字符宽度。程序中有一个功能,需要判断某个字符占用1个字符宽度还是2个字符宽度。首先我使用正则表达式[^\\x00-\\xFF]来解决问题。如果有字符匹配,则占用1个字符宽度,否则占用2个字符宽度。但后来我发现这是不正确的。例如,这些字符\xe2\x94\x8c\xe2\x94\x80\xe2\x94\xac\xe2\x94\x90\xe2\x94\x82\xe2\x94\x9c\xe2\x94\xbc\xe2\x94\xa4\xe2\x94\xb4\xe2\x94\x98不在 的范围内[^\\x00-\\xFF],但它们都只占用 1 个字符宽度。我想知道在C#中如何确定使用定宽字体时特定字符占用1个字符宽度还是2个字符宽度?
我有兴趣查询浏览器中 DOM 元素可能增长到的最大大小。众所周知,空 DOM 元素(没有样式)的 .clientWidth 为 0,但添加文本/图像/等。元素可能会导致其宽度增加。thisOne以下面结构中的DOM 元素为例:
<table style="padding: 20px; border-spacing: 100px">
<tr>
<td></td>
<td>
<div id="thisOne"></div>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
目前#thisOne.clientWidth === 0,但如果我向其附加大量文本,它的宽度会不断增大,但直到它达到为止,document.body.clientWidth因为列、填充类等。我想知道如何计算出对象的当前最大宽度不做类似的事情:
const thisOne = document.getElementById('thisOne');
thisOne.style.visibility = 'hidden'; // do not display to user.
thisOne.innerHTML = 'blah '.repeat(2000);
const maxWidth = thisOne.clientWidth;
thisOne.innerHTML = '';
thisOne.style.visibility = 'visible';
Run Code Online (Sandbox Code Playgroud)
基于 JQuery 的答案很好,但了解纯 HTML/JS 版本会更好。
(如果有人想知道,我计划将音乐符号的 SVG 放入 div 中,但我希望通过在添加之前为渲染器提供适合的宽度,使其能够很好地包裹到其他行上)
我想设置我的宽度longtable,使其适合页面而不是裁剪掉。我有 206 列和 17 行。
我使用tablesgenerator.com 来获取我的longtable,但选项“将表格缩放到文本宽度”不适用于longtable,需要一些帮助。(这里是乳胶初学者)。
\documentclass{article}
\usepackage{longtable}
\usepackage{booktabs}
\begin{document}
\begin{longtable}{@{}lllllllllllllllll@{}}
\toprule
\textbf{SN} & \textbf{zhelio} & \textbf{zhelio\_un} & \textbf{zCMB} &
\textbf{zCMB\_un} & \textbf{Peak\_MJD} & \textbf{Peak\_MJD\_un} & \textbf{x1}
& \textbf{x1\_un} & \textbf{c} & \textbf{c\_un} & \textbf{mB} &
\textbf{mB\_un} & \textbf{t} & \textbf{t\_un} & \textbf{Host\_logmass} &
\textbf{Host\_logmass\_un} \\* \midrule
\endhead
%table stuff here...
\caption{}
\label{tab:my-table}\\
\end{longtable}
\end{document}
Run Code Online (Sandbox Code Playgroud)
这就是它的样子
Bottom_sheet_image_dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:behavior_hideable="false"
app:behavior_peekHeight="62dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/llAddDriverPic"
android:background="?android:attr/selectableItemBackground"
android:padding="8dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/baseline_add_photo_alternate_24"
android:layout_margin="8dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/add_picture"
android:layout_gravity="center_vertical"
android:padding="8dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/llRemoveDriverPic"
android:background="?android:attr/selectableItemBackground"
android:padding="8dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/baseline_no_photography_24"
android:layout_margin="8dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/remove_picture"
android:layout_gravity="center_vertical"
android:padding="8dp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
代码实现:
BottomSheetDialog bsDialog = new BottomSheetDialog(getContext());
bsDialog.setContentView(R.layout.bottom_sheet_image_dialog);
bsDialog.setOnShowListener(dialog -> {
BottomSheetBehavior bottomSheetBehavior = ((BottomSheetDialog)dialog).getBehavior();
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
});
Run Code Online (Sandbox Code Playgroud)
出现以下问题:视频中看到的宽度不会完全显示。如果我在横向模式下从一开始就启动底页,则宽度看起来也会有所不同,因为左侧和右侧未被覆盖:
可能存在什么问题?在显示对话框之前是否需要预先定义宽度?
我需要将 div 宽度设置为 110%,但这对于 Tailwind CSS 来说似乎不可能。他们的文档仅指定 100% 的值。
w-full width: 100%;
Run Code Online (Sandbox Code Playgroud) 假设我想制作一个水平导航栏,有五个链接,我将宽度设置为20%.一旦我为链接添加1px边框,它们就会变得超过20%,最后一个链接会移到新的行上!我怎样才能解决这个问题?
我希望CSS允许我做一个负填充值,这样边框实际上会在元素上而不是在它周围,但它不允许这样做.
当读取DIV部分的宽度时,结果以%表示.但是,我想以像素值转换它.这怎么可能 ?
我的html中定义了一个"h"类.它的宽度="100%".它的父div有width ="69%".
width = ($(this).find('.h').width())
Run Code Online (Sandbox Code Playgroud)
所以实际上宽度不是window.width(),而是它的69%.我想要像素!
width ×10
css ×3
flutter ×3
html ×2
android ×1
bottom-sheet ×1
c# ×1
containers ×1
dart ×1
datatable ×1
dialog ×1
dom ×1
fixed-width ×1
fonts ×1
javascript ×1
jquery ×1
latex ×1
layout ×1
longtable ×1
match ×1
stack ×1
tailwind-css ×1
unicode ×1
widget ×1