Home > Web Front-end > HTML Tutorial > How to center and evenly distribute the li in ul_html/css_WEB-ITnose

How to center and evenly distribute the li in ul_html/css_WEB-ITnose

不言
Release: 2018-05-24 09:37:03
Original
7292 people have browsed it

Ul has a fixed width, li has a variable width, and li has been set to inline-block, as shown in the picture. Now I want the li to be evenly distributed horizontally and centered in the ul. I don’t know how to set it up

Reply to the discussion (solution)


<style type="text/css">
ul{margin:0 auto;padding:0;
width:400px;background:#F00;
text-align:center;
}
li{
list-style:none;
display:inline-block;
margin:0 10px;width:100px;
background:#0F0;}</style><ul>	
<li>1</li><li>2</li><li>3</li></ul>
Copy after login

Pure css only works if you give li a given width.
Otherwise, we have to use js.


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template