Images fixed position despite resolution - html

On my website I would like to have several images across the width of my page. When I am on my laptop (resolution: 1366x768) there's 7 image next to each other. When I test it on my smartphone there's 5 images next to each other and when I test it on a screen with resolution 1920x1080 there's 7 and some space open. What I want to do is get the middle 5 to always show on the screen (as this is my menu) and always in the middle of the screen. When the resolution gets changed, more or less images will appear on both sides.
In conclusion:
When on smartphone: 5 pictures.
When on laptop (normal screen): 7 pictures.
When on HD-screen: 9 pictures.
And always the 5 middle ones on the same position.
This is what I've got:
Html:
<div id="head-container">
<!--<div id="head-film"></div>-->
<div id="head-roll">
<div id="head-table">
<table>
<tr id="headTable">
<td>
<img src="./files/img/frame1.png"/>
</td>
<td>
<img src="./files/img/frame2.png"/>
</td>
<td>
<img src="./files/img/frame3.png"/>
</td>
<td>
<img src="./files/img/frame4.png"/>
</td>
<td>
<img src="./files/img/frame5.png"/>
</td>
<td>
<img src="./files/img/frame6.png"/>
</td>
<td>
<img src="./files/img/frame7.png"/>-->
</td>
</tr>
</table>
</div>
</div>
</div>
css:
div#head-table{
z-index:2;
position:absolute;
}
I have tried to seperate the table in 2 tables and let them each take 50% of the screen with a margin of 50% like this:
div#head-table-left{
width:50%;
margin-right:50%;
}
div#head-table-right{
width:50%;
margin-left:50%;
}
But when the resolution changes, the left table will stick to the left side of the screen.
Is there a way to solve this? Or something completely different? Thanks!

If you keep them all in one container (BTW, I'm not sure a table is ideal for content that's not actually tabular data: for a menu, a <ul> with the <li>s set to float:left or display: inline-block is a better HTML structure. But back to your question…) :)
I recommend keeping all the images in the same block and using 2 media queries to hide certain elements as the screen gets smaller.
#media screen and (max-width: 960px) {
#headTable td:nth-child(1),
#headTable td:nth-last-child(1) {
display: none;
}
}
#media screen and (max-width: 600px) {
#headTable td:nth-child(2),
#headTable td:nth-last-child(2) {
display: none;
}
}
I'm just using 600px and 960px as estimates: change those to whatever screen widths fit your design. Quick caveat: CSS nth-child selectors and media queries both work on IE 9+ and all other browsers. On older browsers, If you have to support lower browsers, you'll need a fallback solution - but only for widescreen IE7 / widescreen IE8, which are both pretty rare.

Related

Make a DIV responsive in a non-responsive site.

I have a div in my non-responsive site which contains an ad with 120x600 pixels. I want to make the div float always at the right of the screen. For desktop or large devices it is ok But When in the Smaller device then as the site is non responsive so when site loads the div become very small. If the site would responsive then in a device of width about 400px it would cover almost all the portions of the screen. I need to do that in my non-responsive site. This is for the ads higher click through rate. A example div is -
<div id="float_rightad" style="position:fixed; top:15%; right:0;width: 160px; height:600px; z-index:5000;">
<div style="position:absolute; left:-5px; margin-top:0px; z-index:15;">
<a href="Javascript:void(0);" onclick="document.getElementById('float_rightad').style.display='none'"><img src="http://secretdiarybd.com/wp-content/uploads/2015/05/close.gif.png" alt="close" height="20"></img>
</a>
</div>
<div>
<script data-cfasync="false" type="text/javascript" src="//www.sparkadsmedia.com/adscript/120x600_english.js"></script>
</div>
</div>
How can i do that in my site?
You can probably achieve it by putting additional CSS3 statement in a style block like the following and also use a relative width (%) for your ads (wherever is possible):
<style type="text/css">
#media screen and (orientation: landscape ) and (max-width:400px ) {#float_rightad { YOUR STYLE PERTINENT TO SMALL SCREEN}}
#media screen and (orientation: portrait ) and (max-width:400px ) {#float_rightad { YOUR STYLE PERTINENT TO SMALL SCREEN}}
</style>
If your add contains the img element, then you can specify the image width relative (in %) to the container div; otherwise, consider using iframe element.
Hope this may help.
Best regards,

How to get rid of spaces on mobile version

Currently in my style.css file I am using certain designs only for the mobile version of my website.
Here is the beginning tag:
#media only screen and (min-width : 150px) and (max-width : 780px)
I want to be able to set it up so that when the site is on a mobile device it does not use the &nbsp that is shown below, I want to only use &nbsp in the full desktop. Is there a way to handle this in a css file?
<td colspan="2" style="font-size: 16pt;">
Home
All Products
</td>
If you want to use CSS for that. Then on the desktop site you would have to write the HTML as this
<td colspan="2" style="font-size: 16pt;">
Home
All Products
</td>
cannot be removed dynamically using CSS. JavaScript can handle these events, but CSS is not designed to handle this.
This way you can control the space between the elements using CSS. Now in the media style, you can remove this margin.
#media only screen and (min-width : 150px) and (max-width : 780px) {
td a:nth-child(2) {
/* second a */
margin-left: 0;
}
}
I think there are two possible solutions:
Use margins instead of since the non-breaking space is protected and cannot be removed via CSS. You could apply margin:0 3%; or something alike to the anchors.
Wrap that s by a span: <span class="spacer"> </span> and apply display:none when on mobile.

Adjusting elements with css according to the browser size

So I have html page like this:
I'd want to make it so that when I resize my browser or use it on a machine with different resolution the images and buttons would adjust accordingly. I guess their width should be in relationship with the browsers size somehow.
And I also want the buttons to remain in the oder listed above not that they go under each other when I resize (
At the moment the following happens:
As you might notice the map part adjusts well but I can't figure out why the buttons wont.
Here's my index.html file part:
<div class=wrapper">
<div class="toolbar">
<a href="" onclick="touch('football')"><img alt="Football"
src="images/iconsB/football.png" class="toolbarButton" /></a> <a
href="" onclick="touch('basketball')"><img alt="Basketball"
src="images/iconsB/basketball.png" class="toolbarButton" /></a>
###and so on until the end of icons###
</div>
<div class="loginbar">
<div>
<a href="#logged-in-box" class="loggedin_button"
onclick="touch('addingplaces')">Add places</a>
</div>
<div id="loggedinbutton">
<a href="#login-box" class="login-window"
onclick="showLoginForm('a.login-window')">Log in</a>
</div>
</div>
And here's my css http://pastebin.com/0DGMfnmh
Any ideas where to start? Thanks in advance!
You are looking for CSS Media Queries. With Media Queries you are able to declare CSS rules for specific resolutions only.
If you assign a class to every image, you are able to set the width of the images through media queries. Here is a quick example:
The HTML:
<img src='#' class='icon'>
<img src='#' class='icon'>
<img src='#' class='icon'>
The CSS:
/* Default rule */
.icon {
width: 64px;
height: auto;
}
/* Rules for horizontal screen resolution <= 800px */
#media (max-width: 800px) {
.icon {
width: 48px;
}
}
/* Rules for horizontal screen resolution <= 600px */
#media (max-width: 600px) {
.icon {
width: 32px;
}
}
Have a look at this link it shows you some of the basic with what you can do with media queries if you want them to wrap so going onto separate lines I would follow #Michal 's advice

Text position moving around on different sized monitors

Here's my code:
<div class="swd-layout-cell layout-item-2" style="width: 100%">
<p>
<img width="450" height="400" alt="" src="images/new.jpg" style="float: left;margin-right:20px" class="">
</p>
<h5>CloudMoV</h5>
<h6>Mobile users can import a live or on-demand video to watch from any video streaming site. </h6>
<h6>Invite your friends to watch the video concurrently. </h6>
<h6>Chat with your friends while enjoying the video.</h6>
<br>
</div>
The image appears on the left with the text on right of it. But on different sized monitors the text placement is varying.On one monitor the placement was correct and on another the text was appearing below the image.
How can I fix this?
This is being caused by width: 100%;.
HTML:
<div class="swd-layout-cell layout-item-2" style="width: 100%;">
So you have this as your container, it will strech 100% of the screen. In the demo mess around with the size of the window and you will see the text move around.
This is because when the window is lets say 500px, the image is taking up 400px. So your text is trying to get into 100px worth of space.
DEMO HERE
You can set a min-width that will stop the cotainer from getting to small so it will not squash the text.
HTML:
<div class="swd-layout-cell layout-item-2" style="width: 100%; min-width: 700px;">
So here you can see we set a min-width, this works fine as it will just stop the container from getting to small.
DEMO HERE
Another option is to use media tags. Now these are used to help design sites for all kind of resolutions.
CSS:
div {
width: 100px;
height: 100px;
}
#media screen and (min-width: 1080px) {
div {
background: blue;
}
}
#media screen and (min-width: 487px) and (max-width: 1079px) {
div {
background: green;
}
}
#media screen and (max-width: 487px) {
div {
background: red;
}
}
So this is a quick demo to show you what they do. It uses the different CSS based from the size of the screen. So using this with your code can allow you to customise the layout depending on the size of the screen.
DEMO HERE
<div class="swd-layout-cell layout-item-2" style="width: 100%;">
<p style="clear:both;">
<img alt="" src="images/new.jpg" style="float: left;margin-right:20px; width:50%; max-width:450px;" class="">
</p>
<h5>CloudMoV</h5>
<h6>Mobile users can import a live or on-demand video to watch from any video streaming site. </h6>
<h6>Invite your friends to watch the video concurrently. </h6>
<h6>Chat with your friends while enjoying the video.</h6>
<br>
</div>

CSS/HTML - Hide images on mobile phone and use an alternate text

I currently have a page that generates a table from an SQL database using PHP, including one column that contains images. Due to us now having to work on a mobile platform, I'm looking for a way to hide the images. I'm currently using display: none on an antiscreen.css file, but as the images are links, it doesn't show the links
For clarity, when the image is on a PC browser it appears like this:
<td>
<a href="link to image source:>
<img height=80 alt='Text I want to display' src="link to image source" />
</a>
</td>
And when on a mobile the image, link and text are hidden using the display:none method.
So how would you recommend I work this out?
I would probably do this:
<td>
<a href="link to image source:>
<img height=80 alt='Text I want to display' src="link to image source" />
<span class="mobileonly" src="link to image source">Text I want to display</span>
</a>
</td>
Then I would set span.mobileonly { display: none; } on the main stylesheet and span.mobileonly { display: inline; } in antiscreen.css. The advantage is that the mobile link will also be easy to style.
Another option, which works for all screen sizes under a certain nr. of pixels is to use a media query, basically similar to the above one but with the advantage that it works on any screen size smaller than the defined number of pixels.
/* Media Query for mobile */
#media screen and (max-width: 480px) {
/* This resizes tables and images to be 100% wide with a proportionate width */
/* Hide stuff on mobiles */
table[class=emailnomob],td[class=emailnomob],img[class=emailnomob],span[class=emailnomob]{display:none !important;}
/* Additional Media Query for tablets */
#media screen and (min-width: 480px) and (max-width: 1024px) {
/* Hide stuff on tablets */
table[class=emailnomob],td[class=emailnomob],img[class=emailnomob],span[class=emailnomob]{display:none !important;}
This should covers both mobile and tablet devices.
Code courtesy of .net email tutorial. I only stripped the parts you don't need.
Usage:
<img class="emailnomob" height=80 alt="Text I want to display" src="link to image source" />