html - 如何强制 margin-right 0?

标签 html css

我的 html 和 css 是这样的:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>Data</title>
        <style type="text/css"> 
            body {  
                font-family: 'Arial';
                font-size: 9px;
                margin-bottom: 100px;
            }
            div.global{
                width: 100%;
                font-size: 12px;
            }
            div.left {
                float: left;
                width: 50%; 
                text-align: center;
            }
            div.right {
                margin-left: 80%;
            }
            div.center {
                margin-left: 35%;
                width: 485px;
                text-align: center;
                font-size: 12px;
            }
        </style>
    </head>
    <body>
        <div class="global">
            <div class="left">
                <div style="width: 80mm; margin-left: -15px !important;"> 
                    data.... <br>
                    test....
                </div>
                <hr style="max-width: 80mm; margin-left:0; height:1px; border:none; color:#333;background-color:#333;">
            </div>
            <div class="right">
                <div style="width: 80mm; margin-right: 0 !important"> 
                    <table>
                        <tr style="padding-right:35px">
                            <td>Lamp</td>
                            <td align="right">test 1</td>
                        </tr>
                        <tr>
                            <td>No</td>
                            <td align="right">test 2</td>
                        </tr>
                        <tr>
                            <td>Date</td>
                            <td align="right">test 3</td>
                        </tr>
                    </table>
                </div>
                <hr style="max-width: 80mm; margin-left:0 height:1px; border:none; color:#333;background-color:#333;">

            </div>
        </div>  
        <div class="center">
            data 1 2 3<br>
            data 4 5 6
        </div>          
    </body>
</html>

................................................ ............

我想在最右边显示表格(table in class=right)

我试试

......................

<div style="width: 80mm; margin-right: 0 !important">

................................

但是id不行

有没有人可以帮助我?

更新

演示是这样的:

https://jsfiddle.net/skfd7215/1/

最佳答案

感谢这是一篇较旧的帖子,我还没有根据您提供的代码对此进行测试(因此我不能保证它在现阶段适用于您给定的场景)但我正在研究一个解决方案来强制执行也通过 margin-right 将相关元素添加到右侧,并发现了这个小美:

.element {
  margin-left: auto;
  margin-right: 0;
}

此处的代码笔示例 https://codepen.io/jamie-endeavour/pen/GdrZao

无论哪种方式,我都希望你能解决问题。如果您可以分享您的解决方案,那就太好了,因为以上答案均未被接受!

关于html - 如何强制 margin-right 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43717133/

相关文章:

html - HTML 或 CSS 可以给图像裁剪效果吗?

python - 如何使用beautifulsoup获取html中的类内容?

javascript - 主 div 不能随动态内容正确缩放

html - 使一个 div 标签位于另一个 div 标签的底部

css - 如何摆脱 chrome 浏览器中 textarea 底部与其包装 div 之间的差距?

html - 按高度百分比设置多个 div 以填充父 div

html - 仅 CSS 响应式菜单不会在页面加载时关闭

javascript - 单击提交时的 HTML http重置/?

html - 父div需要重叠在子div上

javascript - 媒体查询在 IE8 中不起作用——即使使用 respond.js 解决方法