images inside the blog posts - html

I'd like to define the appearance of my images inside the section (I'm trying to add a border to the image - but I can't reference the image directly because the images are added dynamically - as content of blog posts.)
Can you advise me on how to do that?
Do I have to create a new section/id/div? How can I than say to the machine: In the section/id/div I created I would like you to apply these styls to the images."
?
thanks, D.

Yes you need to get a reference to the image or the block in which the images is going to be displayed. Then apply the css rules to the image or block you will then get the styles on the image. I would prefer class="" if there are many and id="" if there is only one.
If you have img inside any elements like below,
<div class="someclass">
<img src="" />
</div>
then at CSS,
.someclass{
your rules go here.
}
or if you want to directly have styles on image then you HTMl will be like below and CSS same as above.
<img class="someclass" src="" />

If content is added dynamically, styles are applied automatically as new content is added to the DOM, you don't need to worry about that. Inject the content you want, and as long as there is CSS-rules that match that content, the browser will handle the rest.
Update
I realize that I might have misunderstood your question at first. If the user is completely in control of the markup of the blog post, I guess the best way would be to use a selector, that select every image within a container that wrap each blog post.
Lets say each blog post is rendered within an element with class post. Then you could do something like this:
.post img {
border: 1px solid #000;
}

Related

How would I remove a picture if user is a mobile device

enter image description hereI need to remove a picture (using css) if a device visits that is a mobile user. I’ve tried media queries with the display:none and many other things And nothing. Maybe I’m just not using proper syntax or putting it in the right spot? Some help would be greatly appreciated. Thanks!
In the example you've posted, the stylesheet is targeting the class:
.post .sc_image img
but your code example only shows an image tag without the parent containers that have the .post .sc_image classes.
You'd expect to see the image inside some divs (etc) like this:
<div class="post">
<div class="sc_image">
<img />
</div>
</div>
For your example to work correctly, remove .post .sc_image out of your css.
However, I'd guess that these other classes are because your complete code has more to it than just the tag sitting by itself. With that in mind, I would assume that some other style within your application is overwriting the display:none property.

How to make mdGridTile's into links

I have a similar question as this thread, but the answer doesn't seem to be listed anymore. I have a list of tiles that show a property image and some relevant information. I'd like each to be a full link to another page with more information on the property.
I've made my tiles into a directive, and currently the html content of that directive is wrapped in an anchor tag. Which works to reach my specified link, however that anchor tag only matches the height of the mdGridTileFooter.
Is there a way to make the entire tile clickable? So that the user can click on any part of it and access the intended link (not just the bottom footer?
The HTML Directive:
<a ng-click="spVm.linkToProperty(proforma)" ng-href="{{spVm.path}}">
<div>
<md-grid-tile-footer class="saved-prop-address">
<div class="saved-prop-address-title" ng-bind="spVm.city"></div>
<div class="saved-prop-address-subtitle"
ng-bind="proforma.listing.update_date | date: 'MMMM dd'"></div>
</md-grid-tile-footer>
</div>
</a>
The HTML Page with the Tile List:
<md-grid-list md-cols-xs="2"
md-cols-sm="3" md-cols-md="3" md-cols-gt-md="6"
md-row-height="1:1" md-gutter="4px">
<md-grid-tile class="saved-prop"
ng-repeat="proforma in sdVm.pageGroups[sdVm.saved.idx]"
ng-click="sdVm.showSelectedProperty(proforma); sdVm.linkToProperty(proforma)"
ng-href="{{sdVm.path}}"
ng-style="{'background-image':'url({{proforma.thumbnail_url}})'}">
<pgo-saved-property proforma="proforma">
</pgo-saved-property>
</md-grid-tile>
</md-grid-list>
Thank you!
Since it looks like the directive had no height, adding any responsive height/width styling to the anchor tag won't work.
Adding this code to the css for the directive, and the anchor tag, will bring the anchor/link to the full height and width of the tile.
style="display:block;height:100%;width:100%;"
And any responsive changes that occur with the tiles will work with this code as well.

Is there a way to add microdata to an image referenced in CSS?

I am attempting to add itemprop="image" for a corporation's logo (as shown here: http://www.schema.org/Corporation), but I am using the Gantry Logo plugin from the Gantry framework for Wordpress. As a result, the image is actually loaded by a reference in CSS, and not using the HTML tag.
Unfortunately, it seems that the itemprop="image" can only be added to that tag, as that is where it grabs the URL from.
Can anybody think of a way around this without attempting to hide a logo on the site and place the tag on it?
(The site I am specifically referring to is http://www.bpsresolver.com for reference.)
"Can anybody think of a way around this without attempting to hide a
logo on the site and place the tag on it?"
That's exactly what needs to be done.
The way to do it is to open the source for this Gantry Logo plugin and find the logo's <a id='logo'></a> that the css refers to and change it to <img src='yourimage.jpg'/> I usually use WindowsGrep to find id='logo' or whatever it may be in your case.
But to answer your question: "Is there a way to add microdata to an image referenced in CSS?" - No :)
What I ended up doing to fix it was going to the logo.php plugin located in /plugins/gantry/widgets/. At the bottom of that file is where the <a> tag is that miro mentioned.
Instead of removing it and replacing it (since it had a number of other CSS properties attached that needed to stay the same), I simply added the <img> tag in between the <a> tags, and changed the CSS that referred to the image from background: url(url_to_image); to background: transparent;.
Lastly, I wrapped the whole thing in a <div> tag which I used to indicate the scope, and placed itemprop inside <img>.

Dynamic CSS attribute

I have the next two elements on an HTML file:
<a id="a1" href="?cssfile=css-folder/015/styles.css">Style number 015</a>
<div id="a1Preview"></div>
The first one (anchor) is a reference to a CSS that will be loaded dynamically by the page. The second one (div) pretends to be a preview (thumbnail) of the style sheet.
THE PROBLEM IS I need a way to set the div background dynamically from the CSS, something like:
#a1Preview
{
background: url(css-folder/{"015" extracted from the <a> element}/preview.png);
}
Is this possible? Any ideas? Of course the HTML is untouchable. I can only change the CSS.
Thanks in advance.
You could use jQuery to change the css content dynamically. jQuery is a extension to javascript. From there you could then use the system you use to skin, but generally to extract href attributes from tags and change CSS, you can use such a thing.

Is it better to define images in direct html or css?

If I have the choice to insert images directly into the html or in the css, say for example a link wrapped in an image I could do either...
<img src="#" alt="" width="" height="" />
Or I could do...
<a id="img" href="#"></a>
#img {background: url('#') no-repeat; height: #; width: #;}
Which is better and why? Both work as wanted but is there any difference to load times etc, or any considered better practice?
Using images in HTML is better when the image has any contextual meaning... if it is a decorative picture without any contextual meaning, then use CSS. CSS is for presentation, HTML is for content.
The best hint for you to determine whether to use HTML or CSS for a picture is:
If I remove the picture, will the web-page content still make sense?
An image in HTML is meant to provide a visual meaning in context, with a meaningful text fall-back. Using an A element without any content should be avoided since its content will have a relationship with the link, for browsers and web-crawlers (such a Google bot).
Use CSS images only for decorative purposes. Otherwise it can damage your search engine rankings. Always provide an alt attribute for images, determine what will it be imagining that an eventual visitor cannot see any images.
If the image has context, such as a logo, or a photo, I would suggest loading it as an <img> Make sure you are providing alt text for accessibility and SEO reasons as well.
If an image has no context in the scope of the page, then I think the correct place for it, is defined the in the CSS which controls the design.
The whole idea is to separate your presentation from your content as much as you can. An Image can be content, and if so, should be in it.
Generally, I try to put as many images in CSS as possible but Doozer and Mario have good points. If the image is important to the context, it can go in the HTML. I will also use <img> tags when text needs to float around and image.
One thing that CSS can do that <img> can't are CSS image sprites. This is the only real performance benefit that you'll get from one or the other. Performance-hungry websites like youtube.com will combine many images into one large composite image in order to cut down on the HTTP traffic (and therefore the page load times). For example, this is a sprite taken from youtube.com.
Follow principles of semantic HTML. If the image is content, ie a thumbnail, photo, or button, use an <img> element. If it is more a part of the page design, a background image may be more appropriate.
A more specific example: If you are using your image as an icon next to a text link, use a background-image:
<span class="printIcon" onclick="window.print()">Print</a>
.printIcon { background: url(...) no-repeat; padding-left: 20px }
If your image is the button itself, with no text aspect, use an <img> element with an appropriate alt attribute that would work to substitue for the image if it is unavailable.
<img src="printButton.png" alt="Print" onclick="window.print()" />