Dynamic Website Width [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
These days people are using various screen sizes to view websites. I need to figure out how to set up a dynamic website width which can automatically change with the screen size. I created a website with 1200px wide. The website and the content is too big for my laptop screen. But it is more suitable with my other monitor due to it is big in size. Can I adjust that width to change dynamically with the monitor size of the user?

You can use CSS media queries for this. (note: older versions of browsers won't support)
Media Queries is a CSS3 module allowing content rendering to adapt to conditions such as screen resolution (e.g. smartphone screen vs. computer screen).
More specifically, it will look at the following:
height and width of the device height and width of the browser
screen resolution orientation of the device (for mobile phones and
tablets; portrait or landscape)
CSS2 allows you to specify stylesheet for specific media type such as screen or print.
Now CSS3 makes it even more efficient by adding media queries.
You can add expressions to media type to check for certain conditions and apply different stylesheets. For example, you can have one stylesheet for large displays and a different stylesheet specifically for mobile devices.
It is quite powerful because it allows you to tailor to different resolutions and devices without changing the content.
Example:
The following CSS will apply if the viewing area is smaller than 600px.
#media screen and (max-width: 600px) {
.class {
background: #ccc;
}
}
If you want to link to a separate stylesheet, put the following line of code in between the <head> tag.
<link rel="stylesheet" media="screen and (max-width: 600px)" href="small.css" />
Multiple Media Queries:
You can combine multiple media queries. The following code will apply if the viewing area is between 600px and 900px.
#media screen and (min-width: 600px) and (max-width: 900px) {
.class {
background: #333;
}
}
Device Width:
The following code will apply if the max-device-width is 480px (eg. iPhone display). Note: max-device-width means the actual resolution of the device and max-width means the viewing area resolution.
#media screen and (max-device-width: 480px) {
.class {
background: #000;
}
}
Also this is a good article to read on resolution specific stylesheets on css tricks

Related

Different desktop and mobile view - what approach is the best?

I got a WWW website project where mobile version is the same as mobile app but "desktop" version is completely different. Different nav, different cards, views divided in different way..
What is the best approach to do this in PHP/Laravel and HTML/CSS/JS? I'm asking about general approach.
Thank you in advance.
K
This should be done through css using media queries by doing this you can control the cards sizes and views depending on the device size. You can find more information https://www.w3schools.com/css/css_rwd_mediaqueries.asp
The 'trick' I use for that is using a different css stylesheet.
You can set a min and max for your css styles, f.e.:
#media (max-width: 600px) {
//put css here for very small screens
}
#media (min-width: 601px) and (max-width: 1024px) {
//put css here for medium sized screens
}
#media (min-width: 1025px) {
//put css here for large screens
}
Note that this only works if your html stays the same over all screens and the layout is only defined by different css. But in certain situations this is a possible approach.
But differences are huge and in my opinion using only CSS is not enought. Changing size of elements and position in grid is obvious and exist in all projects. This is some kind of edge case.
For example on desktop I have user profiles in one view with 2 sections but on mobile I have two dedicated subpages.
In desktop I have normal menu in nav bar but on mobile each view have on top and bottom contextual buttons.
In desktop some things are in modal but in mobile in separated subpage or as a appearing text label (simple status).
...and so on

How do I make my website change size for different screen sizes?

I'm currently updating my website and I would like everything to automatically change size to fit browsers, mobile and desktop alike, while keeping the same ratio.
What is the best way to do this?
I've tried several methods but haven't managed to get any working, the pictures at the bottom of the page and the javascript at the top are causing the biggest problems.
I'd prefer a html/css option, but if there's a better way through javascript I'm fine with that.
Here is link to my subdomain I'm using for testing:
http://www.beta.trinity-international.com/
Thanks!
Please go with RWD (Responsive Web Design) approach using CSS3 media queries.
Media query:
Media query is a CSS technique introduced in CSS3.
It uses the #media rule to include a block of CSS properties only if a certain condition is true.
Syntax
#media (min-width: 700px) { ... }
Reference :
https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
Responsive frameworks :
There are some frameworks that can be used for creating RWD.
Twitter Bootstrap http://getbootstrap.com/2.3.2/
Foundation http://foundation.zurb.com/
Skeleton http://getskeleton.com/
Some things to keep in mind for responsive web design
Viewport:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
A <meta> viewport element gives the browser instructions on how to control the page's dimensions and scaling.
Media query:
Media query is a CSS technique introduced in CSS3.
It uses the #media rule to include a block of CSS properties only if a certain condition is true.
For example if you want your website with different sizes for differnt screens :
#media only screen and (max-width: 1500px) {
html, body {
margin-left:2%;
margin-right:2%;
}
}
#media only screen and (min-width:1501px) {
html, body {
margin-left:5%;
margin-right:5%;
}
}
This does not change size but just the margin that increases for bigger screen sizes.
For more explanation on responsive check this link w3schools

Responsive Wordpress Page [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Hi i have the following website :http://mall-haine.ro/
I can't figure it out how to make it resize for the Mobile devices.
Could you help me pls?
i have tried to use CSS like
#media screen and (max-width:480px) {
}
and i don't understand what should i write there..
First of all, the bit:
#media screen and (max-width:480px)
means what follows inside the braces will apply only on devices with screens less than or equal to 480px (i.e. mobiles, when they are no bigger than that). So inside the braces you put CSS that you only want to apply to such mobiles.
It's perfectly standard CSS (apart from being inside this extra pair of braces), but is intended to override what you have already specified for larger screens. And in order to override the large screen stuff, it must go after the large screen stuff. So:
div.sidebar {
color : red;
border : 1px solid blue;
}
#media screen and (max-width:480px) {
div.sidebar {
color : green;
}
}
The default CSS now says that, for all screens, the sidebar div will have a red font, and blue border.
But for mobiles up to 480px, you have said don't use a red font, use green instead. But you've said nothing about border in the media query, so that will remain blue on mobiles same as for desktops.
So the media query only holds CSS rules where you want a different style from what you specified for the default. The most common use of a media query is where you have boxes of content side by side on desktops, usually in floated divs. There's no room for that on the mobile, so you would specify float:none; inside a media query for smaller screens (which could use a min-width that takes in tablets as well as mobiles). The float:none forces the divs to show one below the other instead of side by side, so the content will be much larger and more readable on the small screen.
I hope this explains things well enough for you to get started. Experiment with that, then for futher info Google for media queries.
Try this:
#media screen and (max-width:480px) {
body { font-size:0.7em; }
}
Also, read here

How to edit a HTML theme's mobile version?

I have downloaded a free HTML template from web and i'm trying to edit this HTML theme. In my theme i changed background photo, it's good on my computer and my resolution (1366x768) but on mobile and other resolutions it's not working well. Background image is crushing.
please visit that website with your computer and your mobile phone for understanding clearly. Theme link
and please help me to edit mobile version of this website. I couldn't find anything. Here's the list of my javascript files in theme folder. image of files
What you can use is a media query the syntax of which looks like so:
#media <What to respond to> {
//then place the elements, class and id here
}
The media query can take in width by doing #media (max-width:<insert width here>) or #media(min-width:<insert width here>)
Multiple media queries can be used together like so #media (max-width:100px) and (min-width:50px).
Another class of media queries can be used to specify how behave depending on the type of device, they include but not limited to:
tv
screen
handheld
all
They are used by typing #media <name of device>
An Example with some of they things i have mentioned being used
#media screen and (max-width: 100px) and (min-width: 50px) {
//If the device is a screen, is wider/equal to 50px but smaller
//than or equal to 100 then it will do this
img {
width: 75px;
height: 30px;} }
#media screen and (max-width: 400px) and (min-width: 101px) {
//I'm sure what will happen but i will tell you anyway
//If the device is a screen, is wider than/equal to 101px but
//smaller than/equal 400px
img { //Something
}}
My suggestion is to read up on it take a look here
There are many ways to solve your problem. One way is change the background using media queries. This is done by editing your css file. If you have multiple css files, you will need to know which one is setting your background image and place the media queries in there.

Web Design fluidity [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I'm looking for someone to steer me in the right direction. I have a functional web page that runs crisply on my 13" MacBook. The issue is viewing the web page at different sizes and how the elements get distorted. What kind of things need to be done to ensure it looks crisp and beautiful on any screen size. Does it require me to use percentages when detailing height and widths of elements or does it require some javascript.
I realize this is broad and all im looking for is someone to steer me towards what should be changed so I can get the site live.
Thanks!
General direction:
You want to check out media queries to make your design responsive to different viewing media. You will want to consider other meta tags such as ones defining the viewport size, but in general you can do it all with CSS.
Here are example queries that can wrap your custom CSS rules for each device size:
/* Smaller than standard 960 (devices and browsers) */
#media only screen and (max-width: 959px) {}
/* Tablet Portrait size to standard 960 (devices and browsers) */
#media only screen and (min-width: 768px) and (max-width: 959px) {}
/* All Mobile Sizes (devices and browser) */
#media only screen and (max-width: 767px) {}
/* Mobile Landscape Size to Tablet Portrait (devices and browsers) */
#media only screen and (min-width: 480px) and (max-width: 767px) {}
/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */
#media only screen and (max-width: 479px) {}
Obviously you will want to fill-in the CSS rules as needed to ensure your content doesn't get scrunched.
A good strategy is to design for small mobile application, then go bigger from there. That way you don't find yourself trying to cram way. too. much. into a small interface.
In general you can also use the float:left; property for your main layout blocks (instead of absolute positioning, etc) That way your sidebar, etc will float above/below your main content when the parent element is too narrow to have both side-by-side.
Also, yes. You can use percentages, etc to fill areas fluidly. Use background- properties instead of <img> tags. Hope that helps.
I guess you may take bootstrap as a refer!
It is responsive, and will display almost the same on different resolution screen!
So try something like this.
and if you want to make your site looks like the same on all screen, try precentage!(but not suggested!)
You will need css3-mediaqueries for responsive designs or fluid designs
We Can assign different stylesheets depending on browser window size.
You must know How to use CSS Media Queries & Using Available Space
Have a go here
What are CSS Media Queries
and how to implement them.
too
I thought of not editing my answer any more, but i have got some good points to change my mind From http://www.webmonkey.com/2011/06/tips-tricks-and-best-practices-for-responsive-design/
Use #media to scale your layout for any screen, but remember that
this alone isn’t really responsive design.
Use liquid layouts that can accommodate any screen size. Don’t
simply design one look for the iPhone/Android, one for tablets and
one for the desktop. Keep it liquid, otherwise what happens when
some new, intermediate screen size suddenly becomes popular?
Roll your own grids based on the specifics of your site’s content.
Canned grid systems will rarely fit the bill. The problem with
canned grids is that they don’t fit your unique content. Create
layouts from the content out, rather than the canvas (or grid) in.
Start small. Start with the smallest size screen and work your way
up, adding #media rules to float elements into the larger windows of
tablet and desktop browsers. Start with a narrow, single-column
layout to handle mobile browsers and then scale up from there rather
than the other way around.
Use the Respond or CSS3 Media Queries JavaScript libraries to
bootstrap #media query support into older browsers that won’t
otherwise know what to do with it. Starting with the smallest screen
and working your way up means it’s the desktop browsers that need to
handle #media, make sure older browsers work by using polyfills like
Respond.
Forget Photoshop, build your comps in the browser. It’s virtually
impossible to mock up liquid layouts in Photoshop, start in the
browser instead.
Scale images using img { max-width: 100%; }. For very large images,
consider using something like Responsive Images to offer the very
smallest screens smaller image downloads and then use JavaScript to
swap in larger images for larger screen.
Embrace lazy loading. There may be items on your site, auxiliary
content that’s nice to have, but not essential. Load that content
using JavaScript after the primary content is done loading.
Forget about perfect. Even with these suggestions you’re still
leaving out users who have old browsers with JavaScript disabled.
Such users are increasingly rare and if they see the mobile layout
on their desktop, guess what, it’s not the end of the world. Your
site is still perfectly usable.

Categories