带有图像(作为链接)的透明框(div)——按比例调整大小?

发布于 2024-10-08 19:44:47 字数 1038 浏览 1 评论 0原文

这实际上是一个由两部分组成的问题。所以我有这个透明的 div 元素漂浮在背景图像上,我想要的是在框中包含图像(作为链接)。但不透明。我有透明的盒子,但我似乎不知道如何使内容不透明,因为我还希望盒子内的这些图像(作为链接)按比例缩放到网络浏览器。到目前为止,我的 css 是这样的:

#menu
  {
  position:absolute;
  top:13%;
  left:3%;
width:25%;
height:20%;

background-color:#ffffff;

filter:alpha(opacity=60);
opacity:0.6;
-moz-opacity:0.6;
    -khtml-opacity: 0.6;
 }

  #work img
  {
position:absolute;
margin: 2% 29%;

height:33%;

  }



#infocontact img
 {
    position:absolute;
margin: 33% 29%;
height:33%;
   }

   #store img
     {
    position:absolute;
margin: 66% 29%;
height:33%;
  }

我的 html 是这样的,

 <div id="menu">
 <div id="work">
 <img src="work.gif" /> </div>
 <div id="infocontact">
 <img src="info.gif" />
 </div>
 <div id="store">
 <img src="store.gif" /></div>


  </div>

所以我现在拥有的是那些随着浏览器的高度(以及随后的宽度)缩放的 gif 图像。我想做的是让这些图像也随着盒子的比例缩放。因此,如果由于某种原因您将浏览器设置得很小,则图像不会超出较小的透明框。

我知道它一定是可能的,我只是无法找出 css/html 的正确组合来使其工作。

This is actually a two part question. so I have this transparent div element floating over a background image, what I want is to have images(as links) inside the box. But not transparent. I have the transparent box but I can't seem to figure out how to make the contents not transparent, because I would also like those images(as links) within the box to scale proportionally to the web browser. my css so far is this:

#menu
  {
  position:absolute;
  top:13%;
  left:3%;
width:25%;
height:20%;

background-color:#ffffff;

filter:alpha(opacity=60);
opacity:0.6;
-moz-opacity:0.6;
    -khtml-opacity: 0.6;
 }

  #work img
  {
position:absolute;
margin: 2% 29%;

height:33%;

  }



#infocontact img
 {
    position:absolute;
margin: 33% 29%;
height:33%;
   }

   #store img
     {
    position:absolute;
margin: 66% 29%;
height:33%;
  }

and my html is this

 <div id="menu">
 <div id="work">
 <img src="work.gif" /> </div>
 <div id="infocontact">
 <img src="info.gif" />
 </div>
 <div id="store">
 <img src="store.gif" /></div>


  </div>

so what I have now is those gif images scaling with the height (and subsequent width) of the browser. and what im trying to do is have those images scale with the scale of the box as well. so if for some reason you make the browser pretty small, the images dont stick out past the smaller transparent box.

i know its gotta be possible, i just cant figure out the right combination of css/html to make it work.

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

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

发布评论

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

评论(1

度的依靠╰つ 2024-10-15 19:44:47

CSS:

.pic1
{
    position:absolute;
    width:10%;
    thisistheexactwidthofitscontaineralwaysinpercentmax-width:110px;
}

img.scaled,.scaled
{
    width:100%;
}

HTML:

<div class="pic1"><img class="scaled" src="images/yourpic.png" alt="" title="">
</div>

为图像指定比其容器更高的 zindex 并将链接应用于图像,而不是容器。

另外,对于可缩放图像,请使用 width 属性。根据容器在页面流程中的位置指定容器的宽度,以及img.scale width< /code> 到 100%

您可能需要调整容器的大小才能使其成比例,但它是一个免查询的解决方案,除了缩小具有透明背景的 png 图像之外,效果良好。

The CSS:

.pic1
{
    position:absolute;
    width:10%;
    thisistheexactwidthofitscontaineralwaysinpercentmax-width:110px;
}

img.scaled,.scaled
{
    width:100%;
}

The HTML:

<div class="pic1"><img class="scaled" src="images/yourpic.png" alt="" title="">
</div>

Give the image a higher zindex than its container and apply the link to the image, not the container.

Also, for scalable images, use the width attribute. Assign the width of the container in respect to its position in the flow of your page, and the img and .scale width to 100%.

You may have to play with the size of the container to get it proportional, but it's a query free solution and works well except for scaling down png images with transparent backgrounds.

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