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,
Related
How do I code my website so that my 100% width images adjust size according to different screen resolutions? For e.g. 1280 x 720.
Here is the link to my home page with the images that need resizing according to screen resolution. Look at Lines 119 to 123 for image codes.
You have put a height of 700px+ on your images using the img in css. Add another class in css saying:
.full-width-img{
width:100%;
height:auto;
display:block;
}
Add class="full-width-img" to your images you want to have 100% width.
EDIT
Remove the width qnd height from your img tags. BEcause right now they are:
<img src="images3/motoxmaxres.jpg" class="full-width-img" width="100%" height="" alt="motocross landing">
While it should be
<img src="images3/motoxmaxres.jpg" class="full-width-img" alt="motocross landing">
As we need to define an image with amp-img tag for an amp page, the problem is with the responsive nature of those image.
For example:
<p align="center"><amp-img width="400px" height="200px" layout="responsive" src="https://xyx.com/abc.png"></p>
Now if the master div is 600px then, the image will get stretched out to 600px (more than its normal 100%), but for a mobile device with master div being 300px , the image will adjust the height and will be perfectly fine as it will get contained in the 300px div stretching it to 100% won't make effect.
Also, layout cannot be set to fixed because it will then stretch out of the mobile display.
What's the solution?
If you have dynamic width of the image and want to handle this situation than go to this link : https://ampbyexample.com/advanced/how_to_support_images_with_unknown_dimensions/ and read "Fixed-Height Layout with correct Aspect Ratios" section.
It will help you to implement amp-img when you do not know the image width and do not want the image to be get stretched.
You can do like this :
CSS
<style amp-custom>
.magic-img { max-width:400px; margin: 0 auto;}
</style>
HTML
<div class="magic-img">
<amp-img width="400" height="200" layout="responsive" src="https://xyx.com/abc.png"/>
</div>
I'm trying to resize pictures on an responsive website using transform:scale in CSS. I want to keep the aspect ratio. So I created two classes for the . The two classes are according to weather the picture is landscape or portrait.
My HTML:
<img class="landscape" src="" width=100%; height=100%>
<img class="portrait" src="" width=100%; height=100%>
My CSS:
img.ladscape { transform:scale(0.745,0.671);}
img.portrait { transform:scale(0.671,0.745);}
The landscape picture gets right scaled.
The portrait format one does not get scaled right.
Where is my mistake?
I also want an third class for square-format pictures.
Thanks for your help.
-Cevin
The problem is that you set width and height that point to the area of the display dimension .
If you remove them you can see the difference
img.quer {
transform:scaleX(0.745) scaleY(0.671);
}
img.hoch {
transform:scaleX(0.671) scaleY(0.745);
}
<img class="quer" src="https://www.w3schools.com/css/trolltunga.jpg" >
<img class="hoch" src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSobAPMeqgsRtHrX8vclVHPggkhqcSt0q1ixhyokNq3Wa16TGF6Mp34Cjo" >
https://jsfiddle.net/dqypm8yh/
Because the width of the screen is bigger than height (on monitor) the landscape will scale better
I have this webpage where there is an image on top and paragraphs on its right and bottom. This is the CSS I am using (sorry the CSS is directly in the HTML, I have to do this)
<div style="float:left" class='wrapper'>
<img border="0" src="images/about.png" style="float:left;margin-right:2em;margin-bottom:2em">
<p style="text-align:left;line-height:14px;margin:0px 0px 14px;padding:0px"><font color="#444444" face="trebuchet ms, sans-serif" size="3">Lorem ipsum here...</font></p>
<p style="text-align:left;line-height:14px;margin:0px 0px 14px;padding:0px"><font color="#444444" face="trebuchet ms, sans-serif" size="3">Lorem ipsum here...</font></p>
</div>
It seems to work fine even in mobiles. But I wanted to see the image centered at the top of the page when it's displayed in a mobile or tablet (smaller screens). Currently the image is close to the left side of the page when I open the website in a mobile. I wanted it aligned to the center of the page.
The picture below shows how I wanted it to be displayed in large screens and in mobiles (note that this is not exactly what happening now. the second image is what I want to achieve, but at the moment the image is closer to the left margin, and not aligned to the center)
Oh, and I can only use CSS. Is it possible?
Thank you all!
You will need to use media queries in a CSS file.
This will add properties for screens with a width lower than 640px for example.
#media screen and (max-width:640px){
img{
float:none !important;
display:block;
margin-left:auto !important;
margin-right:auto !important;
}
}
However you have to to remove float:left from the HTML and put it in a css file, otherwise the inline-style will override the media query
If you really can't modify the HTML. You should write float:none !important; in the media query write but it's a bad pratice to use !important
Update
Live example http://jsfiddle.net/7d3Lv/2/
Try resizing the Result box
First time user, with a simple but frustrating problem.
I am a new web coder, designing my website (austinwoehrle.net)
I am trying to make the banner of Seattle scale with my darker background, but if I zoom in, it breaks out of the div.
On smaller monitors the image will be too large to fit in the darker background.
I have already set the width to 100% and have tried a lot of trouble shooting!
Thanks for the help!
Again, my website is http://www.austinwoehrle.net/homepage.html
At the moment you have this:
<div id="seattle" alt="test">
<img src="seattle.jpg" width="620" height="210">
</div>
Change the width of your image to width="100%". This may then be slightly wider than you want it, so you will want to add margin or padding to the containing seattle div on line 126 of mystyle.css
width:80%;
margin:0 10%;
Then alter your image to have a width of 100% and remove the height.
<img src="seattle.jpg" width="100%">
Notes
margin:0 10%;
//is equal to writing
margin-top:0;
margin-right:10%;
margin-bottom:0;
margin-left:10%;
Check out this site for information on how to write this.