WordPress.org

Ready to get started?Download WordPress

Forums

code in the post (10 posts)

  1. mrwolfy
    Member
    Posted 4 years ago #

    for some reason I am not able style the code tag. Unfortunately, for some reason, my code comes out as monospaced, but without a background color. example below

    http://oliverwolfson.com/mel-write-obj-sequence/

    I tried styling the code by putting in the following CSS. But nothing changed.

    code {
    	color: blue;
    	background-color: #EEEEEE;
    
    	}

    any ideas on this one?

  2. rizaldy
    Member
    Posted 4 years ago #

    looking into your css i found that you put .code

    .code {
    	color: dimgray;
    	font-family: courier, serif;
    	background-color: #EEEEEE;
    	padding: 10px;
    	border: 1px solid #888888;
    	margin: 0 20px 0 20px;
    	width: 530px;
    }

    remove "." like this

    code {
    	color: dimgray;
    	font-family: courier, serif;
    	background-color: #EEEEEE;
    	padding: 10px;
    	border: 1px solid #888888;
    	margin: 0 20px 0 20px;
    	width: 530px;
    }
  3. mrwolfy
    Member
    Posted 4 years ago #

    Thank you for your reply.

    Actually the .code is a class (below) that I use to style code. That works fine and gives me the look I want. The problem is that when I copy and paste this code to the program that I use the code in, I always get errors.

    <div class="code">

    anyway, today I was experimenting with using the built-in code tag (below), and that seems to work well. I can copy and paste code and it seems to work. My problem is that I am unable to style the code.

    <code>

    I already tried doing what you suggested but it made no difference.

    Here is an example of both my .code class and the built-in code tag in action. the code with the white background is the default, with gray bg is my custom style.

    http://oliverwolfson.com/mel-renaming/

  4. alchymyth
    Forum Moderator
    Posted 4 years ago #

    your first attempt should work:

    code {color: blue;
    background-color: #eeeeee;}

    have you tried refreshing the browser cache by pressing CTRL and F5 simultaniously ?

    just be aware that not all this text of your post is within 'code' - the paragraph tags seem to break it:

    int $i;

    string $rename[] = ls -sl;
    int $selSize = size $rename;

    for ($i =0; $i <$selSize ; $i++){

    rename ($rename[$i]) ("newName_" + ($i +1));

    }

  5. Stian Andreassen
    Member
    Posted 4 years ago #

    If you want to show code in your posts, you might consider a syntax highlighter plugin, f.i. http://wordpress.org/extend/plugins/syntaxhighlighter/

  6. mrwolfy
    Member
    Posted 4 years ago #

    yea it's strange, this is the post that is within the code tags (Below). i tried clearing the cash, but there was no change.

    I'll try highlighter! But will that solve the issue of code, Which is cut and pasted giving me errors? that is really the problem anyway as i can style the code any way i want, with a div. It just needs to easily paste into a script and work.

    <code>
    
    int $i;
    
    string $rename[] = <code>ls -sl</code>;
    int $selSize = <code>size $rename</code>;
    
    for ($i =0; $i <$selSize ; $i++){
    
    rename ($rename[$i])  ("newName_" + ($i +1));
    
    }
    </code>

    This seems like a strange problem. Thanks for the suggestions! Please let me know if anyone has insight.

  7. Stian Andreassen
    Member
    Posted 4 years ago #

    Are you using the visual editor, or the HTML editor? The latter is recomended if you're posting code, as the visual editor (TinyMCE) will break the code.

  8. mrwolfy
    Member
    Posted 4 years ago #

    thanks, but yes I am using the HTML editor. still somehow the code is broken though. I must be doing something wrong, right?

    Question: is there something I need to do with text that I want to be displayed as code when writing HTML? Is there something that I need to do with basic HTML or CSS to style text so that it can be used properly as code? Because if I could do that I wouldn't have to worry about the code tag apparently been broken in my WordPress set up.

  9. mrwolfy
    Member
    Posted 4 years ago #

    okay, I think that I fixed it. Should have read the Codex a bit more closely. Using the <pre> before my div seems to have fixed the problem.

  10. mrwolfy
    Member
    Posted 4 years ago #

    http://codex.wordpress.org/Writing_Code_in_Your_Posts#Using_PRE

    Just to be clear, the problem fixed is: I can now cut and paste code styled with my custom div, and it works fine, apparently.

    I still cannot figure out how to style the built-in code tag.

    Anyway, thanks for all the suggestions.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.