gpt4 book ai didi

css - 将四个不同的 div 垂直居中

转载 作者:太空宇宙 更新时间:2023-11-03 19:06:19 24 4
gpt4 key购买 nike

我有四个 div,每个都是一个包含许多行的列表。它们都通过相对定位向左浮动,因此都排成一排。我想将它们在 div“容器”中垂直居中。我该怎么做?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<style type="text/css">
.titlefont{
font-family:"Lucida Console", Monaco, monospace;
}

div#saucelistdiv{
float:left;
width:auto;
margin:10px;
vertical-align:middle;
height:auto;
}
div#meatlistdiv{
float:left;
width:auto;
margin:10px;
vertical-align:middle;
height:auto;
}
div#container{
height:600px;
border:2px solid red;
width:auto;
}
#grainlistdiv{
float:left;
width:auto;
margin:10px;
vertical-align:middle;
height:auto;
}
div#veggielistdiv{
float:left;
width:auto;
margin:10px;
vertical-align:middle;
height:auto;
}
#tablelist{
border:2px solid;
}
</style>
<body>

<center>
<div id="container">
<div id="saucelistdiv"><table id="tablelist">
<span class="titlefont">SAUCES</span>
<tr><td><input type="radio" name="rbbase" value="Pizza Sauce" checked="checked" />Pizza Sauce</td></tr>
<tr><td><input type="radio" name="rbbase" value="Cheese Sauce" />Cheese Sauce</td></tr>
<tr><td><input type="radio" name="rbbase" value="Barbecue Sauce" />Barbecue Sauce</td></tr>



<tr><td><input type="radio" name="rbbase" value="Salsa" />Salsa</td></tr>
<tr><td><input type="radio" name="rbbase" value="Alfredo Sauce" />Alfredo Sauce</td></tr>
<tr><td><input type="radio" name="rbbase" value="Taco Sauce" />Taco Sauce</td></tr>



<tr><td><input type="radio" name="rbbase" value="Tzatziki (Cucumber) Sauce" />Tzatziki (Cucumber) Sauce</td></tr>
<tr><td><input type="radio" name="rbbase" value="Chicken Gravy" />Chicken Gravy</td></tr>
<tr><td><input type="radio" name="rbbase" value="Beef Gravy" />Beef Gravy</td></tr>



<tr><td><input type="radio" name="rbbase" value="Ranch Dressing" />Ranch Dressing</td></tr>
<tr><td><input type="radio" name="rbbase" value="1000 Island Dressing" />1000 Island Dressing</td></tr>
<tr><td><input type="radio" name="rbbase" value="Parmesan Peppercorn Dressing" />Parmesan Peppercorn Dressing</td></tr>



<tr><td><input type="radio" name="rbbase" value="Spaghetti Sauce" />Spaghetti Sauce</td></tr>
<tr><td><input type="radio" name="rbbase" value="Chili" />Chili</td></tr>
<tr><td><input type="radio" name="rbbase" value="Syrup" />Syrup</td></tr>



<tr><td><input type="radio" name="rbbase" value="Garlic Butter" />Garlic Butter</td></tr>
<tr><td><input type="radio" name="rbbase" value="Mayonnaise" />Mayonnaise</td></tr>





</table>
</div>

<div id="meatlistdiv">
<span class="titlefont">MEATS</span>
<table class="center" id="tablelist">



<tr><td><input type="checkbox" name="cbing" value="Sausage" />Sausage<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Pepperoni" />Pepperoni<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Diced Ham" />Diced Ham<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Beef" />Beef<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Bacon" />Bacon<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Lamb" />Lamb<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Bratwurst" />Bratwurst<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Chicken" />Chicken<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Shrimp" />Shrimp<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Crab" />Crab<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Seasoned Beef" />Seasoned Beef<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Corned Beef" />Corned Beef<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Turkey" />Turkey<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Eggs" />Eggs<br /></td></tr>




</table>
</div>

<div id="grainlistdiv">
<span class="titlefont">GRAINS</span>
<table class="center" id="tablelist">
<tr><td><input type="checkbox" name="cbing" value="Elbow Macaroni" />Elbow Macaroni<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Spaghetti Noodles" />Spaghetti Noodles<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Oyster Crackers" />Oyster Crackers<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Goldfish" />Goldfish<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Mini Pancakes" />Mini Pancakes<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Pretzels" />Pretzels<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Stuffing" />Stuffing<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Taco Chips" />Taco Chips<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Ramen Noodles" />Ramen Noodles<br /></td></tr>
</table>
</div>

<div id="veggielistdiv">
<span class="titlefont">VEGGIES/OTHER</span>
<table class="center" id="tablelist">
<tr><td><input type="checkbox" name="cbing" value="Lettuce" />Lettuce<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Tomatoes" />Tomatoes<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Onions" />Onions<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Green Peppers" />Green Peppers<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Green Olives" />Green Olives<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Black Olives" />Black Olives<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Pineapple" />Pineapple<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Sauerkraut" />Sauerkraut<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Broccoli" />Broccoli<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Cauliflower" />Cauliflower<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Jalapeno Peppers" />Jalapeno Peppers<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Pickles" />Pickles<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Cucumbers" />Cucumbers<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Carrots" />Carrots<br /></td></tr>
<tr><td><input type="checkbox" name="cbing" value="Mushrooms" />Mushrooms<br /></td></tr>
</table>
</div>


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

最佳答案

我相信,如果您将 float:left; 更改为 display:inline-block;,那么您将获得您正在寻找的效果。

关于css - 将四个不同的 div 垂直居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10131301/

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