CSS Question

CSS Question

by Hayk Zakaryan -
Number of replies: 21

I am working on the Serenity theme.

I want to put a banner on the page-header part of the theme.

My banner has a logo on the left side and just background color, i am not sure how to put css in order to make this work with all the screen sizes.

My banner is a .jpg image with the size 1200vs150 px.

Here is the css for #page-header id

#page-header {height: 150px;    background:url([[pix:theme|back23]]);

Thanks.

Average of ratings: -
In reply to Hayk Zakaryan

Re: CSS Question

by Danny Wahl -

I'm not sure what you mean by 'all screen sizes' but I think what you will want is:

background:url([[pix:theme|back23]) no-repeat scroll top left #000000;

 

note: you'll want to change #000000 to whatever color you actually want the background color to be.  Also, I would just change the banner to be a png with a transparent background, and only as wide as the logo (instead of 1200px)

Average of ratings: Useful (1)
In reply to Danny Wahl

Re: CSS Question

by Hayk Zakaryan -

Hi Daniel,

But i can't do this way, my banner itself has gradient background. If i make it scrollable and add some color from the right. I will have to colors.

Hayk

In reply to Hayk Zakaryan

Re: CSS Question

by Mary Evans -

Hi Heyk,

When designing, or remodeling a theme I always try to set #page to the width I want the finished theme to be. So if I want the header to run the full width of the page I make #page { width: 100%;}

If I wanted some space either side of the header I would set it as #page { width: 95%; margin: 0 auto; }.

I always, where possible set  #page-header { width: 100%; }

This initial set up for #page allows for a fluid theme which will re-size to any screen resolution (screen size ) which has been set by the user.

Like Daniel has pointed out, avoid using oversized images in the header. Or at least have them a  uniform size to match the minimum screen resolution. Most sites these days use 1024px x 768px so the min width of your image should not be more than 999px as 25px of the total width of the screen can be taken up by the right-hand scroll bar. But if you are going for total fluidity, the maximum width of your header image should be not more than 775px this allows for 800px by 600px screen resolution.

Also remember, if you go for fluid width settings, keep all widths in % (percentages) this allows the the page to re-size easily.

Another thing to remember when setting widths in percentages, is to allow for any padding. So any element with say a width of 100% and with padding of say 1% (approx 10px) (on left and right side only) needs the width set to 100-(1%+1%) = 98% this is very important.

Last but not the least, I hope you are cloning the themes you are customizing, as the fact you are changing the appearance of CORE themes, your previous one being Anomaly, and now Serenity. If you haven't CLONED them, then when you upgrade Moodle, unless you save the themes you have changed, you will loose all the styles and images you are adding now.

HTH

Mary

Average of ratings: Useful (2)
In reply to Mary Evans

Re: CSS Question

by Hayk Zakaryan -

Hi Mary,

Thanks for your help. I will keep up with % es.

Yes i have cloned the themes in order not to lose originals.

Anyway i couldn't make it work as i want. So now i have my banner, which is a gradient background and logo on the left side(All itself one .jpg ). Let's say i cut out the size of banner to 350px vs 150px , and i want to make it the whole width of my page. I also want this page to work on mobile devices(I know that this way it may not be possible). Here is my css for that part

#page { width: 100%;}
#page-header {     width:100%;    height:150px;    background:url([[pix:theme|gradient6]])  no-repeat scroll top left ;   margin-bottom: 5px;}

I mean if i am making it scrollable and put some color from the right side, i am loosing my gradient background.

Is it possioble this way to make it work?

I have one more question. I have created a horizontal dropdown menu(css javascript). On my general.php and frontpage.php files it is under this div      <div id="page-header" class="clearfix">

I put my navigation on my banner bottom-right side with relative positioning uising % -es.

Also when i put my navigation on the bottom-right side of my banner and hover over it, my drop-down opens behind the block(that is under it).

My css for navihgation is in core.css and the javascript is inside the head of frontpage.php and general.php.

The navigation works fine on the top parts of the banner, here it has "room" to open-up the dropdown.

Hayk

Also when i put my na

In reply to Hayk Zakaryan

Re: CSS Question

by Mary Evans -

Hi Hayk,

What I tend to do is use the h1.headermain tag to hold the logo.jpg

and use the #page-header to hold the background repeat image bg.jpg.

 

 

 

I would then style it something like this...

#page-header,
#page-header h1.headermain {
width: 100%;
height: 100px;
margin: 0;
padding:  0;
{

#page-header {
background: url([[pix:theme|bg]])
}

#page-header h1.headermain {
background: url([[pix:theme|logo]]) no-repeat left top;
position: relative;
left: 10px;
}

Which would give me a page header which looks something like this...

HTH

Mary

Average of ratings: Useful (1)
In reply to Mary Evans

Re: CSS Question

by Hayk Zakaryan -

Hi Mary,

This worked fine for me, thank you very much.

Only the login-info moved down.

It is ok yes if i just use positioning to move the

.headermenu class up?

In reply to Hayk Zakaryan

Re: CSS Question

by Mary Evans -

Yes you should be able to do that.  Perhaps if you check in Firefox Firebug where the div.headermenu container is in relation to your logo.

Try adding ...

.headermenu {
position: relative;
top: 0;
right: 0;
}

to see which way you need to move it, then jsut adjust the top and right values to place it near the right edge of your screen... perhaps top: 10px and right: 10px might work.

Glad it helped you solve the problem with the banner.

Cheers

Mary

Average of ratings: Useful (1)
In reply to Mary Evans

Re: CSS Question

by Hayk Zakaryan -

Hi Mary,

I am now good with the .headermenu class too.

Thnak you very much.

After this i will have to prepare a sample with custom-corners on Moodle 1.9

I may post some questions with it, is it ok?

Thanks again.

Hayk.

In reply to Mary Evans

Re: CSS Question

by Chad Outten -

Is it possible to put 3 images in a page header or div and give the impression that the banner is fluid?

the left and right images are logos that would align left and right in the page header or div, and the third image would be a spacer that expands, contracts as the page width is resized.

trying to do this for anomaly theme. appreciate any pointers.

In reply to Chad Outten

Re: CSS Question

by Mary Evans -

Hi,

Yes you can do this, and is pretty easy. if you have all the images, then depending on which version of Moodle you are working on, how you do it is similar but the syntax different from Moodle 1.9  to Moodle 2.0.

I'll assume you are using Moodle 2.0 as Anomaly is not a core theme in Moodle 1.9, although it is available in Moodle Themes to download.

What I do is try to use the container which form the header, this then make it easier and quicker to do.

Open up anomaly/layout/general.php using Notepad, and at the top of this file you will see the code which forms the header container in Anomaly most of which you can ignore apart from the areas I have highlighted...

<?php if ($hasheading || $hasnavbar) { ?>
<div id="page-header">
<div class="rounded-corner top-left"></div>
<div class="rounded-corner top-right"></div>
<?php if ($hasheading) { ?>
<h1 class="headermain"><?php echo $PAGE->heading ?>

<div id="left-logo"></div>

<div id="right-logo"></div>

</h1>
<div class="headermenu"><?php
echo $OUTPUT->login_info();
if (!empty($PAGE->layout_options['langmenu'])) {
echo $OUTPUT->lang_menu();
}
echo $PAGE->headingmenu
?></div><?php } ?>

<?php if ($hascustommenu) { ?>
<div id="custommenu"><?php echo $custommenu; ?></div>
<?php } ?>

<?php if ($hasnavbar) { ?>
<div class="navbar clearfix">
<div class="breadcrumb"><?php echo $OUTPUT->navbar(); ?></div>
<div class="navbutton"><?php echo $PAGE->button; ?></div>
</div>
<?php } ?>
</div>
<?php } ?>

The parts I have highlighted will form the containers for your three images.

Delete the part I have crossed out...

<?php echo $PAGE->heading ?>

The containers you will use are as follows:

page-header for the repeating background image

h1 for the left/right logos

You will notice I have added two more containers "left-logo" and "right-logo" these will float left and right when you apply the css rules, see below.

First however, you will need to add those too extra containers to anomaly/layout/general.php just as I have written them above.

Next open anomaly/general.css using Notepad and add the following to the end of this file...I'll assume height of your images are 100px but you can adjust this value. The logoes may differ in size both width and height. Just make sure you add the correct width and height to the css.

#page-header,
h1.headermain {
width: 100%;
height: 100px;
margin: 0;
padding: 0; }

#page-header { background: url([[pix:theme|spacer]]) repeat-x }

h1.headermain div#left-logo {
clear: left;
float: left;
width: 200px;
height: 100px;
padding: 0;
margin: 0;
position: relative;
top: 0; left: 20px;
background: url([[pix:theme|left-logo]]) no-repeat left top; }

h1.headermain div#right-logo {
clear: right;
float:right;
width: 200px;
height: 100px;
padding: 0;
margin: 0;
position: relative;
top: 0;
right: 20px;
background: url([[pix:theme|right-logo]]) no-repeat right top;}

Save the files you have changed and upload them to their respective directories on your web server, and see what it looks like.

You will need to make sure the values for the image are the same as the height of the containers. Also depending on what it looks like in situ, you may need to adjust the left and right positions of the logos.

That's it.

HTH

Mary

Average of ratings: Useful (1)
In reply to Mary Evans

Re: CSS Question

by Chad Outten -

i spoke too soon! logos display nicely for chrome, firefox & safari but not IE. images overlap the 5px navbar at bottom of header - see attached. ive played with various page-header settings but can't seem to sort this for IE. any ideas?

Attachment headermain.png
In reply to Chad Outten

Re: CSS Question

by Mary Evans -

Hi Chad is this site live?  If so can you send me a link in message or post it here. IE has a different way of working, so needs some TLC...

In reply to Chad Outten

Re: CSS Question

by Mary Evans -

Hi Chad,

Thanks for the link, nice site...you did a good job.

Ok...you can drop the following from both sides:

position: relative;
top:0;
left:0;
right:20px;

Add then just all this to the right side:

margin: 0 20px 0 0;

This just adds 20px to the right of the image forcing it away from the edge.

Let me know how you get on.

Cheers

Mary

In reply to Mary Evans

Re: CSS Question

by Denetta Albrecht -

This is exactly what I've been trying to accomplish too. I have a long rectangular .jpg image (1044 x 170). I want it to fill my entire header (no padding needed). I also want it to resize with the window in any browser (to be fluid).

1. I tried your recommendation of changing my .jpg to a .pgn file then my image wouldn't render on the screen anymore so I changed it back to .jpg.

2. Each time I add       

#page-header {
    width: 100%  .......again my image disappears.

I'm sure I've botched the code somewhere in my novice tinkering. Any help would be appreciated.

My site:  libertyoc.liberty.k12.ok.us   

Moodle 2.4, Boxxie Theme (yes, I've cloned this theme before changing code.)  (-:

My current header CSS code:

#page-header {
    width: 100%
    background: url([[pix:theme|logo]]);
    height: 220px;
    background-repeat: no-repeat;
    background-position: 0 0;
    background-color: #004081;
}
#page-header a:link,
#page-header a:visited {
    color: #ffffff;  
}
#page-header h1.headermain {
    color: #fff;
    font-weight: normal;
    font-size: 2em;
    margin: 30px;

Looking forward to the Forum's AWESOME Moodlers to lend me a hand. THANKS!

In reply to Denetta Albrecht

Re: CSS Question

by Mary Evans -

Hi,

First of all you look to have missed the ; from the end of width: 100%; Also because of the way you started to write the CSS mark-up you should have written background-image: instead of just background. So try writing it like this...

#page-header { 
    width: 100%;
    height: 220px;
    background-image: url([[pix:theme|logo]]);
    background-repeat: no-repeat;
    background-position: left top;
    background-color: #004081;
}

That should get you back on track.

In reply to Mary Evans

Re: CSS Question

by Denetta Albrecht -

Hi Mary,

First THANK YOU for helping this novice establish and brand my first Moodle.

I tried the code you gave me, but the tiger logo still did not fill the header. There was open space to the far right of the tiger logo.

Then I thought I'd try what Hayk did with the logo and repeating background. SUCCESS, but I created new problems. In the screen shot below you can see how placing the tiger logo in the headermain requires no margin or the logo and bg are further misaligned. A lack of margin forces the upper left text too far into the corner (unsightly).

This is with a 5px margin, and the logo and bg misalign.

This also forced my custom menu and log in to move too far down. I tried adjusting them, but they stay well below the header. I tried adding the header menu code you gave to Hayk, but it didn't move them. (Maybe because we are using different themes?)

This is my custom menu highlighted in light blue far below the header. (As well as 0px margin.)

smile  We've met my goal of having the tiger logo fill the header or at least look like it with a repeating bg, but now I need to get the custom menu below the red bar and some margin around the left corner text without moving the tiger logo.

I'm sorry to be such a needy novice. Any recommendations?

(Boxxie 2.4) (libetyoc.liberty.k12.ok.us)

#page-header,
#page-header h1.headermain {
width: 100%;
height: 230px;
margin: 0;
padding:  0;
}
#page-header {
    background: url([[pix:theme|bg]]);
}
#page-header a:link,
#page-header a:visited {
    color: #ffffff;  
}
#page-header h1.headermain {
    background: url([[pix:theme|logo]]) no-repeat left top;
    left: 50px;
    color: #fff;
    font-weight: normal;
    font-size: 2em;
    margin: 0px;   -Adjusting this misaligns the tiger logo and bg but the text needs a margin

}


#custommenu {
    overflow: visible;
    position: relative;
    top: 10px;   -Adjusted to 0 but menu is still outside header
    left: 0;
}