I am trying to place icons for mobile web app using css.
However I am having some problem with this.
I set outer box and placed icon there which I thought would be good for different devices since they have different size
Below is my code but I am not seeing the icons
Am I missing anything here?
This is my html
<link rel="stylesheet" type="text/css" href="/mobile_pages/main/main_page.css"/>
<br>
<div id="siteMenu">
</div>
This is my css
#siteMenu{
position: relative;
width: device-width;
height: device-height;
}
.icon{
background-size: cover;
width: 80px;
height: 80px;
}
#intro_icon{
position: absolute;
background-image: url('intro_icon.png');
top: 50px;
left: 0px;
}
#direction_icon{
position: absolute;
background-image: url('direction_icon.png');
top: 50px;
left: 90px;
}
#pic_icon{
position: absolute;
background-image: url('pic_icon.png');
top: 50px;
left: 180px;
}
when I give specific px for width and height in #siteMenu, I can see the icon.
However, I want it to be device width and device height.
I tried 100%, auto value for width and height but still didn't work.
what should I do here?
Just tried your code in jsFiddle, with google logo, it is working fine.
Can you make sure the path of your icons is right, so in the same folder as your CSS?
Make sure the ccs file is well referenced, and the < link> tag must be in the < head> tag of your page?
#intro_icon{
position: absolute;
background-image: url('http://upload.wikimedia.org/wikipedia/commons/8/87/Google_Chrome_icon_(2011).png');
top: 50px;
left: 0px;
}
for device-width and device-height, they are media-query parameters not css attributes. Also you need to set up html and body tag full page :
html{
width: 100%;
height: 100%;
}
body{
min-height:100%;
padding:0px;margin:0px;
}
#siteMenu{
position: relative;
width: 100%;
height: 100%;
height: 100vh;
min-height:100%;
}
JsFiddle, Note that vh is not supported by all browsers (e.g IE8)
Related
In my program, I need to place the image of a button on top of another image exactly where that button is supposed to be. To be able to use it in different monitor resolution, I position the images using %. I also set up height and width of the body (or div) to 100vw and 100vh (i also tried to screen.height and window.height). But when I change resolution of the monitor, the images adjust to the new resolution but now with enough precision y the height (width is fine). The button is displayed a little bit higher in a lower resolution. Why is not working?
.alarm img {
position: fixed;
width: 4.5%;
left: 41.7%;
top: 71%;
}
.faceplate img {
position: fixed;
width: 17%;
left: 40%;
top: 40%;
margin-left: 0px;
margin-top: 0px;
}
<html>
<body style="width:100vw; height:100vh; margin:0;padding:0">
<div_logo class="faceplate"><img src="pictures/asel3_faceplate.png">
<div_alarm class="alarm"><img src="pictures/asel3_alarm.png"></div_alarm>
</div_logo>
</body>
</html>
You should use media queries to fix this problem for different screen sizes. You have to create different types of CSS for different types of screen sizes.
In this fact, you have to go to media queries.
For more details, you can follow the link
https://www.w3schools.com/HOWTO/howto_css_media_query_breakpoints.asp
In media, query defines your CSS style for different screen sizes.
I hope this is what you are expecting.
.faceplate {
top:25%; /* just change this */
left:25%; /* just change this */
position: absolute;
}
body {
height: 100vh;
width: 100vw;
margin: 0;
position: relative;
padding: 0;
}
.faceplate {
top: 25%;
left: 25%;
position: absolute;
}
.faceplate > img {
width: 90%;
height:90%;
}
.faceplate .alarm {
position: absolute;
top: 0;
}
.faceplate .alarm > img {
width: 70%;
height: 70%;
}
<html>
<body>
<div class="faceplate"><img src="https://dummyimage.com/100x100/e055e0/fff">
<div class="alarm"><img src="https://dummyimage.com/80x80/000/fff"></div>
</div>
</body>
</html>
https://imgur.com/PghL7ON
E1, E2, E3, E4 are UI elements and they will have eventually a hover effect on them. I also have a background image.
Here is what I was able to achieve so far.
<div class="bg">
<img src="bg.jpg" id="bg_id">
<div class="ui">
<img id="ui-elem1" src="ui-elem1.png">
</div>
</div>
and in the CSS part I have:
body {
overflow: hidden;
margin: 0 ;
}
.bg {
position: relative;
width: 100vw;
height: 100vh;
}
#bg_id {
position: absolute;
width: 100%;
height: 100%;
}
.ui {
position: relative;
width: 50vw;
left: 10vw;
top: 75vw;
}
/* 20% of ui */
/* 20% width 4 images = 4*20 = 80% padding = 6.6% */
#ui-elem1 {
position: absolute;
width: 20%;
height: 100%;
padding: 6.6%;
}
My code displays the background image fine, it resizes and it's always proportional to the viewport. But alas, when it comes to the UI I can't see the first UI element there. What to do?
Thank you.
EDIT: Here's a jsfiddle for it. https://jsfiddle.net/vq24a76p/1/ Doesn't show it proportionally to the viewport.
For this you could use background-image property an set the size to cover just like the example...
FIDDLE
.bg {
background-image:url('https://media.mnn.com/assets/images/2014/07/Mount-Fuji-Japan-Wintertime.jpg.1000x0_q80_crop-smart.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size:cover;
}
Another approach if you want to use an image tag, is to set the width:100% and height auto, the caveat in this is that some vertical images will have a blank space at the bottom...
So I have my media queries set to have an element positioned "X" pixels relative from the previous element at a min-width of 756px (the resolution of my iphone 6S). On my windows desktop, I positioned the element to where I want it to be. However, when I open the site up on my iphone (using the default Safari browser), the element is off by over a hundred pixels! The element is positioned higher on my iphone than it shows on my desktop. Any ideas? I checked my zooms on my desktop browser and they are all set to 100%.
edit: Here is a fiddle mockup of my code. https://jsfiddle.net/8f6y1pdx/1/
<header>
<div id = "navContainer"><h1>Hello</h1></div>
<div id = "backgroundImage"><img src = "http://cdn.wallpapersafari.com/4/18/laMvrx.jpg" width = "2560" alt = "bg image"></div>
</header>
<body>
<div id = "contentOneContainer">Container one</div>
<div id = "contentTwoContainer">Container two</div>
</body>
and the css
html, body{
padding: 0;
margin: 0;
}
#navContainer{
position: fixed;
z-index: 0;
width: 100%;
background-color: black;
color: white;
height: 100px;
text-align: center;
}
#backgroundImage{
position: fixed;
z-index: -2;
}
#backgroundImage img{
width: 100%;
max-width: 2560px;
}
#contentOneContainer{
width: 100%;
height: 500px;
background-color: blue;
position: relative;
top: 417px;
z-index: 0;
color: white;
}
#contentTwoContainer{
width: 100%;
height: 250px;
background-color: gray;
position: relative;
top: 417px;
z-index: 0;
color: white;
}
/*----------------------------------*\
Responsive
\*----------------------------------*/
#media (min-width: 757px){
#contentOneContainer{
background-color: red;
}
}
If you adjust the screen size, at 757px I have the background color of the container switch. Basically, on my desktop, I am lining up the bottom of the image with the top of the first container. When viewed on my iphone 6s (I don't know how to make this work when viewing the fiddle on mobile) the bottom of the image and the top of the container are a hundred plus pixels apart. I hope this helps a little. Also, sorry if my code blows.
Add viewport meta tag in the head section for the media queries to work on mobile.
http://getbootstrap.com/css/#overview-mobile
I can't seem to center my navigation or footer in IE8.
I had to float my navigation just to get the dimensions to show correctly in IE8.
I'm using divs for the footer and nav because I know this language isn't going to be translated in IE8 and I'm still having issues. Below is the CSS that I am using for my footer, which works fine in Firefox and Safari. Also, I need this to be stationary so it somehow needs to involve margin: 0 auto; my issue can be viewed at http:www.vslateart.com/index.html (homepage alignment)
.footer {
display: block;
margin-left: auto;
margin-right: auto;
width: 200px;
}
Is there any sort of workaround so that this can translate to IE8?
Similar question: Using "margin: 0 auto;" in Internet Explorer 8
Your code looks perfectly valid.
Are you missing a doc type at the top of your page? Without the DOCTYPE, IE automatically goes into Quirks rendering mode.
<!DOCTYPE html>
Failing that - have you set the width of your parent to be greater than the width of .footer?
this code center a div to center (fiddle):
.footer {
display: block;
margin: 0 auto;
width: 200px;
}
I think you want to do this
.footer{
position: absolute;
display:block;
width: 200px;
margin-left: -100px;
left: 50%;
}
This should do the trick!
margin-left shoud be negativ and the width/2
so margin-left = (-1)*(width/2)
The position could be relative(may work better)
EDIT
I use this code to center my homepage
position: absolute;
width: 1000px;
min-height: 100%;
margin-left: -500px;
left: 50%;
This will make then window center until the window is 999px wide then it will missmatch.
Then use something like this
#media only screen and (min-width: 1000px){
div.screen-size-wrapper{
position: absolute;
width: 1000px;
min-height: 100%;
margin-left: -500px;
left: 50%;
}
}
#media only screen and (max-width: 999px){
div.screen-size-wrapper{
width: 100%;
min-height: 100%;
}
}
Tell me if this dosen't work :)
EDIT - This works for your webpage (i tried it)
Paste this in you container css
margin-right: auto;
width: 1200px;
margin-left: -600px;
left: 50%;
position: absolute;
I want to place a small circular login image on the border of div such that half image will be outside the border line just for style purpose?I think I have to set z-index but how OR is there any better way?
Thats exactly what you need to do.
Give you img a class name. Then in your style sheet add something like this
#classname
{
position: absolute;
z-index: 10;
top: #distance from top of page#
left: #distance from left of page#
}
z-index needs to be a number greater than your div which will have an index of 0 if you haven't changed it.
Hope this helps.
.overout {
text-decoration:none;
position: relative;
z-index: 10;
top: 105px;
right: -25px;
}
You can do this very easily using divs. Consider the following code
<html>
<head><title>Logo test</title></head>
<body>
<div style="position: relative; width: 400px; height: 100px; margin: 0px auto 0px auto; top: 50px; background-color: #f00;">
<div style="position: relative; height: 100px; width: 100px; background-color: blue; left: 20px; top: -50px;">
</div>
</div>
</body>
</html>
All you have to do is replace the second divs "background-color" property with the "background-image" property and nest that div inside your existing div. Make sure you make the div the exact size of your logo and set background-repeat: no-repeat;
Hope that helps. Test the example code I posted. You can place all the style information into a css class like this:
.logo
{
background-image: url(yourlogo.png);
background-repeat: no-repeat;
width: /* width of logo */
height: /* height of logo */
top: /* distance from top */
left: /* distance from left */
}