Text over image not showing in mobile browser - html

so I placed some links (text) over an image and in desktop browsers everything is working just fine, however, once you open it in a mobile browser, the text is not showing up. Here's my css:
#header {
width: 100%;
position: relative;
}
#dm {
top: 0;
left: 0;
right: 0;
width: 100%;
height: 100%;
}
#logo {
position: absolute;
top: 5%;
left: 18.8%;
width: 13.5%;
height: 64.8%;
background-color: transparent;
border: none;
}
h2 {
position: absolute;
top: 59%;
left: 21.7%;
width: 78%;
}
h2>a {
color: #f6f6f6;
font-size: 1.3vw;
font-variant: small-caps;
font-weight: lighter;
font-family: "Times New Roman", Times, serif;
text-decoration: none;
text-shadow: #000000 10% 10% 20%;
margin-right: 1%;
}
And HTML code:
<div id="header">
<img src="header.png" border="0" id="dm">
<a id="logo" href="index.html"></a>
<h2>Domů O nás Web & Grafický design Digitální kresba Pro firmy Ostatní služby Portfolio Faq Kontakt</h2>
</div>
Does anyone know how to solve this issue?

The font size you have set for the links is font-size: 1.3vw;, which means they will appear at 1.3% of the viewport width.
For desktop browsers with screen width of at least 1000px, it will show up as at least 13px which is totally fine.
For a mobile browser, if your device screen is 640px wide, it will only appear as ~8px which is way too small, which is probably why you couldn't see it. Besides, most mobile devices have width of between 320px and 400+px if viewed at portrait mode, so that makes the text even smaller.
When I put it at the fiddle, I thought there was no text until I placed a grey placeholder image. You should have used em instead of vw for the font size if you want to scale it.

Related

How to stop text from moving away from position when resizing?

I'm fairly new to coding, have been at it for a few hours for a month now. For the past few hours I've been stuck with the problem that can be seen in the two pictures I attached. I've tried searching for answers and various methods such as min-width, display:flex, adjusting the font-size from autoscaling with vw and using rem. I just want my text to stay inside of the laptop screen no matter what screen size I'm viewing it on. I know I could use the easy way and just photoshop the photo with the text but I want to learn how to do it with coding for future projects as well. I do want the picture to scale a bit so it can be viewed on for example a phone in an ok size. Can you help me please?
body {
margin: 0;
text-align: center;
}
h1 {
color: #66BFBF;
font-family: "Dancing Script", Verdana, Geneva, Tahoma, sans-serif;
font-size: 5vw;
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%, -50%);
}
.top-container {
background-color: #ccf2f4;
padding-top: 50px;
position: relative;
}
.laptop {
width: 50%;
height: 50%;
}
<section>
<div class="top-container">
<img class="laptop" src="img/laptop.png" alt="cloud-img">
<img class="top-cloud" src="img/cloud.png" alt="cloud-img">
<h1>I'm Nhien</h1>
<h2 class="dreamer">just a gamer with big dreams.</h2>
</div>
</section>
You can also access the website from www.nhienweb.com
You should add the image to the background of the section or the div.
For this answer, I am adding it to the section background.
<section>
<div class="top-container">
<img class="top-cloud" src="img/cloud.png" alt="cloud-img">
<h1>I'm Nhien</h1>
<h2 class="dreamer">just a gamer with big dreams.</h2>
</div>
</section>
In the HTML, I have removed the laptop img from html and will add it in the css. I will position the cloud as absolute.
And here is the css for this code
body {
margin: 0;
text-align: center;
}
h1 {
color: #66BFBF;
font-family: "Dancing Script", Verdana, Geneva, Tahoma, sans-serif;
font-size: 5vw;
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%, -50%);
}
.top-container {
background-color: #ccf2f4;
padding-top: 50px;
position: relative;
}
.top-cloud {
position: absolute;
top: 0;
left: 0;
/* Positioned it relative to the top-container */
}
section {
background-image: url([your path to img relative to the css file]);
background-size: cover;
/* bg size to cover makes it what you want gives it full width at any screen */
}
If this doesn't help comment and ask me.
I applied this code to the CSS so it is working now. Don't think that this is the correct way to solve the problem but it seems fine when I tested my website on my mobile. Thanks for your trouble and time!
#media (max-width: 591px){
h1{
top:30%;
}
}

My text moves up and down when my browser resizes

I have been working on a new homepage for my website, but
I can't figure out why text moves up and down when I resize
my browser.
My CSS Code:
.welcome {
width: 100%;
height: 60px;
background-color: #4CAF50;
margin-top: -4px;
}
.welcome h1 {
font-family: 'Lato', sans-serif;
color: white;
font-size: 40px;
margin-bottom: 20px;
margin-top: 5px;
margin-left: 15px;
}
.welcome p {
color: white;
overflow: hidden;
float: left;
position: relative;
top: -50em;
}
#welcome-background {
width: 100%;
height: auto;
max-height: 1000px;
margin-top: -16px;
min-height: 500px;
}
If you see any other CSS error's please let me know
My HTML:
<div class="welcome">
<h1 style="float:left;">About Us</h1>
<img id="welcome-background" style="" src="/new_homepage/img/black-bg.png">
<p style="color: white; position: relative; top: -50em;">Hardwire Studios' is a gaming community that has servers am a variety of games, such as Minecraft, Garry's Mod, Counter-Strike: Global Offensive, Rust, and many more coming in the future. We try to provide the best "Lag-Free" experience on all of our server, yet also make them as fun and enjoyable as they can be, by only using the best of the best host companies. You can also see our future plan's by simply scrolling down a little more, until you find the "Future Plan's" Section.</p>
</div>
Your paragraph uses relative positioning, which means it is still in the flow of the document. Because it comes after an image, its vertical position changes as the height of the image changes.
Instead. put the image and paragraph inside of a wrapper element that is positioned relatively, then position the paragraph with absolute positioning.
This could look something like this:
HTML:
<div id="welcome-wrapper">
<img id="welcome-background" src="...">
<p>Hardwire Studios' is...</p>
</div>
CSS:
#welcome-wrapper {
position: relative;
}
#welcome-wrapper p {
position: absolute;
top: 10em;
}

CSS Text over image (width 100%) without absolute position

I have an image with width 100% so that it enlarges with the window's size. How can I place texts over it so that they enlarge in the same proportion as the image does?
HTML:
<div class=instructables>
<h1>
I N S T R U C T A B L E S
</h1>
<img src="http://i.imgur.com/QvCRbHp.jpg" width="100%"/>
<div class=projects>
9
</div>
</div>
CSS:
.instructables {
margin-top: 150px;
margin-bottom: 200px;
margin-left: 150px;
margin-right: 150px;
letter-spacing: 2px;
line-height: 2;
font-size: 15px;
position: relative;
}
.projects{
position: absolute;
top: 140px;
left: 285px;
font-size: 350%;
font-family: Georgia, Serif;
color: #424242;
}
I tried using position: absolute; and obviously it doesn't work as the text just stay in the same place even if the image is enlarged.
Thank you!
Update: So basically I have this section on my website
http://i.imgur.com/q5kaxMM.png
with a jpg (robot and words) and numbers. When I enlarge the window, the jpg enlarges, but the numbers stay the same (in terms of size and position)
http://i.imgur.com/4nhdnl2.png
My goal is to make the entire section looks exactly the same as the 1st image, no matter how I enlarge the window.
Definitely need some media query love here. I'd suggest starting with some basic styles and add as needed. These can get you started, you can add as many as you like and adjust as you like.
#media screen and (max-width: 480px) {
.projects {font-size: 15px;}
}
#media screen and (min-width: 800px) {
.projects {font-size: 25px;}
}
#media screen and (min-width: 1200px) {
.projects {font-size: 40px;}
}
You were quite close with the position: absolute;. I think the best you can do, is position the text (.projects) with percents. That's way it's not locked on a fixed, pixel position.
Have a look: https://jsfiddle.net/v1u01md3/1/
It's not foolproof, for example when you make the screen really small. But that could be fixed with some media queries.
Have you tried using mediaqueries to adjust your text position/size?
Here is a good overview: https://developer.mozilla.org/de/docs/Web/CSS/Media_Queries/Using_media_queries
You can use background-image instead img and put a text over without position: absoulte like this:
#wrapper {
position: relative;
width: 100%;
height: 300px;
background: url('path/to/img') no-repeat top;
background-size: cover;
text-align: center;
}
jsFiddle
The idea to make that work is that you have to include inside an element with position relative all elements with position absolute.
Here is a working example modifying your code. HTML here:
<div class="instructables">
<div class="projects">
<h1>
I N S T R U C T A B L E S
</h1>
<img src="http://i.imgur.com/QvCRbHp.jpg" width="100%"/>
<span>9</span>
</div>
</div>
and the CSS here:
.instructables {
letter-spacing: 2px;
line-height: 2;
font-size: 15px;
position: relative;
}
.projects{
position: absolute;
top: 140px;
left: 285px;
font-size: 15px;
font-family: Georgia, Serif;
color: #424242;
}
h1
{
position: absolute;
}
span
{
position: absolute;
}

HTML / CSS Display fixed ratio images based on the height of the page

There is probably a relentlessly simple solution to this but I've been chasing my tail for a while so I've come to ask those wiser and smarter than me.
I've got a website for a personal project I'm making which displays images within a lightbox. See image:
The header area (red) is fixed height.
I want the images (yellow) to sit within a light box (green) which also has a caption. Crucially the images displayed need to retain their aspect ratio, 5:4, and fill the remaining height left below the header (bar a small margin top and bottom).
There's probably a really simple, elegant solution out there but I've not found it.
Any help gratefully received.
EDIT ---
Here's a fiddle of what I'm trying to do: http://jsfiddle.net/qh2V8/
Even this isn't right as I've had to put a fixed width in to even try and get it to work.
CSS:
#header{
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 145px;
background-color: #F00;
}
#overlayBg {
position: fixed;
top: 155px;
bottom: 20px;
padding: 8px;
padding-bottom: 30px;
left: 0px;
right: 0px;
margin-left: auto;
margin-right: auto;
background: #FF0;
width: 400px;
}
#overlayContainer img {
position: relative;
height: 100%;
width: 100%;
}
#overlayBg p {
position: relative;
padding-top: 8px;
padding-bottom: 10px;
font-family: 'Josefin Sans', sans-serif;
font-weight: 600;
font-size: 14px;
}
HTML:
<div id="header"></div>
<div id="overlayBg">
<div id="overlayContainer">
<img src="http://i.imgur.com/u9VIg60.jpg" />
</div>
<p>Caption</p>
</div>
The image size need to be set through scripting, unless the images are a fixed constant size. The following link is of good help to your problem: Change image size with JavaScript
I'm pretty sure that you can get the original size of the image through yourImg.Style.Height and yourImg.Style.Width, and then make the calculations required to make it a 5:4 picture..
Here's where I got to.
There are fixed ratio solutions if you are basing the size of the element on width, using :before and padding-top. There's a good write up here.
There is a fixed ratio solution if you are basing the size of the element on height, however the height must be a % of the height of the screen. Written up here in another Stackoverflow question:
Resize a Div Based on Height but Retain Aspect Ratio (almost got it) Strange Reload bug
If you have a fixed pixel size header or footer and need an element to expand to fill the exact size remaining you can't do it with just HTML and CSS.
Here's a codepen.io of where I got to:
http://codepen.io/niazipan/pen/ydkGt
JS to set the image height, and CSS to style everything else around it. Code below:
HTML
<div id="overlayBg">
<div id="overlayContainer">
<img src="http://i.imgur.com/u9VIg60.jpg" id="yourImgId" />
</div>
<p>Caption</p>
</div>
CSS
html, body {
height: 100%;
text-align: center;
}
#header{
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 50px;
background-color: #F00;
}
#overlayBg {
position: fixed;
top: 55px;
padding: 8px;
margin-left: auto;
margin-right: auto;
background: #FF0;
position: relative;
text-align: left;
}
#overlayContainer {
height: 100% !important;
width: 100%;
}
#overlayBg p {
font-family: 'Josefin Sans', sans-serif;
font-weight: 600;
font-size: 14px;
margin-top: 5px;
margin-bottom: 5px;
}
JS
var size = window.innerHeight - 120;
document.getElementById('yourImgId').style.height = size + 'px';
document.getElementById('overlayBg').style.width = size * 1.25 +'px';

responsive design css button over background-image, fixed position issues while resizing

I am writing a responsive webpage that has a background image and a button over it. The button needs to be at a specific position on the image. Now I am creating a div with the background-image (different for mobile, tablet and desktop breakpoints) and I create a css button on the image. The problem comes when I resize the window, within the same breakpoint, the background-image resizes but the css button is placed w.r.t the parent container of the background div and thus moves.
The code snippet looks like
<div class="imgContainer">
<a href="/gotohere.html">
<span class="goto_btn">Click here</span>
</a>
</div>
the css code for mobile breakpoint looks like
.imgContainer {
background-image: url("mobile.jpg");
height: 18em;
width: 100%;
background-repeat: no-repeat;
background-size: cover;
clear: both;
position: relative;
}
.goto_btn {
bottom: 3.5em;
font-size: 15px;
right: 4em;
background-color: #1867C3;
border-radius: 10px;
color: #FFFFFF;
display: block;
float: right;
font-family: Helvetica Neue,arial,sans-serif;
font-weight: 700;
margin-top: 75%;
padding: 10px 58px;
position: absolute;
text-shadow: 2px 1px #000000;
text-transform: uppercase;
}
Now I can create such css rules for tablets and desktop similarly and it looks fine but the issue comes within the same breakpoint, lets say mobile, for different screen-size say iphone 5 and galaxy S4 screen, the position of goto_btn is not fixed although its placed position:absoulte; w.r.t the imgContainer which is position:relative;
Can I somehow position the goto_btn fixed with the imagConatainer div so that any resizing within the breakpoint keeps the relative position of button fixed with respect to the background-image ?
Any help will be hugely appreciated.
Thanks
i based the your buttons position according to your .imgContainer width and height tag
.imgContainer {
background-image: url("mobile.jpg");
height: 18em;
width: 100%;
background-repeat: no-repeat;
background-size: cover;
clear: both;
}
.goto_btn {
font-size: 15px;
background-color: #1867C3;
border-radius: 10px;
color: #FFFFFF;
display: block;
font-family: Helvetica Neue,arial,sans-serif;
font-weight: 700;
padding: 10px 58px;
position: absolute;
top:16em;
right:2em;
text-shadow: 2px 1px #000000;
text-transform: uppercase;
}
was able to get it working, to most parts by
(a) changing background-size: 100% 100% in imgContainer and
(b) proving bottom, left and right in % values in goto_btn
This did streteced the background-image in some edge cases (like galaxy note 3) but for most parts, it worked fine. Depends on the size of the image(jpg) for each breakpoint.