table-layout :fixed white-space: nowrap word-break:break-all和word-wrap:break-word

表布局与空白处理
本文介绍了CSS中的table-layout属性及white-space属性的应用。table-layout属性用于控制表格布局算法,提高表格加载速度;white-space属性则用于指定如何处理元素内的空白字符。

设置表格布局算法:

table
  {
  table-layout:fixed;
  }

亲自试一试

浏览器支持

IEFirefoxChromeSafariOpera
     

所有浏览器都支持 table-layout 属性。

注释:任何的版本的 Internet Explorer (包括 IE8)都不支持属性值 "inherit"。

定义和用法

tableLayout 属性用来显示表格单元格、行、列的算法规则。

固定表格布局:

固定表格布局与自动表格布局相比,允许浏览器更快地对表格进行布局。

在固定表格布局中,水平布局仅取决于表格宽度、列宽度、表格边框宽度、单元格间距,而与单元格的内容无关。

通过使用固定表格布局,用户代理在接收到第一行后就可以显示表格。

自动表格布局:

在自动表格布局中,列的宽度是由列单元格中没有折行的最宽的内容设定的。

此算法有时会较慢,这是由于它需要在确定最终的布局之前访问表格中所有的内容。




CSS white-space 属性

实例

规定段落中的文本不进行换行:

p
  {
  white-space: nowrap
  }

亲自试一试

浏览器支持

IEFirefoxChromeSafariOpera
     

所有浏览器都支持 white-space 属性。

注释:任何的版本的 Internet Explorer (包括 IE8)都不支持属性值 "inherit"。

定义和用法

white-space 属性设置如何处理元素内的空白。

这个属性声明建立布局过程中如何处理元素中的空白符。值 pre-wrap 和 pre-line 是 CSS 2.1 中新增的。

默认值:normal
继承性:yes
版本:CSS1
JavaScript 语法:object.style.whiteSpace="pre"

可能的值

描述
normal默认。空白会被浏览器忽略。
pre空白会被浏览器保留。其行为方式类似 HTML 中的 <pre> 标签。
nowrap文本不会换行,文本会在在同一行上继续,直到遇到 <br> 标签为止。
pre-wrap保留空白符序列,但是正常地进行换行。
pre-line合并空白符序列,但是保留换行符。
inherit规定应该从父元素继承 white-space 属性的值。




word-break:break-all和word-wrap:break-word都是能使其容器如DIV的内容自动换行。

它们的区别就在于:

1,word-break:break-all 例如div宽200px,它的内容就会到200px自动换行,如果该行末端有个英文单词很长(congratulation等),它会把单词截断,变成该行末端为conra(congratulation的前端部分),下一行为tulation(conguatulation)的后端部分了。

2,word-wrap:break-word 例子与上面一样,但区别就是它会把congratulation整个单词看成一个整体,如果该行末端宽度不够显示整个单词,它会自动把整个单词放到下一行,而不会把单词截断掉的。

<template> <c-modal v-model:open="open" title="" @ok="handleOrderOk" width="1600px" :footer="null"> <div style="padding-bottom: 15px"> <a-button key="back" @click="handleCancel" v-if="isFooter">取消</a-button> <a-button key="print" @click="handlePrint">打印</a-button> </div> <div id="printJS-form"> <div v-for="(item, index) in formState" :key="index"> <div class="order-container print-container-div" > <div class="order-top widthClass"> <div class="order-top-title"> <div class="order-top-logo"><img class="logo" src="../../../assets/cimc.png" /></div> <p class="order-top-titles">Piping Welds Positive Material Identification Report</p> <div class="order-top-QRCode" style="float: right;width: 100px"> <img style="width: 80px;weight:30px;float: right" src="/static/pipe/images/seatrium.png" /> <img style="width: 80px;weight:30px;float: right" src="/static/pipe/images/br.png" /> </div> </div> </div> <div class="printable-area widthClass"> <table class="widthClass"> <tr style="height: 30px"> <td style="width: 50%;"></td> <td style="width: 12%;font-size: 16px;border-left: 0 none !important;">Analysis Data Sheet: </td> <td style="width: 13%;font-size: 16px;border-left: 0 none !important;"> </td> <td style="width: 12%;font-size: 16px;border-left: 0 none !important;">BM*:base material</td> <td style="width: 13%;font-size: 16px;border-left: 0 none !important;"></td> </tr> </table> <table class="widthClass" style="font-size: 16px;font-weight: 400;"> <tr style="height: 30px;"> <td style="width: 28%;">Job Title:</td> <td style="width: 24%;">{{item.pringProjectNo}}</td> <td style="width: 24%;">PMI Report NO.:</td> <td style="width: 24%;"></td> </tr> <tr style="height: 30px;"> <td style="width: 28%;">Location:</td> <td style="width: 24%;">Workshop </td> <td style="width: 24%;">Date:</td> <td style="width: 24%;">{{dayjs(item.applyDate).format("YYYY-MM-DD")}}</td> </tr> <tr style="height: 30px;"> <td style="width: 28%;">Analyser Type and Model No.:</td> <td style="width: 24%;">Nition XL2</td> <td style="width: 24%;">Operators:</td> <td style="width: 24%;">Ding Guang wei</td> </tr> <tr style="height: 30px;"> <td style="width: 28%;">Analyser Serial No.:</td> <td style="width: 24%;"></td> <td style="width: 24%;">Analyser Cablibration Date:</td> <td style="width: 24%;"></td> </tr> <tr style="height: 30px;"> <td style="width: 28%;">Material Specification/Grade:</td> <td style="width: 24%;">316/316L</td> <td style="width: 24%;">PMI Procedure No.:</td> <td style="width: 24%;">I-PR-3010.2S-1351-973-YCT-001</td> </tr> </table> <table class="widthClass" style="font-size: 16px;font-weight: 400;"> <tr style="height: 30px;"> <td style="width: 5%;" rowspan="4">S/NO</td> <td style="width: 23%;" rowspan="4">Joint No.</td> <td style="width: 60%;" colspan = '10'>Alloy Content, WT%</td> <td style="width: 12%;" colspan = '2'>Result</td> </tr> <tr style="height: 30px;"> <td style="width: 6%;">Min.</td> <td style="width: 6%;">10.0</td> <td style="width: 6%;">16.0</td> <td style="width: 6%;">2.00</td> <td style="width: 6%;">NA</td> <td style="width: 6%;">NA</td> <td style="width: 6%;">NA</td> <td style="width: 6%;">NA</td> <td style="width: 6%;">NA</td> <td style="width: 6%;">NA</td> <td style="width: 6%;" rowspan="2">Accept</td> <td style="width: 6%;" rowspan="2">Reject</td> </tr> <tr style="height: 30px;"> <td style="width: 6%;">Max.</td> <td style="width: 6%;">14.0</td> <td style="width: 6%;">20.0</td> <td style="width: 6%;">3.00</td> <td style="width: 6%;">NA</td> <td style="width: 6%;">NA</td> <td style="width: 6%;">NA</td> <td style="width: 6%;">NA</td> <td style="width: 6%;">NA</td> <td style="width: 6%;">NA</td> </tr> <tr style="height: 30px;"> <td style="width: 6%;">I.D.</td> <td style="width: 6%;">Ni</td> <td style="width: 6%;">Cr</td> <td style="width: 6%;">Mo</td> <td style="width: 6%;">Cu</td> <td style="width: 6%;">NB(cb)</td> <td style="width: 6%;">Ti</td> <td style="width: 6%;">W</td> <td style="width: 6%;">C</td> <td style="width: 6%;">Other</td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> </tr> </table> <table class="widthClass" style="font-size: 16px;font-weight: 400;"> <div v-for="(weldItem,index) in item.weldList" :key="item.id" style="width: 100%;"> <tr style="width: 100%;min-height: 30px;" > <td style="width: 5%; text-align: center; vertical-align: middle; display: table-cell;" rowspan="3">{{index+1}}</td> <td style="width: 23%;">{{weldItem.weldNo}}</td> <td style="width: 6%;">BM1*</td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> </tr> <tr style="width: 100%;min-height: 30px;" > <td style="width: 23%;" >{{weldItem.weldNo}}</td> <td style="width: 6%;">Joint</td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> </tr> <tr style="width: 100%;min-height: 30px;" > <td style="width: 23%;">{{weldItem.weldNo}}</td> <td style="width: 6%;">BM2*</td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> </tr> </div> </table> </div> </div> <div style="page-break-after:always"></div> </div> </div> </c-modal> </template> <script setup> import {ref, reactive, onMounted} from "vue" import { print } from "@/utils/print" import * as server from "@/packages/piping/api/cpin"; import {create} from "@/utils/imgtoBase64"; import dayjs from "dayjs" const open = ref(false) const initType = ref() const totalWeight = ref(0) const formState = ref({}) const isFooter = ref(true) const orderTableState = reactive({ datasource: [] }) onMounted(() => { create("/static/mes/images/dataScreen-header-center-bg.png").then((res) => { centerImg.value = res }) }) const handleOrderOk = () => {} const init = (type, data) => { initType.value = type isFooter.value = type === "galv" console.log("data2", data) let printDatas = [] // 使用 Promise.all 等待所有异步操作完成 Promise.all(data.map(async (dataItem) => { try { const res = await server.getOrderList({ page: 0, size: 10000, orderNo: dataItem.orderNo }) let item = res.data.content[0] || {} item.weldList.forEach((weld, index) => { weld.indexNum = index + 1 }) return item } catch (error) { console.error("获取订单列表失败:", error) return {} } })).then(results => { printDatas = results formState.value = printDatas }) } const handleCancel = () => { open.value = false } const handlePrint = () => { print({ // mediaPrint:false, // noPrintSelector:'avoid-this', type: "html", printable: "printJS-form", // type: "raw-html", // printable: "test-dom", // scanStyles: false, // noHeadersAndFooters:true, maxWidth: 1500, targetStyles: ["*"], scanStyles: false, style: ` table{font-size:3px} td{font-size:10px !important} .print-container-div{ width: 1100px !important; } .widthClass{ width: 1000px; font-size:1px } .ant-descriptions-view >table{ width:100%!important; font-size:1px; } @media print { a[href]:after { content: none !important; } #footer { display: none; } } .imgInline{ display: flex;} .order-top-QRCode{float:right} .order-top-title { width: 100%; height: 50px; text-align: center; display: flex; padding-top:15px } .order-top-logo { img { margin-top:10px; width: 150px; position: absolute; left: 0; } } .order-top-titles { font-size: 18px; font-weight: bold; width: 100%; margin: 0; align:center; text-align:center; padding-top:15px; } .order-top-vice-title { width: 100%; } .logo{width:150px;height:20px} .paging{page-break-after: aways;} .order-container { width: 100%; height: 100%; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; .order-top { width: 100%; display: flex; justify-content: center; position: relative; margin-bottom: 100px; height:400px; .order-top-title { width: 45%; height: 50px; text-align: center; display: flex; .order-top-logo { img { width: 150px; position: absolute; left: 0; } } .order-top-titles { font-size: 18px; font-weight: bold; width: 100%; margin: 0; } .order-top-vice-title { width: 100%; } } } .order-top-QRCode { display: flex; align-items: center; } .order-mid { width: calc(100%); padding-top: 15px; } .order-mod { width: calc(100% ); .order-mod-left{ width: 49%; padding: 5px 0; border-radius: 10px; background: #eef0f3; } .order-mod-right { width: 49%; padding: 5px 0; border-radius: 10px; background: #eef0f3; } .order-mod-title { //border: 1px solid #3981ee; padding: 5px; //color: #3981ee; width: 50%; display: flex; align-items: center; justify-content: center; margin: 10px auto; background: #fff; border-radius: 7px; } .order-mod-content { display: flex; align-items: center; width: 100%; margin: 10px auto; .order-mod-content-title { width: 30%; text-align: right; padding: 5px 0; } .order-mod-content-content { flex: 1; white-space: nowrap; } } } .order-bot { width: 100%; margin-top: 10px; } .order-table { //border: 1px solid black !important; // transform: scale(0.7); //width: calc(100% / 0.7); // transform-origin: top center; } } :deep(.ant-descriptions) { .ant-descriptions-item-label { white-space: nowrap; width: 20px; border: 1px solid black !important; } .ant-descriptions-item-content { white-space: nowrap; border: 1px solid black !important; } } .ant-modal .ant-modal-body{font-size:9px} :deep(.c-table-wrap) { .ant-table-container { table { //padding-bottom: 80px; } .ant-table-cell{ border: 1px solid black !important; padding: 12px 8px; } .ant-table-cell-ellipsis { border-color: black !important; border: 1px; padding: 12px 8px; } } } .order-container { width: 100%; } thead { display: table-header-group; } .order-top, .order-mid, .order-mod, .order-bot, .order-table { page-break-inside: avoid; } td{text-align: center;border: 1px solid #000;} th{ text-align: center;border: 1px solid #000;} .ant-table-row{ page-break-inside: avoid; } td{text-align: center;border: 1px solid #000;} tr {page-break-inside: avoid;} th{ text-align: center;border: 1px solid #000;} table { border-collapse: collapse;} table tr th, table tr td { border: 1px solid #000!important; } #printJS-form table tr td[style*="border-left: none"] { border-left: none !important; } .print-container { transform: scale(0.8); transform-origin: top left; width: 100%; } //@page{size:auto} //.paging{page-break-after: always;} } ` }) } defineExpose({ init, open }) window.onbeforeprint = function () { var links = document.getElementsByTagName("a") for (var i = 0; i < links.length; i++) { links[i].setAttribute("data-href", links[i].href) links[i].removeAttribute("href") } } window.onafterprint = function () { var links = document.getElementsByTagName("a") for (var i = 0; i < links.length; i++) { links[i].href = links[i].getAttribute("data-href") links[i].removeAttribute("data-href") } } </script> <style lang="less" scoped> .order-container { width: 100%; height: 100%; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; .order-top { width: 100%; display: flex; justify-content: center; position: relative; margin-bottom: 60px; .order-top-title { width: 45%; height: 50px; text-align: center; display: flex; .order-top-logo { img { width: 150px; position: absolute; left: 0; } } .order-top-titles { font-size: 18px; font-weight: bold; width: 100%; margin: 0; } .order-top-vice-title { width: 100%; } } } .order-top-QRCode { display: flex; align-items: center; } .order-mid { width: calc(100%); padding-top: 15px; } .order-mod { width: calc(100%); .order-mod-left { width: 49%; padding: 5px 0; border-radius: 10px; background: #eef0f3; } .order-mod-right { width: 49%; padding: 5px 0; border-radius: 10px; background: #eef0f3; } .order-mod-title { //border: 1px solid #3981ee; padding: 5px; //color: #3981ee; width: 50%; display: flex; align-items: center; justify-content: center; margin: 10px auto; background: #fff; border-radius: 7px; } .order-mod-content { display: flex; align-items: center; width: 100%; margin: 10px auto; .order-mod-content-title { width: 30%; text-align: right; padding: 5px 0; } .order-mod-content-content { flex: 1; white-space: nowrap; } } } .order-bot { width: 100%; margin-top: 10px; } .order-table { //border: 1px solid black !important; // transform: scale(0.7); //width: calc(100% / 0.7); // transform-origin: top center; } } :deep(.ant-descriptions) { .ant-descriptions-item-label { white-space: nowrap; width: 20px; border: 1px solid black !important; } .ant-descriptions-item-content { white-space: nowrap; border: 1px solid black !important; } } :deep(.c-table-wrap) { .ant-table-container { table { //padding-bottom: 80px; } .ant-table-cell { border: 1px solid black !important; padding: 12px 8px; } .ant-table-cell-ellipsis { border-color: black !important; border: 1px; padding: 12px 8px; } } } .order-container { width: 100%; } thead { display: table-header-group; } .order-top, .order-mid, .order-mod, .order-bot, .order-table { page-break-inside: avoid; } .order-mod-title { } td { text-align: center; border: 1px solid #000; } th { text-align: center; border: 1px solid #000; } @media print { a[href]:after { content: none !important; } #footer { display: none; } tr { page-break-inside: avoid; } } .ant-table-row { page-break-inside: avoid; } td { text-align: center; border: 1px solid #000; } tr { page-break-inside: avoid; } th { text-align: center; border: 1px solid #000; } table { border-collapse: collapse; } table tr th, table tr td { border: 1px solid #000 !important; } .ant-descriptions-item-label { white-space: nowrap !important; } .print-container { transform: scale(0.8); transform-origin: top left; width: 100%; } .numbers { font-family: "Arial", sans-serif; /* 或其他不支持自动转换的字体 */ } div { font-family: "Arial", sans-serif; /* 或其他不支持自动转换的字体 */ } .widthClass { width: 1500px !important; } .print-container-div { width: 1500px !important; } </style> 其中 <table class="widthClass" style="font-size: 16px;font-weight: 400;"> <div v-for="(weldItem,index) in item.weldList" :key="item.id" style="width: 100%;"> <tr style="width: 100%;min-height: 30px;" > <td style="width: 5%; text-align: center; vertical-align: middle; display: table-cell;" rowspan="3">{{index+1}}</td> <td style="width: 23%;">{{weldItem.weldNo}}</td> <td style="width: 6%;">BM1*</td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> </tr> <tr style="width: 100%;min-height: 30px;" > <td style="width: 23%;" >{{weldItem.weldNo}}</td> <td style="width: 6%;">Joint</td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> </tr> <tr style="width: 100%;min-height: 30px;" > <td style="width: 23%;">{{weldItem.weldNo}}</td> <td style="width: 6%;">BM2*</td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> <td style="width: 6%;"></td> </tr> </div> </table>设置宽度 100%没有起作用
11-01
<table style=" border: 1px solid black; border-collapse: collapse; width: 50mm; height: 30mm; table-layout: fixed; box-sizing: border-box; font-size: 12px; "> <tr style="border: 1px solid black;"> <td style="border: 1px solid black; padding: 1px; width: 8.89%;">资产编码:</td> <td style="padding: 1px; width: 8.89%; overflow: hidden; text-overflow: ellipsis;">$zcbm$</td> <td rowspan="3" style=" border: 1px solid black; vertical-align: middle; text-align: center; width: 71.12%; padding: 0; height: 10mm; overflow: hidden; "> <div style=" max-width: 100%; max-height: 100%; display: flex; justify-content: center; align-items: center; margin: 0 auto; overflow: hidden; "> #QRCodeImg# </div> </td> </tr> <tr style="border: 1px solid black;"> <td style="border: 1px solid black; padding: 2px; width: 8.89%;">资产名称:</td> <td style="padding: 1px; overflow: hidden; text-overflow: ellipsis; width: 8.89%;">$zcmc$</td> </tr> <tr style="border: 1px solid black;"> <td style="border: 1px solid black; padding: 2px; width: 8.89%;">使用部门:</td> <td style="padding: 2px; overflow: hidden; text-overflow: ellipsis; width: 8.89%;">$sybm$</td> </tr> <tr style="border: 1px solid black; height: 20mm;"> <td style="border: 1px solid black; padding: 2px; width: 8.89%;">启用日期:</td> <td style="padding: 2px; overflow: hidden; text-overflow: ellipsis; width: 8.89%;">$date$</td> <td style="visibility: hidden;"></td> </tr> </table>除了二维码都没有完全显示,在原来的代码进行修改并给出完整代码
10-10
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值