Results 1 to 4 of 4

Thread: Help with responsive CSS header text and image

  1. #1
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default Help with responsive CSS header text and image

    Hi all

    I know I can setup different media sizes for responsive view, but I am trying to work out how I can do this dynamically via responsive css (only).

    What I have is a small logo image that could be used as a background or aa an image and then there is the site title that has space between for where the logo should appear. The title is a simple two word title which should make things easier. Both the site title words and the logo need to auto resize based on screen with.

    So in essence I am wanting

    header text word 1 - image - header text word 2

    Some css I have been playing with but not able to get it to work is

    Code:
    #header {
      max-width:100%;
      border-bottom:0 none;
    }
    
    #header {
      background-repeat:no-repeat;
      background-size:contain;
      background-position:center;
    }
    
    #header #site-title {  
      height:101px;
      height:6.3125rem;
      font-size:56px;
      font-size:3.5rem;
      line-height:99px;
      line-height:6.1875rem;
      word-spacing:104px;
      word-spacing:6.5rem;
      text-align:center;
      text-transform:uppercase;
      background: transparent url(images/logo.png) no-repeat 49% 0;
      white-space: nowrap
    }
    The above tries to use the logo as a background, but if it would work better as a standard image I'd be happy (actually better for me) to change that

    The html output I have tried several ways as shown here

    HTML Code:
    <div id="header">
      <h1 id="site-title"><a href="http://mysite.com/">Two Words</a></h1>				        
    </div>
    HTML Code:
    <div id="header">
      <img src="http://mysite.com/logo.png" alt="Two Words"><h1 id="site-title"><a href="http://mysite/">Two Words</h1></a>				        
    </div>
    HTML Code:
    <div id="header">
      <h1 id="site-title"><a href="http://mysite/"><img src="http://mysite.com/logo.png" alt="Two Words">Two Words</a></h1>				        
    </div>
    Thanks for your help
    1st rule of web development - use Firefox and Firebug
    2nd rule - see the first rule
    --
    I like Smilies

  2. #2
    Join Date
    Dec 2008
    Location
    Selby, North Yorkshire
    Posts
    90
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default

    First of all does your HTML contain the following?

    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />


    These lines ‘tell’ the browser what sort of device to render an image for.

    The CSS then reflects this information, see example below.
    Code:
    /* Settings for a Desktop PC
    ===================*/
    
    /* desktop styles here */
    
    
    /* Settings for a Tablet
    ===================*/
    @media screen and (max-width: 980px) {
    
    /* tablet styles here */
    
    }
    
    
    /* Settings for a SmartPhone
    ===================*/
    @media screen and (max-width: 640px) {
    
    /* smartphone styles here */
    
    }
    Last edited by Beverleyh; 05-12-2015 at 07:44 AM. Reason: Add text colour | MOD EDIT: formatting, MQ braces corrected and CSS removed that is not pertinent to the OP

  3. #3
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    We would need a link to the page to offer specific help, but in the meantime, for a totally fluid/scalable option, have a play with viewport units http://caniuse.com/#feat=viewport-units Good for modern browsers and IE9+ (you can provide fixed-size fall-backs for IE8 in a conditional stylesheet)

    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
    <meta name="description" lang="en" content="A responsive / scalable header demo."/>
    <title>Responsive / Scalable Header</title>
    
    <style>
    #header #site-title {  
    	text-align: center;
    	text-transform: uppercase;
    	white-space: nowrap;
    	background: #ddd url(logo.png) no-repeat 46.5% 50%; /* tested with a 192 x 192 px img */
    	background-size: 7vw;
    	font-size: 5vw;
    	line-height: 10vw;
    	word-spacing: 10vw;
    }
    
    @media ( min-width:60em ) { /* bigger than 960px - fixed units after this point to stop upscaling */
    
    	#header #site-title {  
    		background-position: calc(50% - 30px) 50%; /* calc offset from center to account for different word length */
    		background-size: 67px;
    		font-size: 3em;
    		line-height: 2em;
    		word-spacing: 2em;
    	}
    
    }
    </style>
    
    </head>
    <body>
    
    <div id="header">
    	<h1 id="site-title"><a href="http://mysite/">Two Words</a></h1>				        
    </div>
    
    </body>
    </html>
    If you need more help, please provide a link to your page.
    Last edited by Beverleyh; 05-12-2015 at 08:13 AM. Reason: MQ added to stop continued scaling (elements would just keep getting bigger)
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  4. #4
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default

    Thank you both for your help, I will try what you have provided, but if I can't nut it out I will return with a link to the page in question.

    Cheers
    1st rule of web development - use Firefox and Firebug
    2nd rule - see the first rule
    --
    I like Smilies

Similar Threads

  1. Replies: 5
    Last Post: 04-09-2015, 12:16 AM
  2. Replies: 5
    Last Post: 01-14-2015, 10:26 AM
  3. responsive image grid?
    By mlegg in forum CSS
    Replies: 8
    Last Post: 09-24-2014, 04:57 PM
  4. Resolved Multizoom - Image sizing in responsive design
    By ozinder in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 02-14-2014, 01:14 PM
  5. Switch Content: Change Text Size of Header
    By ro1960 in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 08-02-2007, 05:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •