当背景图像的容器改变大小时,更改背景图像的哪一侧被修剪?

发布于 2024-10-17 08:55:53 字数 1994 浏览 7 评论 0原文

我有一个 div (带有背景图像),图像的宽度是 40px。

现在,当我将宽度更改为 20px 时,它会修剪图像的右侧。有什么办法让它修剪左侧吗?

解释:我有一个正方形(4 个角图像和 1 个上下条带图像(条带图像仅为 1x20,带有重复 x))。如果我进入仅包含“欢迎!”一词的欢迎页面,则正方形的大小将会减小。如果我进入“我的角色”页面,方块的大小将会增加。

这意味着正方形将始终适合内容。

 <table align="center">
    <tr>
        <td>
            <div id="dynamic" class="DynamicWidth" >
                <div class="ContentTL ContentCorners">
                </div>
                <asp:Panel ID="ContentTC" runat="server" CssClass="ContentTC ContentStrips">
                </asp:Panel>
                <div class="ContentTR ContentCorners">
                </div>
                <div class="ContentDiv">
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                    </asp:ContentPlaceHolder>
                </div>
                <div class="ContentBL ContentCorners">
                </div>
                <asp:Panel ID="ContentBC" CssClass="ContentBC ContentStrips" runat="server">
                </asp:Panel>
                <div class="ContentBR ContentCorners">
                </div>
            </div>
        </td>
    </tr>
</table>

问题:现在,对于正方形尺寸的减小和增大,我无法使用“px”单位,因为在欢迎屏幕中,整个正方形的宽度(2个角和条带)可能是200px,而在其他页面中,它将是1000px 。

所以我决定使用“%” - 两个角具有相同的宽度百分比,并且条带的宽度将完成 100%(例如:角每个为 3%,条带将为 96%)

一切都很好,但有一个问题 - 我的角图像看起来像这样 - 右下角(在此处输入图像描述)和左下角(在此处输入图像描述)。如果页面真的很小 - 我的左角还可以,但我的右角失去了圆度 - 几乎看起来像一个正方形。 (200px 的 3% 确实很小,它不是修剪图片的左侧,而是修剪右侧的图像,从而导致圆形尺寸的损失)

解决方案:为了使这个东西起作用,我向您询问了一种从其中修剪图像的方法另一边,但我想到了另一个解决方案:我拍摄了左下图像(在此处输入图像描述)并简单地翻转了它(-moz-transform: scaleX(-1); 我也有用于 Opera、Safari 和 IE 的),并且宽度会在从另一侧修剪时发生变化。

顺便说一句:现在,我只需要 2 个角点图像,而不是 4 个

I have a div (with a background image) and the image's width is 40px.

Now when I change the width to 20px it trims the image's right side. Is there any way to make it trim the left side instead?

Explanation : I have a square (4 images for corners and 1 image for upper and lower strip (the strip images are just 1x20 with repeat-x)). If I go to the welcome page which only contains the word "Welcome!", that the square's size will decrease. If I go to the 'My Character' page, the square's size will increase.

Meaning the square will always fit the content.

 <table align="center">
    <tr>
        <td>
            <div id="dynamic" class="DynamicWidth" >
                <div class="ContentTL ContentCorners">
                </div>
                <asp:Panel ID="ContentTC" runat="server" CssClass="ContentTC ContentStrips">
                </asp:Panel>
                <div class="ContentTR ContentCorners">
                </div>
                <div class="ContentDiv">
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                    </asp:ContentPlaceHolder>
                </div>
                <div class="ContentBL ContentCorners">
                </div>
                <asp:Panel ID="ContentBC" CssClass="ContentBC ContentStrips" runat="server">
                </asp:Panel>
                <div class="ContentBR ContentCorners">
                </div>
            </div>
        </td>
    </tr>
</table>

Problem : Now, for the square's size to decrease and increase I can't use the 'px' unit since in the welcome screen, the whole square's width (2 corners and strip) might be 200px and in other pages, it's gonna be 1000px.

So I decided to use '%' - both corner with same % of width and the strip's width will complete to 100% (Ex: corners are 3% each, strip will be 96%)

It's all well but there's a problem - my corner image looks like this - bottom right(enter image description here) and bottom left(enter image description here). if the page is really small - my left corner is ok but my right corner losses its roundness - almost looks like a square. (3% of 200px is really small and instead of trimming the left side of the picture it trims the right one which results in loss of the round size)

Solution : For this thing to work I asked you for a way to trim the image from the other side but than I thought of another solution : I took bottom left image (enter image description here) and simply flipped it (-moz-transform: scaleX(-1); I also have ones for opera,safari and IE) and the the width changes while triming it from the other side.

BTW : Now, I only need 2 images for corners instead of 4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

箜明 2024-10-24 08:55:53

给它背景位置:-20px 0;

give it background-position: -20px 0;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文