HTML: <ul> 标签位于 div 区域的边缘

标签 html css

由于某些原因,ul 中的 li 标签没有缩进。有什么我想念的吗?

最佳答案

您的 CSS 文件的第 1 行是问题所在。

* {
    margin: 0;
    padding: 0;
}

通过该声明,您将列表项的边距和填充设置为 0;因此它不会出现缩进。

要解决这个问题,您应该为您的元素包含一些默认样式。例如,在我的样式表中,第一行是 CSS 重置,然后是各种元素的一些通用样式。

/*CSS Reset*/
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}/* HTML5 display-role reset for older browsers */article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}table{border-collapse:collapse;border-spacing:0}
/*Generic Styles*/
ul{list-style:disc;margin:1em 0 1em 3em}
li{margin:.3em 0}

关于HTML: <ul> 标签位于 div 区域的边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10049487/

相关文章:

jquery - 如何使用 CSS 隐藏特定的字段集

html - 正确的字体粗细加载然后在半秒后改变?

html - 如何将元素从左侧移动到右侧?

java - 如何将带有html元素的jsonArray输出到JSP中

javascript - 如何将两个父节点连接到一个子节点以及如何务实地为树中的每个节点制作工具提示?在 D3 js (SVG) 中

php - cakephp 中 webroot 中的 css 文件并与 html 链接

css - iPad Safari 滚动会导致 HTML 元素消失并延迟重新出现

html - text-align:center 不适用于 div 元素

html - 如何在此网页上以这种方式从移动设备到桌面重新排列元素?

html - 为什么背景图像没有出现在 Jumbotron (Bootstrap) 中?