Need help in to load image into div without Stretch and Do scaling as well but using CSS.
i have already try few Examples but they are not working. below are those examples,
.img-contain {
width: 550px;
height: 220px;
overflow: hidden;
}
.myimage {
min-width: 100%;
}
<div class="img-contain">
<img src="http://wallpapers111.com/wp-content/uploads/2014/12/Beautiful-Scene-Wallpapers-Hd-1.jpg" class="myimage" />
</div>
This is what your code is saying right now.
Your image will have a minimum width of the image-contain which is 300px wide.
If you want the image to scale as well as keep it's aspect ratio try this code out;
.myimage{
width:100%;
}
Don't set the width of the img-contain to be a fixed width if you want it to scale with the size of the webpage.
If you are wanting a minimum width I would suggest using a media query, then setting a max-width: 100%; and height: auto; or your image will be distorted. This will make your page responsive.
.myimage { max-width: 100%; height: auto;}
#media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (orientation: portrait) {
}
}
That would be for mobile portrait. IPhone
#media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (orientation: landscape) {
}
}
Landscape and so on.
.myimage { max-width: 100%; height: auto;}
#media only screen {
and (min-device-width: 320px)
and (max-device-width: 480px)
and (orientation: portrait) {
}
}
#media only screen {
and (min-device-width: 320px)
and (max-device-width: 480px)
and (orientation: landscape) {
}
}
Related
Implemented a logo in the box, where width should be 100% if the image is in portrait or square orientation and width should be auto if the image is in landscape orientation.
You can use media queries for this
#media (orientation: landscape) {
img {
width: auto;
}
}
#media (orientation: portrait) {
img {
width: 100%;
}
}
Hope this may help you.
DEMO
#media (orientation: landscape) {
img {
width: auto;
}
}
#media (orientation: portrait) {
img {
width: 100%;
}
}
<img src="https://static.pexels.com/photos/371633/pexels-photo-371633.jpeg">
How could one go about creating a div, that would have a default size of XX%, however, if the screen gets too small it would switch into 100% size? I have tried using min-width property but the problem with this is that it will not be responsive after the min-width is reached and will overflow if the screen is even smaller.
You have to use #media queries. So let's say you have a <div> that should take up only 50% of the web page and then you need to show it full width once it enters mobile phone, say 640px width:
div {
width: 50%;
}
#media screen and (max-width: 640px) {
div {
width: 100%;
}
}
you must use #media for that like this :
#media screen and (min-width: 769px) {
/* STYLES HERE */
}
#media screen and (min-device-width: 481px) and (max-device-width: 768px) {
/* STYLES HERE */
}
#media only screen and (max-device-width: 480px) {
/* STYLES HERE */
}
You can do it with #media queries, e.g.:
div {
width: 50%;
height: 100px;
border: 1px solid;
}
#media (max-width: 568px) { /* adjust to your needs */
div {width: 100%}
}
<div></div>
so, I want to make a responsive loader (image). that the position always in the middle of the screen and the width always follow the size of the screen. So, I used #media only screen for do that, and now I have a problem to differentiate the size for ipad and ipad pro.
this is the code:
/*ipad portrait*/
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
.sp-conload img{
width: 100%;
height: auto;
margin-top: -330px;
}
}
/*ipad landscape*/
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
.sp-conload img {
width: 65%;
height: auto;
margin-top: -290px;
}
}
/*ipad pro portrait*/
#media only screen and (min-device-width : 1024px) and (max-device-width : 1366px) and (orientation : portrait) {
.sp-conload img{
width: 100%;
height: auto;
margin-top: -460px;
}
}
/*ipad pro landscape*/
#media only screen and (min-device-width : 1024px) and (max-device-width : 1366px) and (orientation : landscape) {
.sp-conload img{
width: 70%;
height: auto;
margin-top: -440px;
}
}
<div class="sp-conload">
<div class="sp-loader" >
<h2 id="anim9" class="frame-9"><span><img src="../img/loader/9.png"></span></h2>
<h2 id="anim8" class="frame-8"><span><img src="../img/loader/8.png"></span></h2>
<h2 id="anim7" class="frame-7"><span><img src="../img/loader/7.png"></span></h2>
<h2 id="anim6"class="frame-6"><span><img src="../img/loader/6.png"></span></h2>
<h2 id="anim5" class="frame-5"><span><img src="../img/loader/5.png"></span></h2>
<h2 id="anim4" class="frame-4"><span><img src="../img/loader/4.png"></span></h2>
<h3 id="anim10" class="frame-10"><span><img src="../img/loader/10.png"></span></h3>
</div>
</div>
the problem is, when I open with ipad it will use the ipad pro, but if I used !important in ipad size, when I open with ipad pro it will use the ipad size, because they have max-device-width : 1024px for ipad, and min-device-width : 1024px for ipad pro, and I think it clashed. any suggestion?
This code is the newer way to put an image in the center of the screen. However, some of the styles here are not supported by the older browsers. The good thing though is that you don't need all of those #media styles :)
.sp-conload img{
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
height: 100vh;
}
None of the solutions given previously in stackoverflow solved my problem. If anyone has solution to this, then please please please help me. I want: the horizontal scroll bar should appear when the browser is minimized and divs should not overlap each other
html code for header:
<header><label class="font_white">LIZA's World</label>
<nav>
<ul>
<li>hellohello |</li>
<li>HIHO |</li>
<li>Heyhey |</li>
<li>Ciao Ciao Ciao Ciao |</li>
<li><label class="nav_name">Liza</label></li>
<li>
<form id="search" method="get" action="hello.html" style="float:right">
<input type="text" class="searchbar" size="50" maxlength="120" value="Search..." />
<input type="button" class="search_button"/>
</form>
</li>
</ul>
</nav>
</header>
css code for header and nav:
html, body {
overflow-x:scroll;
}
header {
position: fixed;
height: 40px;
top: 0px;
width: 100%;
vertical-align: top;
background:#2748ab;
margin-left:-8px;
}
nav
{
position: fixed;
vertical-align: top;
margin-top:10px;
top: 0px;
float:left;
margin-left:23%;
width:76.5%;
}
I changed the nav as follows:
nav
{
position: fixed;
vertical-align: top;
margin-top:10px;
top: 0px;
float:left;
margin-left:320px;
min-width:1000px;
}
now the overlapping problem is solved but, the horizontal scrollbar problem is not solved yet.
If you measure the total outer width of the layout. and set the min-width of outer div or body. if resize the browser it shown horizontal scroll bar and alignment not varied.
Ex:
.outerdiv{min-width:1240px;}
or
body{min-width:1240px;}
You need to add media in CSS, understand how to add media into css and make your website responsive.
/*------------------------------------------
Responsive Grid Media Queries - 1280, 1024, 768, 480
1280-1024 - desktop (default grid)
1024-768 - tablet landscape
768-480 - tablet
480-less - phone landscape & smaller
--------------------------------------------*/
#media all and (min-width: 1024px) and (max-width: 1280px) {
.logo{
width:80px;
}
}
#media all and (min-width: 768px) and (max-width: 1024px) {
.logo{
width:80px;
} }
#media all and (min-width: 480px) and (max-width: 768px) {
.logo{
width:50px;
} }
#media all and (max-width: 480px) {
.logo{
width:100%;
}
}
/* Portrait */
#media screen and (orientation:portrait) {
.logo{
width:100%;
}
}
/* Landscape */
#media screen and (orientation:landscape) { /* Landscape styles here */ }
/* CSS for iPhone, iPad, and Retina Displays */
/* Non-Retina */
#media screen and (-webkit-max-device-pixel-ratio: 1) {
}
/* Retina */
#media only screen and (-webkit-min-device-pixel-ratio: 1.5),
only screen and (-o-min-device-pixel-ratio: 3/2),
only screen and (min--moz-device-pixel-ratio: 1.5),
only screen and (min-device-pixel-ratio: 1.5) {
}
/* iPhone Portrait */
#media screen and (max-device-width: 480px) and (orientation:portrait) {
}
/* iPhone Landscape */
#media screen and (max-device-width: 480px) and (orientation:landscape) {
}
/* iPad Portrait */
#media screen and (min-device-width: 481px) and (orientation:portrait) {
}
/* iPad Landscape */
#media screen and (min-device-width: 481px) and (orientation:landscape) {
}
You just need to check which resolution you want to make responsive and particular CSS into that media. You need to use more inspect element for testing. You also add responsive menu code. So your header will adjust perfectly.
I will suggest you to use https://webflow.com for developing responsive website. So you dont need to worry about responsive headache.
I am trying to make a simple webpage responsive but somehow, after the first breaking point, nothing happens. I put the whole code in this fiddle: https://jsfiddle.net/Cilvako/umwhLdqx/
Bellow are the breakpoints I am trying to use but still haven't got to the third since I couldn't make the second work.
/Media Query/
#media screen and (min-device-width : 1px) and (max-device-width : 480px) {
}
#media screen and (min-width : 481px) and (max-width : 768px) {
}
#media screen and (min-width : 769px) and (max-width : 1200px) {
}
#media only screen and (min-width : 1200px) {
}
Don't mix device-width with the normal width if you can. Simply use min-width and max-width if you're targeting only browser window size.
Read this if you're confused CSS media queries min-width and min-device-width conflicting?
You are supposed to write CSS in the media queries and also close and open them properly using '{' and '}' which you are not on the fiddle.
A media query looks something like
#media screen and (min-width : 769px) and (max-width : 1199px) {
h1 { color: blue; }
}
#media screen and (min-width : 1200px) and (max-width : 1800px) {
h1 { color: green; }
}
So between 769px and 1199px, h1s would be blue, and between 1200px and 1800px they would be green. I'm not seeing that in your JSFiddle - the brackets are not closed properly, and I can't see what you're trying to do with the rules.
You almost never ever ever need a max-width
fiddle
body {
background: gray;
}
#media screen and (min-width: 500px) {
body {
background: red;
}
}
#media screen and (min-width: 500px) {
body {
background: red;
}
}
#media screen and (min-width: 800px) {
body {
background: lightblue;
}
}
#media screen and (min-width: 1000px) {
body {
background: orange;
}
}
#media screen and (min-width: 1300px) {
body {
background: pink;
}
}