gpt4 book ai didi

html - 如何使用 div 正确创建时间表?

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

我想创建与以下相同的时间表。

enter image description here

这是我的带有 div 标签的 css 代码。

<html>
<header>
<style type="text/css">
div.whole {
padding: 200px 0 0 0;
width:660px;
margin:0 auto;
align:center;}
p.h {width:660px;text-align:center;}
div{
list-style:none;
margin:0 0;
padding 0 0 0 0;
display:inline-block;
border-bottom: 1px dashed black;
width:100px;}
</style>
</header>

<body>
<div class="whole">
<p class='h'>timetabling</p>

<div>
<div>time</div><div>mon</div><div>tue</div><div>wed</div><div>thu</div><div>fri</div>
</div>
<div>
<div>9:00</div><div>x1</div><div>x2</div><div>none</div><div>x3</div><div>x4</div>
</div>
<div>
<div>10:00</div><div>none</div><div>x3</div><div>x1</div><div>x3</div><div>x4</div>
</div>
<div>
<div>11:00</div><div>none</div><div>x3</div><div>x1</div><div>x3</div><div>x4</div>
</div>
<div>
<div>12:00</div><div>x1</div><div>x1</div><div>x4</div><div>x2</div><div>none</div>
</div>

<div>
<div>total</div><div>2</div><div>4</div><div>3</div><div>4</div><div>3</div>
</div>

</div>
</body>
</html>

显示效果如下: enter image description here

这里有两个问题:
1.margin:0 auto;不能居中。
2.div元素是垂直显示的,如何让它水平显示?

最佳答案

对于解决方案 1: 要使工作 margin:0 autodisplay:blockdiv.whole

对于解决方案 2::“div 元素是垂直显示的如何使其水平显示”将类赋予行的父 div。在这里,我给 class="parent" 并给 width: 100%; 将使它水平。

div.whole {
padding: 200px 0 0 0;
width:660px;
margin:0 auto;
align:center;
display:block; //Here
}

p.h {width:660px;text-align:center;}

div{
list-style:none;
margin:0 0;
padding 0 0 0 0;
display:inline-block;
border-bottom: 1px dashed black;
width:100px;}

.parent {
width: 100%;
}
<div class="whole">
<p class='h'>timetabling</p>

<div class="parent">
<div>time</div><div>mon</div><div>tue</div><div>wed</div><div>thu</div><div>fri</div>
</div>
<div class="parent">
<div>9:00</div><div>x1</div><div>x2</div><div>none</div><div>x3</div><div>x4</div>
</div>
<div class="parent">
<div>10:00</div><div>none</div><div>x3</div><div>x1</div><div>x3</div><div>x4</div>
</div>
<div class="parent">
<div>11:00</div><div>none</div><div>x3</div><div>x1</div><div>x3</div><div>x4</div>
</div>
<div class="parent">
<div>12:00</div><div>x1</div><div>x1</div><div>x4</div><div>x2</div><div>none</div>
</div>

<div class="parent">
<div>total</div><div>2</div><div>4</div><div>3</div><div>4</div><div>3</div>
</div>

</div>

Working Fiddle

关于html - 如何使用 div 正确创建时间表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34938895/

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