将div宽度设置为100%减去px的某个量 [英] Setting div width to 100% minus certain amount of px

查看:116
本文介绍了将div宽度设置为100%减去px的某个量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直在网上搜索过去的几个小时找到一个解决方案,但找不到它,所以这里我是。

Have been searching the net for the past hours to find a solution to this, but couldn't find it, so here I am.

我需要 div 的宽度为 100%减去 left div 的宽度。

I need the width of the div to be 100% minus the width of the left div.

因此,它左边的 div 保持相同的宽度(390像素),而其他 div 根据分辨率调整其大小。我找到了解决方案,它有两个固定宽度 div ,但只是无法想出这一点。

So that the div to the left of it stays the same width (390px) but the other div adjusts its size depending on the resolution . I have found the solution where it has a fixed width div on both sides, but just cant figure this out.

>

推荐答案

简单解决方案:

<div id="content">
    <div class="padder">

    </div><!-- .padder -->
</div>
<div id="sidebar">
    <div class="padder">

    </div><!-- .padder -->
</div>

CSS:

div#content {
    float: right;
    width: 100%;
}

div#content .padder {
    margin-left: 330px;
    padding: 0 30px 0 0;
}

div#sidebar {
    float: left;
    width: 300px;
    margin-top: -30px;
    padding-left: 30px;
    margin-right: -330px;
}

这将允许你有一个固定的侧边栏宽度和一个全宽度的内容区域。我已经用了很多次,它的工作原理就像一个魅力。

This will allow you to have a fixed sidebar width and a full width content area. I have used it many times and it works like a charm.

这篇关于将div宽度设置为100%减去px的某个量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆