如何中心列表 [英] How to center list

查看:142
本文介绍了如何中心列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在我的html页面上有< select> 列表:

If I have a <select> list on my html page:

<body>
<div id="side-bar">...</div>
<div id="list">
       <select id="mylist" size="10"></select>
</div>
</body>

如何CSS mylist使它位于 div id =list> area? (水平垂直

How to CSS mylist to make it located in the middle of the <div id="list"> area? (Both horizontally and vertically)

推荐答案

c $ c> #mylist {margin:0 auto} 。它只包含select元素。如果你想把你的div中的所有内容,然后 #list {text-align:center; }

You could try #mylist {margin: 0 auto}. It centers only the select element. If you want to center all the content within your div then #list { text-align: center; } should do the trick.

编辑:

纵向和横向都可以这样做:

To center the select tag both vertically and horizontally you can do like this:

<style type="text/css">
#list {
    width: 200px;
    height: 200px;
    background: #fa2;
}
#mylist {
    width: 100px;
    line-height: 20px;
    position: relative;
    top: 50%;
    left: 50%;
    margin: -10px 0 0 -50px;
}
</style>
<div id="list">
       <select id="mylist">
           <option value="1">test</option>
       </select>
</div>

这篇关于如何中心列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆