Markdown and image alignment

前端 未结 14 2292
予麋鹿
予麋鹿 2020-12-02 04:06

I am making a site that publishes articles in issues each month. It is straightforward, and I think using a Markdown editor (like the WMD one here in Stack Overflow) wo

相关标签:
14条回答
  • 2020-12-02 04:49

    As greg said you can embed HTML content in Markdown, but one of the points of Markdown is to avoid having to have extensive (or any, for that matter) CSS/HTML markup knowledge, right? This is what I do:

    In my Markdown file I simply instruct all my wiki editors to embed wrap all images with something that looks like this:

    '<div> // Put image here  </div>`
    

    (of course.. they don't know what <div> means, but that shouldn't matter)

    So the Markdown file looks like this:

    <div>
    ![optional image description][1]
    </div>
    
    [1]: /image/path
    

    And in the CSS content that wraps the whole page I can do whatever I want with the image tag:

    img {
       float: right;
    }
    

    Of course you can do more with the CSS content... (in this particular case, wrapping the img tag with div prevents other text from wrapping against the image... this is just an example, though), but IMHO the point of Markdown is that you don't want potentially non-technical people getting into the ins and outs of CSS/HTML.. it's up to you as a web developer to make your CSS content that wraps the page as generic and clean as possible, but then again your editors need not know about that.

    0 讨论(0)
  • 2020-12-02 04:52

    I have an alternative to the methods above that used the ALT tag and a CSS selector on the alt tag... Instead, add a URL hash like this:

    First your Markdown image code:

    ![my image](/img/myImage.jpg#left)
    ![my image](/img/myImage.jpg#right)
    ![my image](/img/myImage.jpg#center)
    

    Note the added URL hash #center.

    Now add this rule in CSS using CSS 3 attribute selectors to select images with a certain path.

    img[src*='#left'] {
        float: left;
    }
    img[src*='#right'] {
        float: right;
    }
    img[src*='#center'] {
        display: block;
        margin: auto;
    }
    

    You should be able to use a URL hash like this almost like defining a class name and it isn't a misuse of the ALT tag like some people had commented about for that solution. It also won't require any additional extensions. Do one for float right and left as well or any other styles you might want.

    0 讨论(0)
  • 2020-12-02 04:54
    <div style="float:left;margin:0 10px 10px 0" markdown="1">
        ![book](/images/book01.jpg)
    </div>
    

    The attribute markdown possibility inside Markdown.

    0 讨论(0)
  • 2020-12-02 04:57

    You can embed HTML in Markdown, so you can do something like this:

    <img style="float: right;" src="whatever.jpg">
    
    Continue markdown text...
    
    0 讨论(0)
  • 2020-12-02 04:58

    I found a nice solution in pure Markdown with a little CSS 3 hack :-)

    ![image alt >](/image-right.jpg)
    ![image alt <](/image-left.jpg)
    ![image alt ><](/center-image.jpg)
    

    Follow the CSS 3 code float image on the left or right, when the image alt ends with < or >.

    img[alt$=">"] {
      float: right;
    }
    
    img[alt$="<"] {
      float: left;
    }
    
    img[alt$="><"] {
      display: block;
      max-width: 100%;
      height: auto;
      margin: auto;
      float: none!important;
    }
    
    0 讨论(0)
  • 2020-12-02 05:00

    this work for me

    <p align="center">
     <img src="/LogoOfficial.png" width="300" >
    </p>
    
    0 讨论(0)
提交回复
热议问题