Html css layouts- Web Mobile suppoort - html

I have a page set out similar to this:
My question is about mobile support and how should I go about doing the following:
When the user resizes the window to about the size of a smartphone screen, I want to remove the main content, which is everything below the header area/login, and keep only the header, the login form and the footer. So I have been using css media queries to do this. My problem is that my login form markup resides within the header area.
<div id = "header">
<div id= "logo"><img src =""/> </div>
+-------form markup here------+
|<div id= "login-form">..... </div>|
+ ----------------------------+
</div>
<div id= "main-content">
This is where I want to put the login form
</div>
So my question is, How should I do this?
should I just create another css file and link/apply that when the screen width-height is detected to be smartphone size ?
Should I create the markup block inside main-content, and set its css style display to none UNTIL the screen is resized to smartphone size, where a media query is set to change display attribute ?
What is the best way to accomplish this? I greatly appreciate any help and at least, some little explanation to justify that answer. Also links and other references are very welcome !
Cheers..

Use Media Queries to hide and show content based on device or device width/height.
Here's a good Media Queries Cheat-sheet:
http://stephen.io/mediaqueries/
I wouldn't position the form as 'absolute' and put it outside the header as another poster suggested. This is super sloppy and bad practice. What's the 'absolute' form going to be positioned too? The body? Aghh. You'd need a wrapper - and that's just more code. You can do it all via CSS. Just use Media Queries to change the CSS styles for the header, show/hide elements, and reposition.
OR
JQUERY (Not the best route, but for what you want you're a limited without a redesign). I kept it simple for easy explanation. Note, I haven't tested this:
$(window).resize(function(){
var maxwidth = $(window).width(); // get device window width
var form = $('#login-form'); // form
if(maxwidth <= 320) { // 320 px or whatever you want
form.clone().appendTo('#main-content'); // clone form and append to main content
form.eq(0).hide(); // hide first form, the one in the header
}
else {
form.eq(0).show(); // show initial form
form.eq(1).remove(); // remove cloned form, if set
}
});

I can see two ways you could go about accomplishing your goal:
Take your login-form out of the header div, put it in the main-content div and absolutely position it to make it appear inside the header when on a desktop screen, then use a media query to move it to below the header for viewing on mobile devices.
Use your idea of having two login-forms: one in the header, and one in the main-content area. Use media queries to change the display attribute so that the correct login-form is showing at the right time depending on the screen size. I'm not sure if duplicating the login-form is good practice, so I would try option 1 to start.
Let me know if this works out!

Related

How to target one widget on my Wordpress homepage without effecting other sections?

I am having trouble changing the styles of a widget on my Wordpress site.
The one I am targeting is the bottommost one on the homepage: http://rfm-inc.com. It is the section of the page that reads "Proud member of the Mitsubishi Materials family of companies"."
The styles seem to be mainly applied to the ID ".content", but I'd like to alter those styles ONLY at the ".text-3" level.
I can change the content stylings and get the effect I want in the widget, but it changes all of the other widgets.
I want the bottom widget to fully span the page (ie, full blue background, centered text, resizing and wrapping text at smaller screen widths), but to leave the other sections alone.
Any tips on how to target this widget independent of the other sections?
Usually wordpress widgets have a their own style css file in wp-content/plugin and the name of the plugin.
Anyway if you open the developer tools on the web browser and you click on the element you want to change, you will figure out which selector to use.
Make some test on the developer tool and then make the changes on your files.
In this EXACT CASE you can do it with:
.widget:last-child {
/* your rules */
}
As this is the last child of the section id="main".
Or use its ID:
#text-3 {
/* your rules */
}
Okay. I solved it. Let's see if I can explain.
First, I changed the #content container to:
body.home #content.col-full {
max-width: 100% !important;
}
This of course expanded the full container.
Then I was able to style individual widgets as needed.
It was the more parent element that needed styling, then everything else flowed from there. But it was hard for me to target, since I:
Didn't know how to target only the home page (body.home)
Didn't see that the container was #content
Didn't realize that the easiest thing to do was to adjust the container and to style the contained widgets separately

What is the best way to load HTML content based on device?

I have two different div element (one for desktop and other for mobile) which have to be loaded based on the device accessing my website. What is the best way to do this? I do not want to check the user agent since it gets updated often.
Right now I'm using css media queries to find the device specs and hide / show the corresponding div. The problem is, I'm loading both the divs irrespective of the device. I only want to load the corresponding div.
Furthermore, re-sizing the desktop browser to the size of mobile should load the mobile div. What is the best way to do this?
Thanks.
If you can use JavaScript (and jQuery ), you can manage to load the content based on the width of the devise. The basic idea is something like this:
index.html
<body>
<div id="content">
<!-- content will be loaded here based on the width of the devise -->
</div>
</body>
phone.html
<div>
This file is for small devices
</div>
pc.html:
<div>
This file is for large devices
</div>
JavaScript in index.html:
function loadcontent(){
var BreakPoint = 480; // pixcel
if($(window).width() < BreakPoint){
file = "phone.html";
}else{
file = "pc.html";
}
$("#content").load(file);
}
loadcontent();
$(window).resize(function () {
....
loadcontent();
....
});
The above code is just the basic concept.
To handle the window.resize events smoothly, there are several functions to be implemented. If you would like to see the codes of that part, I will update my answer.
hope this helps.

dynamically show/hide content based on window width

I am building a website and I need it to behave so that if the window is fullscreen (or any size where width > X px) - it should show the sidebar. If the user resizes the window's width below a certain amount, the sidebar should disappear (display:none).
A prime example to look at is google's news page (news.google.com) - there is a right sidebar which is only visible when the width of the page is above a certain threshold.
I'm usually pretty good in searching google/stack exchange and finding the answer I need, but in this case, maybe it's because of the use of the word 'dynamic' but I can't think of any other way to phrase it, i'm getting a lot of hits which are not what I need.
If I were to think of a solution on my own, I would perhaps add a javascript listener which constantly monitors the x value of the 'viewable area' and have a function constantly running that would do something like, if viewable area X value is lower than my threshold, change the style of my sidbar div to display:none. I think that would work, but I don't know if it's the best way to do this.
Thank you.
What about max-width Media Queries?
#media screen and ( max-width: 768px ) {
/* When the viewport is 768px or less,
hide #sidebar */
#sidebar {
display: none;
}
}
Demo: http://jsfiddle.net/jonathansampson/6Pvyt/show/
For IE6-8, https://github.com/scottjehl/Respond
I believe CSS Media Queries is the best solution as answered already by Jonathan Sampson,
but as youve hinted at it in your question about using a javascript listener I thought I best explain a better (IMO) JS solution using jQuery's on event.
e.g.
jQuery(window).on({
"resize": function(){
if(jQuery(window).width() > 750) {
//code to show sidebar
jQuery(#sidebar).removeclass("hidden");
} else {
//code to hide sidebar e.g.
jQuery(#sidebar).addclass("hidden");
}
}
};
});
What you need is CSS Media queries. http://www.w3.org/TR/css3-mediaqueries/
I use Twitter's bootstrap framework which includes a whole slew of responsive screen functionality.

tinymce, image resize, use css instead of <img width & height>

I use this wonderful tool, tinyMCE, for editing pages at my website.
But i have a problem with the resizing of images.
Is it possible to change the way tinyMCE changes the size of the image?
Now the software changes the width and height inside the ..
<img src="..." width="..." height="..." />
But this setting gets overridden by the CSS.
(I have some general img settings in the CSS, width, height:auto, and centering on page.)
If the users define a size for the image, i want this new size to override the general css.
But with the img parameter width & height. this is notpossible. CSS override their value.
So.
I want tinyMCE to change the size of the image by CSS. Is this possible?
ex:
<img src="..." style="width:...;height...;" />
(The size is set by draging the corner of an image to the size you want.. and not edited in html html code.)
Thanks for reading.
Matte
I bypassed this by adding a plugin in the project that handles the re-size event.
Just going to post it here in case someone ever needs it.
tinymce.PluginManager.add('imageresizing', function(editor, url) {
editor.on('ObjectResizeStart', function(e) {
if (e.target.nodeName == 'IMG') {
var selectedImage = tinymce.activeEditor.selection.getNode();
tinymce.activeEditor.dom.setStyle(selectedImage,'width', e.width);
tinymce.activeEditor.dom.setStyle(selectedImage,'height', e.height);
selectedImage.removeAttribute('width');
selectedImage.removeAttribute('height');
}
});
});
Of course you need to add the plugin to tinyMCE which is beyond the scope of this question, but it's not hard at all.
To solve the problem of getting the default image insert size to fit the container, i used
content_style: 'img {max-width: 100%;}'
Inside the tinymce.init({
It doesn't appear to be currently possible to easily change the way TinyMCE adds width and height tags to the img element. There is a feature request open to add this functionality Stop Prepopulating Image Dimensions.
$("#ctl00_ContentPlaceHolder_RichTextBox_ifr").contents().find("body").find("img").attr("height", "150");
$("#ctl00_ContentPlaceHolder_RichTextBox_ifr").contents().find("body").find("img").attr("width", "200");
Here "#ctl00_ContentPlaceHolder_RichTextBox_ifr" is id of textarea..
With this you can resize the image .. .. ..Sarath#f1

CSS tabs wrap around right side of DIV with text transformation (rotatation)?

I would like to have tabs on the top of a page and if there is not enough room for those tabs, the tabs would then wrap around that DIV and would be text-transformed to rotate 90 degrees. My page is a CSS liquid design that is flexible based on window size. I would not like to use images since the tab text will be populated from a database. Below is a screenshot of would I would like to accomplish. I am also using PHP so, I could build some IF/THEN statements if needed. I would prefer to not use Javascript.
If window is open wide, display as:
If window is open narrow, display as:
I would like to use Listamatic (http://css.maxdesign.com.au/listamatic/horizontal05.htm) and somehow update it to allow for this new wrapping effect with text transformation. Is this possible?
Here is part of the CSS that might work:
.sidetabs {
-moz-transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
}
Update: 12/13/2011: CSS - Force a child DIV to expand page width?
Minitech: Thank you for the insight and the Javascript example. In an effort, to solve my tab issue, I thought I might try another approach.
I am working on an editable navigation. The user can add many tabs across the top as they wish. In the event that there are many tabs that would force the set of tabs to be broken/wrapped to the next line, I would like to force it on 1 line even if this means that the page width would grow immensely.
Is there a way for a child DIV to expand a page width even if the content is in a wrapper? In my JS Fiddle link below, I have a simple wrapper page with a right sidenav. I am using Listamatic tabs (http://css.maxdesign.com.au/listamatic/horizontal05.htm) for the top. As you can see, the tabs are breaking into many rows of tabs and it doesn't look great. Can I use some CSS to force the DIV to not wrap onto a 2nd or 3rd line? I would like the DIV to be liquid based on the number of tabs (and length of the text in the tab text). Any ideas?
http://jsfiddle.net/zenfiddle/yUPCC/3/
Well, as far as I know, that's completely impossible using CSS, as well as using PHP, since it's a server-side scripting language. You'll need to use JavaScript in this instance, and of course make sure you degrade gracefully all the same.
A simple way might be to check for wrapping elements using offsetTop. Something like this (you'll have to adjust for positioning if you use that):
var navigation = document.getElementsByTagName('nav')[0].getElementsByTagName('a'); // Or however you want to do this
var i, element;
for(i = 0; element = navigation[i]; i++) {
if(element.offsetTop > 0) {
// It's a wrapping element
element.className = element.className ? element.className + ' side-tab' : 'side-tab';
}
}
Then, you can style nav a (for example) and nav a.side-tab however you need.