My WP Theme gives me a block where I can build in Custom CSS. I need a picture with the right size and not as background before the .primarymenu.
With CSS you can do that this way:
.menu:before {
content: url('https://placeholdit.imgix.net/~text?txtsize=23&bg=990000&txt=Image&w=150&h=150');
}
<div class="menu">Menu</div>
Related
I have a template written by someone else, and they have used an image in the CSS as a backgound image like so.
.block-title__inner:after {
background-image: url('../media/bg/11.jpg');
}
I am using this template in a CMS and need it to change to a simple img tag so I can change the image used in the backend.
So instead of the HTML being
<div class="block-title__inner "></div>
It would change to
<div class="block-title__inner">
<img src="../media/bg/11.jpg"/>
</div>
Ive searched around but either nothing is out there or Im not using the correct terms, eitherway I cant find anything around how to do this so any help would be great.
This answer has been edited due to new found information:
The website in question is: headyherps.azurewebsites.net/available/adult/gregory
Instead of using a background-image CSS property as your theme has done by default, you'd like to place an img tag within the parent instead because you consider that the best way to manage the content.
So, Your HTML looks something like this:
<div class="block-title__inner section-bg section-bg_second">
<img src="../media/bg/11.jpg" alt="" />
<div class="bg-inner">
<!--header elements-->
</div>
</div>
Now in order to get the img to behave in a similar fashion to the background-position property we need to apply some CSS properties to it.
.block-title__inner img{
position: absolute;
left: 0px;
top: 0px;
width: auto;
height: auto;
min-width: 100%;
min-height: 100%; /* optional fail-safe for images that are too short */
}
I think something like this would work with inline styles.
<div style="background-image: url(../media/bg/11.jpg)"></div>
You can also use jQuery:
$(function(){
$('.block-title__inner').css("background", "url(../media/bg/11.jpg) ");
});
Don't forget to include it in your <head>
Another option ist to write a script that changes the parents style by using the src
https://jsfiddle.net/cdmp22ay/2/
If you want to keep the markup the same as:
<div class="block-title__inner"></div>
You can get the img src from the CSS class attached with jQuery and append the div with an image.
var bg = $('.block-title__inner').css('background-image');
bg = bg.replace('url(','').replace(')','');
console.log(bg);
$('.block-title__inner').append('<img id='theImg' src="' + bg + '" />');
I might not be explaining this too well, but I'm trying to apply the alternating div:nth class to just the indicated div (al-articles), but its getting applied to each child div inside <div class="al-articles"> - any pure css solution? This is for a WP category archive page and I want the post excerpts to have alternating background colors.
Below is the css I'm using
.al-articles {
Padding:0;
}
.al-articles div:nth-child(odd) {
background:#cccac6;
}
.al-articles div:nth-child(even) {
background:#f0eeec;
}
Thanks in advance
This is happening because you're telling the CSS to apply those styles to ALL divs that are children of .al-articles, not the .al-articles div itself.
Try this:
.al-articles:nth-child(odd) {
background:#cccac6;
}
.al-articles:nth-child(even) {
background:#f0eeec;
}
Just give an id to the main div
eg
<div id="main">
Content goes here!!!
</div>
and put inside it whatever you want.
Then to style it:
#main{
style goes here
}
www.angelodias.com.br/blog
My blog has a featured image inside a slider and several images through the post. To solve a problem (images on post bigger than column) I did this:
img {
max-width:450px;
height:auto;
}
The problem is: this code also changes my slideshow max-width to 450px, and that's not good. Is there a way for the CSS to work ONLY inside the post's text?
Example:
<div class="slideshow"> slideshow without custom IMG css, only template css </div>
<div class="entry-content"> post content with custom IMG css and template css</div>
You can try targeting the images use the entry-content container
.entry-content img {
// ....
}
If you use img tag, it will target all images on the page, where .entry-content img will only target the images inside of entry-content elements and that's where your images are and slide show are not.
WordPress allows to add max-width to images, simply go to Settings -> Media
or you can just select the images inside of your content, this should work:
.entry-content img {
max-width: 450px;
height: auto;
}
I have 2 pages that share the same stylesheet. How do I make changes to one, without affecting the other? I am new to coding, so please be specific as possible.
For Instance: I have a main image on the HOME page and want to delete it on the PRACTICE AREAS page but whenever I do so it deletes it on all pages.
Help please, and thank you in advance!
A good practice for styling pages differently is to have a class name applied to the body or to the enclosing div which corresponds to the page, e.g.:
<body class="home">
<div>Content here</div>
</body>
This gives you greater specificity, so in your CSS, you could be writing:
.home div {
background-image: url('your-image.jpg') no-repeat left top;
}
... or some such.
But, it sounds like the image on your home page is content, rather than its presentation. In that case you should be including it in the HTML rather than the CSS.
<body class="home">
<div><img src="your-image.jpg"> Content here</div>
</body>
Does that help?
As far as I know, you can not do conditionals with CSS. I suggest you create a second style sheet for your "Practice Areas" page and simply override the style element showing the main image. For example
/* On main style sheet */
body
{
background-image: url(../graphics/main_page.jpg);
}
/* On Practice Areas style sheet: */
body
{
background-image: none;
}
I am trying to remove a division but I am not able to remove the <div> tag. So I wanted to know if I can hide a division by adding some css codes on the page. The division I am trying to hide is <div id="views" class="menu">.... </div>
Any help?
Add the following CSS to your page or CSS file:
div#views { display:none; }
If you require the div to still occupy the space on the page, use the following instead:
div#views { visibility:hidden; }
Try
#views
{
display: none;
}
in your css