This is code for a two photos grid with a text hover. I want to make this grid responsive for mobiles and I'm stuck at rescaling code for photos.
This is my code
HTML:
<div class="plansgrid" align="center">
<div class="pic">
<img src="images/planssgrid/mcp.png" />
<div class="text">
<h1 style="font-weight: bold;">Medical Cash Plan</h1>
<p>Recrive Cashback to reduce the cost of your everyday medical expenses</p>
</div>
</div>
<div class="pic">
<img src="images/planssgrid/pcp.png" />
<div class="text">
<h1 style="font-weight: bold;">Personal Accident Plan</h1>
<p>Fracture benefits and cash lump sums from accidental injury</p>
</div>
</div>
</div>
CSS:
.pic {
display: inline-block;
position: relative;
max-width: 100%;
height: auto;
overflow: hidden;
}
.text {
position: absolute;
bottom: 0;
right: 0;
width: 100%;
height: 0;
text-align: center;
background: rgba(255, 255, 255, 0.7);
transition: height 0.7s ease-out;
color: darkgreen;
}
.pic:hover > .text {
height: 150px;
}
When I entry on website from a mobile, image is not scaled, is only croped. I want to scale this image, to fit for a mobile device.
Please help me with this.
Thank you very much :D !
Here you have a live preview of this grid: http://hciit.atwebpages.com/
Try adding this to your css, to make your image responsive:
.pic img {
width: 100%;
}
in your situation I think the ideal way to do it would be to resize the image and have it saved in many different sizes so on mobile it won't download it full resolution. then you can use a css trick to resize it based on resolution like this
you can read some more about it here CSS Tricks
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
#media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
#media only screen
and (max-width : 320px) {
/* Styles */
}
/* iPads (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
#media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
/* Desktops and laptops ----------- */
#media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
#media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
#media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
Related
I have a twitter bootstrap 3 application and the SVG logo looks great in Desktops but looks truncated in the mobile browsers e.g. iOS Safari.
My very standard code looks like this:
<!-- RD Navbar Brand-->
<div class="rd-navbar-brand brand">
<a class="brand-name" href="/"><img src="images/logo.svg" height="100"></img></a>
</div>
Is there a way, for example, to reduce the logo size in case of mobile device detected?
you can use media queries like this:
/* Large desktops and laptops */
#media (min-width: 1200px) {
.my-logo {
width:300px;
}
}
/* Landscape tablets and medium desktops */
#media (min-width: 992px) and (max-width: 1199px) {
.my-logo {
width:250px;
}
}
/* Portrait tablets and small desktops */
#media (min-width: 768px) and (max-width: 991px) {
.my-logo {
width:200px;
}
}
/* Landscape phones and portrait tablets */
#media (max-width: 767px) {
.my-logo {
width:150px;
}
}
/* Portrait phones and smaller */
#media (max-width: 480px) {
.my-logo {
width:100px;
}
}
I have this issue where my media queries are messing up on my iPhone and iPad, my tablet media query is targeted on my iPhone so the layout on mobile is all wrong.
I have already checked my ordering of the media queries, and they are from smallest to biggest since as I styled the page starting from mobile view first.
.career-feature-icon {
width: 100%;
height: 300px;
padding: 10px;
#media screen and (min-width: 37.5rem) {
float: left;
width: 50%;
}
#media (min-width: 64rem) {
width: 25%;
}
img {
width: 200px;
height: 200px;
display: block;
margin: 0 auto;
}
h2 {
text-align: center;
#media (min-width: 64rem) {
padding-top: 20px;
}
}
}
My styling is there, but it is overruled by whatever is in the 37.5rem media query.
Again this is ONLY on iOS devices, any help is greatly appreciated!
SOLVED: I changed my media query from REM to px 37.5rem -> 600px 64rem -> 1024px and it rendered the way it should
/*
##Device = Tablets, Ipads (portrait)
##Screen = B/w 768px to 1024px (48rem to 64rem)
*/
#media (min-width: 768px) and (max-width: 1024px) {
//CSS
}
/*
##Device = Tablets, Ipads (landscape)
##Screen = B/w 768px to 1024px
*/
#media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
//CSS
}
/*
##Device = Low Resolution Tablets, Mobiles (Landscape)
##Screen = B/w 481px to 767px (30.065rem to 47.93rem)
*/
#media (min-width: 481px) and (max-width: 767px) {
//CSS
}
/*
##Device = Most of the Smartphones Mobiles (Portrait)
##Screen = B/w 320px to 480px (20rem to 30rem)
*/
#media (min-width: 320px) and (max-width: 480px) {
//CSS
}
Try this might work
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;
}
Media queries for CSS class
am using .CSSTableGenerator as a css class for table. how to use Media queries for this CSS class file only?
/* Smartphones (portrait and landscape) ----------- */
#media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
body {
padding: 0;
margin: 0;
width: 320px; }
}
/* iPads (portrait and landscape) ----------- */
#media only screen and (min-device-width: 768px) and (max-device-width: 1024px) {
body {
//width: 495px;
}
}
#media only screen and (max-width:992px){
}
#media only screen and (max-width: 400px){
}
Use Like this keep Grater size first than lower
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.