gpt4 book ai didi

html - 如何在响应式表格内设置文本 - 单元格和表格的纵横比应为 1 :1

转载 作者:太空宇宙 更新时间:2023-11-04 10:58:25 24 4
gpt4 key购买 nike

我使用响应式设计设计了一张 table 。它在所有设备中保持相同的宽度和高度。所有单元格的宽度和高度应相同。

Cell Height = Responsive Cell Width

+---------+
| CSS |
| Table |
| 1:1 |
+---------+

我想在不折叠单元格和表格的纵横比的情况下将文本放置在单元格中,并且应该格式化文本。

Note: Kindly give solution using CSS. Don't use the Javascript or any other raw value feeding. All Cell should be in same width and height.

我的 HTML 源代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Bootstrap Table</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<style>
td{
width: 25%;
height: 25%;
padding:0 !important;

overflow:auto;
}
td.td-wide{
height: auto;
}
td div{
position:absolute;
width: 25%;

}
.placeholder{
padding-bottom: 100%;
position:relative;
}
</style>
</head>
<body>
<div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
<table class="col-lg-6 col-sm-10 col-md-8 col-xs-12" border="1">
<tr>
<td class="col-lg-3">
<div class='placeholder'>

</div>
<div>
as;dfjdj f;s f;sj f;sjdf
</div>

</td>
<td class="col-lg-3">
<div>
as;dfjdj f;s f;sj f;sjdf
</div>
</td>
<td class="col-lg-3"></td>
<td class="col-lg-3">&nbsp;</td>
</tr>
<tr>
<td class="col-lg-3">
<div class='placeholder'>

</div>
<div>

</div>
</td>
<td colspan="2" rowspan="2" class="col-lg-6 td-wide">&nbsp;</td>
<td class="col-lg-3"><div>
as;dfjdj f;s f;sj f;sjdf
</div></td>
</tr>
<tr>
<td class="col-lg-3">
<div class='placeholder'>

</div>
<div>
as;dfjdj f;s f;sj f;sjdf k kljsf sdf;ljsd fjsd f;lkjsd f;k jsad;lfkjas d;kk ;fjsadf
</div>
</td>
<td class="col-lg-3">
<div>
asdfsadf
</div>
</td>
</tr>
<tr>
<td class="col-lg-3">
<div>

</div>
</td>
<td class="col-lg-3">
<div class='placeholder'>

</div>
<div>
as;dfjdj f;s f;sj f;sjdf
</div>
</td>
<td class="col-lg-3">&nbsp;</td>
<td class="col-lg-3">&nbsp;</td>
</tr>
</table>
</div>
</body>
</html>

最佳答案

据我所知,仅使用 CSS 的唯一方法是放弃表格(它对定位 react 不佳),即使用视口(viewport)单位来创建正方形。

请注意,这会限制“单元格”的大小,并且这些单元格不会影响其他单元格的大小……这需要 javascript。

* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.parent {
width: 50vw;
height: 50vw;
margin: auto;
}
.child {
width: 12.5vw;
height: 12.5vw;
float: left;
border: 1px solid green;
}
<div class="parent">

<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>

关于html - 如何在响应式表格内设置文本 - 单元格和表格的纵横比应为 1 :1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34507573/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com