简体   繁体   English

将调整大小但保持在屏幕上相同位置的菜单

[英]Menu that will resize but stay in the same place on the screen

I am trying to create a simple concession stand menu that will display snack items on the left side of the image and drinks on the right side of the image.我正在尝试创建一个简单的特许摊位菜单,该菜单将在图像左侧显示零食,在图像右侧显示饮料。

However, I need the items on the menu and the background image to resize depending on the size of the screen while also allowing the items on the menu to stay in the same location on the image.但是,我需要菜单上的项目和背景图像根据屏幕大小调整大小,同时还允许菜单上的项目保持在图像上的相同位置。

The code below is working, but with this code, I am having to create a new class for each new row of the menu.下面的代码正在运行,但是使用此代码,我必须为菜单的每个新行创建一个新的 class。 I know this is not the best way of creating this type of page.我知道这不是创建此类页面的最佳方式。

My current css is from the idea on this post: Positioning text over an image so that it always points to the same spot in the image even when resizing the browser我当前的 css 来自这篇文章的想法: 将文本定位在图像上,以便即使在调整浏览器大小时它也始终指向图像中的同一位置

Any help is appreciated.任何帮助表示赞赏。

 <div class="parent"> <table> <tr> <td class="box window">Snacks </td> <td class="box item1">Sausage Dog</td> <div class="box item1 price">3</div> <td class="box item2">Sausage Dog</td> <div class="box item2 price">3</div> <img class="img" src="menubackground.jpg" alt=""/> </tr> </table> </div> <style>.container { border: 1px solid red; width: 300px; height: 90px; } * { box-sizing: border-box; margin: 0; } img { max-width: 100%; display: block; width: 100%; height: 100%; background-size: auto; }.parent { position: relative; }.parent.box { position: absolute; width: calc(1.2vw + 15px); height: calc(1.2vw + 10px); display: -webkit-box; display: flex; -webkit-box-pack: center; justify-content: center; -webkit-box-align: center; align-items: center; }.parent.box.window { top: 15%; left: 8%; color: #ffc11c; font-size: 3vw; padding: 40px; text-shadow: 0px 4px 3px rgba(0,0,0,0.4), 0px 8px 13px rgba(0,0,0,0.1), 0px 18px 23px rgba(0,0,0,0.1); }.parent.box.item1 { top: 27%; left: 6.6%; color: white; font-family: 'Bahnschrift'; min-width: 12%; max-width: 9px; font-size: 2vw; text-shadow: 0px 4px 3px rgba(0,0,0,0.4), 0px 8px 13px rgba(0,0,0,0.1), 0px 18px 23px rgba(0,0,0,0.1); }.parent.box.item2 { top: 32%; left: 6.6%; color: white; font-family: 'Bahnschrift'; min-width: 12%; max-width: 9px; font-size: 2vw; text-shadow: 0px 4px 3px rgba(0,0,0,0.4), 0px 8px 13px rgba(0,0,0,0.1), 0px 18px 23px rgba(0,0,0,0.1); }.parent.box.item1.price { top: 27%; left: 20%; color: white; font-family: 'Bahnschrift'; font-size: 2vw; text-shadow: 0px 4px 3px rgba(0,0,0,0.4), 0px 8px 13px rgba(0,0,0,0.1), 0px 18px 23px rgba(0,0,0,0.1); }.parent.box.item2.price { top: 32%; left: 20%; color: white; font-family: 'Bahnschrift'; font-size: 2vw; text-shadow: 0px 4px 3px rgba(0,0,0,0.4), 0px 8px 13px rgba(0,0,0,0.1), 0px 18px 23px rgba(0,0,0,0.1); }.parent.box.light { top: 16%; left: 48%; color: #ffc11c; }.parent.box.pool { top: 90%; left: 50%; color: #ffc11c; }.parent.box.plant { top: 55%; left: 3%; color: #ffc11c; } </style>

I suppose you're trying to achieve something like this:我想你正在尝试实现这样的目标:

 * { box-sizing: border-box; margin: 0; }.parent { display:flex; width: 100%; height: auto; justify-content: space-between; background-image: url("https://s7g10.scene7.com/is/image/tetrapak/pouring-milk?wid=600&hei=338&fmt=jpg&resMode=sharp2&qlt=85,0&op_usm=1.75,0.3,2,0"); background-size: cover; background-position: cneter; }.parent table{ padding: 35px 10px; }.box { text-align: center; }
 <div class='parent'> <table class='snack'> <tr> <th class="box window">Snacks</th> <th class="box window">Price</th> </tr> <tr> <td class="box item1">Sausage Dog</td> <td class="box item1 price">3</td> </tr> <tr> <td class="box item2">Sausage Dog</td> <td class="box item2 price">3</td> </tr> </table> <table class='water'> <tr> <th class="box window">Drinks</th> <th class="box window">Price</th> </tr> <tr> <td class="box item1">Sausa</td> <td class="box item1 price">3</td> </tr> <tr> <td class="box item2">Sausa</td> <td class="box item2 price">3</td> </tr> </table> </div>

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

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