简体   繁体   English

删除HTML元素之间的可视空白

[英]Remove Visual White Space Between HTML Elements

I am very new to HTML and I need some help on removing visual white space in my HTML code when I compile run it. 我是HTML的新手,在编译运行HTML时,我需要一些帮助来消除HTML代码中的可视空白。

This is what I want my HTML page to look like in this specific area: 这就是我希望我的HTML页面在这个特定区域中的样子:

在此输入图像描述

And this is how it looks on my end (I don't want this. I want it to look like the image above) 这就是它在我看来的样子(我不想要这个。我希望它看起来像上面的图片)

在此输入图像描述

This is the code I am using for the table element: 这是我用于表元素的代码:

<ul>
    <li>
    <p>Gorras</p>
    <ol>
        <li>Small - $10.00</li>
        <li>Medium - $12.00</li>
        <li>Large - $15.00</li>
</ol>        
</li>
</ul>

<ul>
    <li>
    <p>Camisas</p>
    <ol>
        <li>Small - $20.00</li>
        <li>Medium - $22.00</li>
        <li>Large - $25.00</li>
</ol>        
</li>
</ul>

<ul>
    <li>
    <p>Calzado</p>
    <ol>
        <li>Small - $50.00</li>
        <li>Medium - $60.00</li>
        <li>Large - $75.00</li>
</ol>        
</li>
</ul>

<ul>
    <li>
    <p>Gafas</p>
    <ol>
        <li>Small - $10.00</li>
        <li>Medium - $12.00</li>
        <li>Large - $15.00</li>
</ol>        
</li>
</ul>

Is there any way I can remove these spaces between each list? 有什么办法可以删除每个列表之间的这些空格吗?

Thank you very much and please forgive me because I am new to HTML. 非常感谢您,请原谅我,因为我是HTML的新手。

Just put margin:0 on your p and ul elements 只需在你的pul元素上加上margin:0

See here 看到这里

You need to reset the user agent stylesheet, for a quick fix, you can use 您需要重置用户代理样式表,以便快速修复,您可以使用

* {
    margin: 0;
    padding: 0;
}

Demo 演示

So here, the * means reset the margin and padding of ALL elements in the document and then accordingly you can provide margin-left to your lists like 所以在这里, *意味着重置文档中所有元素的marginpadding ,然后相应地你可以向列表提供margin-left

* {
    margin: 0;
    padding: 0;
}

ul {
    margin-left: 50px;
}

ol {
    margin-left: 30px;
}

We reset the margin and padding because say browsers like Firefox, Chrome, etc apply some base styles to your HTML document which is also known as User Agent Stylesheet so inorder to have minimal cross browser issues you should use CSS Reset or using * selector with margin and padding would suffice as well. 我们重置marginpadding因为像Firefox,Chrome等浏览器会将一些基本样式应用于HTML文档(也称为用户代理样式表),因此为了使交叉浏览器问题最少,您应该使用CSS重置或使用带有margin *选择器并且padding也足够。

But if you see, am using too general selectors here, so it is better to assign a class to your elements or you can wrap them under a single div and assign a class to that and select your lists appropriately. 但是如果你看到,我在这里使用过于通用的选择器,那么最好为你的元素分配一个class ,或者你可以将它们包装在一个div并为其分配一个class并适当地选择你的列表。

You need to set the margin 您需要设置边距

ul, li, p {margin: 0;}

JSFIDDLE DEMO JSFIDDLE DEMO

Remove the <p></p> tag and add margin style as below 删除<p></p>标记并添加如下的margin样式

<ul  style="margin:0;">
    <li>
    Gorras
    <ol>
        <li>Small - $10.00</li>
        <li>Medium - $12.00</li>
        <li>Large - $15.00</li>
</ol>        
</li>
</ul>

That is because of the default margin on <ul> . 那是因为<ul>的默认边距。 This margin is from the default set of styles the browser uses when no style is specified. 此边距来自未指定样式时浏览器使用的默认样式集。

You can find that using the developer console of any modern browser (developer console can be got from hitting F12 ). 您可以使用任何现代浏览器的开发人员控制台(开发人员控制台可以通过点击F12 )。

This is what Chrome shows, and you can see the margins taking the space. 这就是Chrome所显示的内容,您可以看到空白处占据了空白。 (Click the "Select an Element" option - the little magnifying glass on the top left corner of the developer tools window. This is a pointer icon on IE, and then click on the element that you want to "Inspect".) (单击“选择元素”选项 - 开发人员工具窗口左上角的小放大镜。这是IE上的指针图标,然后单击要“检查”的元素。)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM