[英]How to remove unwanted whitespaces
I am practicing html/css by making this website but there are some white spaces to the left and right around the links in list of contents.我正在通过制作这个网站来练习 html/css,但是在内容列表中的链接周围有一些空格。 I have added a sample of html code of how complete list is coded.
我添加了一个关于如何编码完整列表的 html 代码示例。
I have tried setting the margins and paddings of all elements to zero but nothing is working.我尝试将所有元素的边距和填充设置为零,但没有任何效果。
body { margin: 0; } .container { display: grid; grid-template-columns: 20% 80%; margin: 0; } .nav_bar { min-height: 100vh; overflow-y: auto; margin: 0; padding: 0; } .nav_bar ul { display: block; padding: 5px; list-style: none; font-size: 0; margin: 0; } .nav_bar li { padding: 10px 5px; border-bottom: 2px solid black; }
<div class="container"> <div class="nav_bar"> <h3>JS DOCUMENTATION</h3> <ul class="nav_list"> <li> <a href="page.html#introduction">Introduction</a> </li> </ul> </div> </div>
You have given the padding
to the ul
tag that is the reason why the line did not touch two extreme ends.您已为
ul
标记提供了padding
,这就是该行未触及两个极端的原因。
just change the padding
in the ul
to 0
只需将
ul
的padding
更改为0
Is this what you are looking for ?这是你想要的 ? I added the color in order to show where the problem occured
我添加了颜色以显示问题发生的位置
body { margin: 0; } .container { display: grid; grid-template-columns: 40% 30%; margin: 0; padding:0; } .nav_bar { min-height: 100vh; overflow-y: auto; margin: 0; padding: 0; } h3 { padding: 10px 5px; } ul { display: block; padding: 0px; font-size: 0; margin: 0; } li { padding: 10px 5px; border-bottom: 2px solid black; } li:first-child { border-top: 2px solid black; } a { text-decoration: none; color: black; font-size: 18px; font-weight: 300; }
<div class="container" style="background-color:green;"> <div class="nav_bar" style="background-color:lightblue;"> <h3 style="background-color:red;">JS DOCUMENTATION</h3> <ul style="background-color:pink;" class="nav_list"> <li> <a href="page.html#introduction">Introduction</a> </li>
Are u expecting like this :你期待这样吗:
NOTE: CHECK MY ANSWER IN FULL SCREEN MODE注意:在全屏模式下检查我的答案
#drop-down{
padding-inline-start:0; /*use this css */
}
HTML: HTML:
<ul class="nav_list" id="drop-down"> <!-add id="drop-down" to ul-->
<li>
<a href="page.html#introduction">Introduction</a>
</li>
</ul>
#drop-down { padding-inline-start: 0; } * { box-sizing: border-box; } body { margin: 0; } .container { display: grid; grid-template-columns: 20% 80%; margin: 0; } .nav_bar { min-height: 100vh; overflow-y: auto; margin: 0; padding: 0; } .nav_bar h3 { padding: 10px 5px; } .nav_bar ul { display: block; padding: 5px; list-style: none; font-size: 0; margin: 0; } .nav_bar li { padding: 10px 5px; border-bottom: 2px solid black; } .nav_bar li:first-child { border-top: 2px solid black; } .nav_list a { text-decoration: none; color: black; font-size: 18px; font-weight: 300; }
<div class="container"> <div class="nav_bar"> <h3>JS DOCUMENTATION</h3> <ul class="nav_list" id="drop-down"> <li> <a href="page.html#introduction">Introduction</a> </li> </ul> </div> </div>
Assuming you mean the padding on the list items
(which you don't currently confiugre in your css), you can do the following;假设您指的是
list items
上的填充(您当前未在 css 中配置),您可以执行以下操作;
.nav_list li {
padding-left: 0;
padding-right: 0;
}
This will remove the padding on the left and right side side for each list item
in your unordered list
.这将删除
unordered list
每个list item
左侧和右侧的填充。
Also note that in your question, you have not yet set all paddings to 0.另请注意,在您的问题中,您尚未将所有填充设置为 0。
.nav_bar ul {
display: block;
padding: 5px;
list-style: none;
font-size: 0;
margin: 0;
}
If this is not desired behaviour, be sure to set the padding of the unordered list
to 0
too.如果这不是我们想要的行为,请务必将
unordered list
的填充也设置为0
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.