Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am using Sunrise Theme from s5themes.com , and I was wondering if in the individual pages I can have a different Header Image, because from what I can tell they use the same CSS code in displaying the header image on the Home Page.
Here is the screenshot of the Home page showing the Image as header
And here is the screenshot of the a Page (About Us) which uses the same Image (the brown texture with green part) as header only seemed zoomed-in.
I tried digging into the code and I believe this is the part in the Styles.css that deals with it.
CSS
.header-wrapper {
background: #333;
background-image: url(img/wood-only.png);
background-attachment: fixed;
background-size: cover;
min-height: 200px;
So I edited the code above, unfortunately it also affects the Image in the Home page
I tried setting the background-size into
background-size: auto;
Ideally I can work with editing the template files but I am not familiar with WordPress' structure, and now I am not sure how to procede.
In WordPress, the header is defined by default in "header.php". You need ftp access, and copy header.php, rename it header2.php, make your changes, save. Then copy whatever your main page template is, and replace the with and save that as a different file, such as main2. Make sure to change the name in the commented area at the top so WordPress will show a distinct name for that template. Upload your new pages to your theme directory. On the pages which you want to have the changed header, select your new page template and save.
Walk in the park.
I managed to solve this without relying too much on creating new templates, by using JetPack plugin.
And took advantage of it's ability to add Custom CSS
This is the CSS line I added
body.page .header-wrapper {
background: #333;
background-image: url(http://image-url/image.png);
background-attachment: fixed;
background-size: auto !important;
min-height: 200px;
}
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
i have the following issue : background image was perfectly working, then after deployment it's not, the image is in a folder in the public folder here is my code :
react component :
function Header() {
return (
<div className="bannerContainer">
<div className="banner">
<h1>news reader</h1>
</div>
<h3>USER GUID</h3>
</div>
)
}
css styling :
.banner {
height: 20vh;
width: 100%;
background-image: url('/images/banner1.png');
background-position: center;
background-size: cover;
background-repeat: no-repeat;
}
'/images/banner1.png' is an absolute path. It will start at whatever is considered to be the root. This can be different for your local environment and deployed environment.
It's best practice to use relative paths, so that it is not dependent on where the root starts:
background-image: url('../relative/path/to/banner1.png'); /* example 1 */
background-image: url('./also/relative/path/to/banner1.png'); /* example 2 */
EDIT: To test whether the problem is with your url, replace your path with a regular image link we know works. Something like:
background-image: url("https://homepages.cae.wisc.edu/~ece533/images/airplane.png");
If the image does appear in the background, then the problem is definitely with your image path.
In that case I'd recommend playing around with it. Place the image in the same folder as the CSS file trying to access it, and see if you can get any success there before moving the image further away.
I am trying to change my products image on hover in woocommerce in wordpress !!!
I tried some plugins I saw like Woocommerce Product Image Flipper & Magni Image Flip for Wocommerce but they are not working for some reason and I tried the solutions you are suggested here in some similar questions .
So do you know another plugin free or not I dont care or do you know maybe an other solution with CSS maybe I dont know
I am using
Wordpress Version : 5.3.2
Wordpress Theme : Flatsome
Woocommerce Version : 3.9.2
Thank You for helping and sorry for my English :)
ok #st3ph3n92 it is working for me !!!
I just write custom css for the 10-20 products I have online every day so for now I am fine !!!
Now in the future I hope there is plugin to do this job ^^
Thank you again for your help #st3ph3n92
#N. Mar, Yes, the custom URL I used was only as an example. With background-image: url("img2"), that would select img2 if it is the same folder as your CSS file. However, if your images are kept in a separate folder, for example "images", the CSS might be background-image: url("images/img2").
There is a StackOverflow post on folder paths here that might be quite useful: What does "./" (dot slash) refer to in terms of an HTML file path location?
Because you're using WooCommerce, I imagine how you're images are stored is a little different. This article might shed some light on it: https://enviragallery.com/where-does-wordpress-store-uploaded-images/
If you want this to be automatic on Wordpress, you will need to use PHP. The issue is that you cannot use PHP in CSS. Instead, you would need to add the styles inline or in the head of the theme's html (as opposed to a separate stylesheet) and then use PHP to reference the image. This is a good bit trickier. There's another Stackoverflow post on that here: CSS background images in WordPress
if you have access to the CSS, you could try setting the image as the background of the div it is in. You could then use the :hover selector to set a new background image.
You can see this on the CodePen here: https://codepen.io/St3ph3n92/pen/BaopGQx
Or run this snippet:
.image-holder {
height: 300px;
width: 300px;
border: 3px solid black;
margin: 0 auto;
background-image: url("https://images.unsplash.com/photo-1491553895911-0055eca6402d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=80");
background-size: contain;
}
.image-holder:hover {
background-image: url("https://images.unsplash.com/photo-1514218953589-2d7d37efd2dc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60")
}
<div class="image-holder"><div>
I hope this helps.
Thank you St3ph3n92 for your answer
So can I change this code with something like this ???
.product-image {
height: 770px;
width: 1155px;
border: none;
margin: 0 auto;
background-image: url("img1");
background-size: contain;
}
.product-image:hover {
background-image: url("img2")
}
<div class="product-image"><div>
I mean that I want something more automatic cause I have 700+ products so I cant insert custom URLS for each one !!! I need a code so on hover my main Products image change with the second image from Product Gallery
Thanks again for your answer !!!
I had the same issue on some of my websites with the same configuration as yours.
Until a few days ago, I had that flipping effect on my products. It was by default, I didn't install any plugin for this feature. Today I noticed that it's not working anymore.
I managed to solve this issue by disabling Autoptimize plugin. I don't know if you use the same plugin, but maybe my answer will help you.
I'm constructing a website using the Tesseract theme by Tyler Moore. I want to make the header fixed and 80% opaque for every page of the website. The header for the home page has a slider for transparency under customization and I managed to make it fixed by changing its position by editing the site-banner css file in cpanel. My question is, how can I apply the same setting to all the other pages of my website? Thank you in advance!
On the wordpress dashbord, hover on the appearance tab, then click on editor. On the right, select stylesheet. Then paste this code at the end of the stylesheet.
#masthead_TesseractTheme {
position: fixed;
margin:auto;
z-index:100000;
opacity: 0.8;
}
Then click Update file.
Click here the see the Procedure on how to locate and edit the stylesheet
There are two CSS files referenced on the same page: A generic.css file and a custom.css file. The generic file has default styles in it that are overridden by the custom.css file for the same elements. This allows users of the site to customize or "skin" their pages without needing to recreate the entire generic.css file. Only a few styles would be overridden.
My question is the following: If the generic.css file has a style for an element with a background image and that same style is overridden in the custom.css with a different background image, is the first image ever downloaded by the browser?
Also, I want to find out if this is bad practice - customizing or "skinning" a generic CSS file with another custom CSS file to override a few styles, including specifying different background images.
While not totally definitive, this site ran some tests regarding this. The significant statement from that site that is related to your question is:
CSS images are kicked off not in the order in which they appear in the
CSS but in the order in which they’re called in the HTML. I’m not sure
of the precise moment when the download is initiated, but my guess is
that it happens just after the CSS rules have been matched, when the
property values are assigned to the DOM elements.
This at least tentatively confirms what I thought I remembered in the back of my mind reading on this a few years back, namely, that background images which are not ever displayed (as in the generic.css images being overridden by the custom.css images) are not ever downloaded.
Further confirmation of this would be the typical image preloader script that used to be so common prior to sprite images (and is still found in certain uses). It was designed to download images that would be used on :hover in css, because without it, the image would not load until the first hover was initiated, and this caused an unsightly delay. So that, also, argues for the fact that unless actually displayed (or preloaded), the background images themselves are never loaded.
I don't think there are generally any issues with "skinning," unless you are essentially overwriting most or all of the generic.css with custom.css, then one could argue, why load the generic at all. But as you said, normally there are just a few styles overwritten.
I think i answered NO and NO BAD PRACTICE. Because when the css file readable / executable by the browser, the browser will make comparisons to find the same value or the difference between css file and then combine them.
Easy example:
css1.css on file there is a line:
.test {display: block; width: 100%; height: 600px; background: #991100 url("image1.jpg") center top; border: 1px solid red;}
then the css2.css there is also the line:
.test {background: #991100 url("image2.jpg") no-repeat center center;}
the result of a combination that will be executed and run by the browser are:
.test {display: block; width: 100%; height: 600px; background: url("image2.jpg") no-repeat center center # 991100; border: 1px solid red}
where the "background: # 991100 url("image1.jpg") center top;" read but not called / executed by the browser.
Far as I know the value of the file css1.css be stacked by the value of the css2.css. What if there a css3.css file? then the file css3.css will also stacking on the combination of css1.css and css2.css.
Hope it helps.
I have a WP site that i am trying to pimp a little.
It will be a place to check out iPhone accesories and i want it to have the iphone look.
I have made a background that i am pleased with but i want to put the background picture over the whole page so the "frame" of the iphone lookalike thing i´ve done is visible all the time and the content of the WP gos under it when scrolled.
My wp is here:
http://www.metalagency.com
and the image that i want to be on top is here:
http://www.metalagency.com/wp-content/themes/twentyeleven/images/testdiv.png
The white section of the image is transparent so i want the wp site to visible in that area.
Am i making any sense here?
Sorry if it is a stupid q but i dont seem to find any answer anywhere on this.
I understand that i need to do some css styling but i am not sure where to put it.
Pls help a slow Swede....
Thanx.
//R
Bookmarklet preview: open your page, copy into location bar, press enter:
javascript:sa=document.styleSheets;sa[sa.length-1].insertRule('#page { background: transparent; height: 700px; overflow: scroll; }');
You should create a simple child theme first (if you don't want your modified twentyeleven theme overwritten by an automattic update): http://codex.wordpress.org/Child_Themes#The_required_style.css_file and put all your modifications there.
Sample style.css:
/*
Theme Name: myPhoney theme
Template: twentyeleven
*/
#import url("../twentyeleven/style.css");
#page {
background: transparent;
height: 700px;
overflow: scroll;
}