Jump to content

Recommended Posts

Ok - gotta be a brain-malfunction but the following code is not doing what I want.

 

I have a menu with a block of anchor tags. I want to enlarge the font on mobile devices and I have this JS function:

 

elems = document.getElementById('menu_box2').getElementsByTagName('a');
for(var i=0; i<elems.length; i++)
{
	elems[i].style.marginBottom = "25px";
	elems[i].style.fontSize = "32px";
}
which is executed to enlarge the font as well as to add some spacing. Well - the margin reset works fine, but the font is not working.

 

What am I forgetting here?

Edited by ginerjm
Link to comment
https://forums.phpfreaks.com/topic/305607-re-set-anchor-text-size/
Share on other sites

Your code seems fine as posted. The margin doesn't apply unless the items are set as display: block; or display: inline-block, but you say that is working so I am assuming you have that setup. The only reason I can think of why the font size might not be applied is if you have another rule somewhere that is marked as !important overriding it.

OK - help me out on my first venture into media queries. Please.

The css that I added does not work as I've set it up.

 

The css is:

	@media (max-width: 500px)
	{....
The settings under that media label do not happen. Nor does this bit of testing code.

 

	// Create the query list.
	var test_val = '500px';
	var test_str = 'max-width: ' + test_val;
	var mediaQueryList = window.matchMedia("(test_str)");
	// Define a callback function for the event listener.
	function handleOrientationChange(mql)
	{
		var w = screen.availWidth;
		if (mql.matches)
		{
			alert("Got a match: testing for " + test_val + " width is: "+w);
		}
		else
		{
			alert("Non-match:  testing for " + test_val + " width is: "+w);
		}
	}
	// Add the callback function as a listener to the query list.
	mediaQueryList.addListener(handleOrientationChange); 
	handleOrientationChange(mediaQueryList); // Run the orientation change handler once.

Now, when I run my script on my laptop I get the 'non-match' message saying my width is 1366. Great.

But - when I run on my iphone6 I get the same 'non-match' message saying my width is 375.

 

 

I must me mis-undertanding the testing that goes on here. Why is that a "non-match"?

Edited by ginerjm

Please ignore my previous post. I had some lines of my code in the wrong places apparently because my testing is now accurate.

 

BUT - my css is still not working.

 

When my testing code (above) shows a 'match' condition for a max-width of 768 the following should happen but it doesn't.

	@media (max-width: 768px)
	{
		#menu_box2 a, #menu_box2 input
		{
			margin-bottom: 20px;
			font-size: 32px;
		}
		#menu_box2
		{
			border:1px solid white;
		}
	}
And - I cannot find any 'later' css settings in my script that would over ride this. I even added a setting to show a border on the box and that is not showing up.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.