Results 1 to 4 of 4
  1. #1
    Join Date
    May 2007
    Posts
    30
    Plugin Contributions
    0

    Default Add to Cart button width

    Hi, does anybody know why the add to cart button width isn't wide enough when using CSS buttons? the others are all fine, and ive tried increasing it using pixels, ems, everything! as well as increasing the container DIV and reducing padding and margins, all that, none of it makes any impact at all! does anybody know why?

    i've searched for this and see lots of questions about add to cart but not this specific inability to increase the width. (i've left it all at zen carts default, not messed with any code on the product display pages)

    thanks!

    Kyle

  2. #2

    Default Re: Add to Cart button width

    I searched and searched for the answer to that one, too, and this is what I found:

    In /includes/functions/html_output.php, you'll find a function zenCssButton($image = '', $text, $type, $sec_class = '', $parameters = '') that builds the Submit buttons.

    Change line 313 from this:
    $style = ' style="width: ' . $width . 'px;"';

    to this:
    $style = ''; // $style = ' style="width: ' . $width . 'px;"';

    To be clear, $style is set equal to empty single quotes.

    Before this line of code, the approximate width of the button is computed, but it is trying to convert ems to pxs, and it's not accurate with the longer buttons.

    Later on in this function, $style is used to build the Submit button. By blanking out the style value, the button is allowed to assume it's default width. If you don't like the results, play around with the variables on lines 306 and 307:

    $min_width = 80; // this is the minimum button width, change the value as you like
    $character_width = 6.5; // change this value depending on font size!

    Also, in /includes/templates/custom-template/css/stylesheet_css_buttons.css, you can change the font size in line 20
    font-size: 1.1em;

    I hope this helps.
    Joyce

  3. #3
    Join Date
    Jan 2008
    Posts
    3
    Plugin Contributions
    0

    Default Re: Add to Cart button width

    ahhh! I've been searching for the answer to this one for hours!!! was so happy i found it that just had to post a thank you.

  4. #4
    Join Date
    Oct 2010
    Posts
    13
    Plugin Contributions
    0

    Default Re: Add to Cart button width

    Nearly 3 years later this is still a problem. I spent hours before I came across this thread. So thank you again.

    I don't see though how the font-size: 1.1em; in stylesheet_css_buttons.css is even going to matter though? The function zenCssButton makes that calculation with just the length of the text * the character_width constant (defaults to 6.5). The net effect of this is that any css customization you do specific to a button (e.g. increasing the font size) are going to get wiped out at the browser by the "style="width: " clause unless your text is quite long.

    Correct me if I am wrong, but won't this change get borked when you do an upgrade? (not that it should stop anybody from doing it, but it's just one of those things that has to get ported).... :)

 

 

Similar Threads

  1. v151 How do I replace the add-to-cart button with a PayPal *Donate* button?
    By picandnix in forum Addon Payment Modules
    Replies: 7
    Last Post: 29 Apr 2014, 02:52 PM
  2. v151 Add To Cart displaying alt text instead of add to cart button
    By AquaticAddiction in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 8 Feb 2014, 07:58 PM
  3. Change the Add to Cart button to Buy Now button
    By dastudio in forum Customization from the Admin
    Replies: 1
    Last Post: 24 Nov 2010, 09:44 PM
  4. How do I replace the Buy Now button with an Add to Cart button?
    By OrcaSoul in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 19 Feb 2010, 05:36 AM
  5. Add To Cart box width
    By kappaluppa in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 19 Feb 2007, 05:39 AM

Posting Permissions

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