admin管理员组文章数量:1122832
I am making a navigation bar in my website and I realized the text is just too close to the edge of the buttons. How can I fix this?
Here is the code I used:
.sections {
height: 75px;
width: 500px;
background-color: #18148b;
line-height: 75px;
margin-bottom: 5px;
color: white;
}
#sectionList {
background-color: #131067;
height: 100%;
width: 500px;
}
<div id="sectionList">
<ul id="list" style="list-style-type: none; margin: 0; padding: 0;">
<li id="section1" class="sections">Section1</li>
<li class="sections">Section2</li>
</ul>
I am making a navigation bar in my website and I realized the text is just too close to the edge of the buttons. How can I fix this?
Here is the code I used:
.sections {
height: 75px;
width: 500px;
background-color: #18148b;
line-height: 75px;
margin-bottom: 5px;
color: white;
}
#sectionList {
background-color: #131067;
height: 100%;
width: 500px;
}
<div id="sectionList">
<ul id="list" style="list-style-type: none; margin: 0; padding: 0;">
<li id="section1" class="sections">Section1</li>
<li class="sections">Section2</li>
</ul>
Share
Improve this question
edited Nov 23, 2024 at 3:23
Mister Jojo
22.2k6 gold badges25 silver badges42 bronze badges
asked Nov 23, 2024 at 3:21
AllenAllen
393 bronze badges
3 Answers
Reset to default 3You have to have your css something like this.
Set every element's margin and padding to 0 and box-sizing to border box.
After that you can apply required margin and padding to different tags.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#sectionList {
background-color: #131067;
height: 100%;
width: 500px;
}
.sections {
height: 75px;
width: 500px;
background-color: #18148b;
margin-bottom: 5px;
color: white;
padding: 30px 10px;
}
<div id="sectionList">
<ul id="list" style="list-style-type: none; margin: 0; padding: 0">
<li id="section1" class="sections">Section1</li>
<li class="sections">Section2</li>
</ul>
</div>
Just add padding to li tag in style for better control
ul#list li{padding:5px 10px 15px 20px;}
In this example, padding is top:5px, right:10px, bottom:15px and left:20px You can set according to your requirement
padding-left: 15px; /* Adds padding */
box-sizing: border-box; /* Ensures padding doesn't increase the total width */
Add this lines to .sections
class.
本文标签: cssHow to change the position of the text in a HTML elementStack Overflow
版权声明:本文标题:css - How to change the position of the text in a HTML element? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736299916a1930631.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论