简体   繁体   English

覆盖设备宽度

[英]Override device-width

I'm working on a website and I'm trying to make it mobile friendly by including <meta name="viewport" content="width=device-width"> in my html. 我正在使用一个网站,并且正在尝试通过在HTML中添加<meta name="viewport" content="width=device-width">使其变得移动友好。

Unfortunately I have an element that needs to be larger then the device width. 不幸的是,我有一个需要大于设备宽度的元素。 I was going to use media queries to hard code values for this element on different screen sizes but it seems like I am not able to override the elements width. 我打算在不同的屏幕尺寸上使用媒体查询对该元素的硬编码值,但似乎无法覆盖元素的宽度。

This is the element whose width I want to override: 这是我要覆盖其宽度的元素:

<div id="menu_bar">

Currently the only way I can override this elements width is by doing: 目前,我可以覆盖此元素宽度的唯一方法是:

<div id="menu_bar" style=" width: 1024px;">

However if I do: 但是,如果我这样做:

<style>
    #menu_bar {width : 1024px;}
</style>
<div id="menu_bar">

it does not work. 这是行不通的。 Even adding !important does not work. 即使添加!important也不起作用。 I need to be able to do it the second way because I need to use media queries. 我需要能够以第二种方式进行操作,因为我需要使用媒体查询。

Just for reference I have the menu bar as a ruby on rails partial because on every page of my website. 仅供参考,我在菜单栏上使用了部分红宝石,因为在我网站的每个页面上。

Any idea how to override the width of the menu bar so I can use media queries? 任何想法如何覆盖菜单栏的宽度,以便我可以使用媒体查询吗?

Any help is greatly appreciated. 任何帮助是极大的赞赏。

Try going to http://atmedia.info/ -- it will scan your device (refresh to rescan it in portrait and in landscape) - it tells you a bit about media queries that match your device. 尝试访问http://atmedia.info/ -它会扫描您的设备(刷新以纵向和横向重新扫描)-它告诉您有关与设备匹配的媒体查询的一些信息。 Assuming you have not already solved your stuff yet. 假设您还没有解决您的问题。

This meta tag combo seems to help me.. and I use media queries to match devices in min-width and min-height (max as well) 这个meta标签组合似乎对我有帮助。我使用媒体查询以最小宽度和最小高度(以及最大)匹配设备

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="mobileoptimized" value="0" />

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

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