Solved

Featured Image 100% Width

Posted on 2015-02-05
11
95 Views
Last Modified: 2015-03-02
I am trying to size the featured image, or post thumbnail, to automatically stretch the image to 100% width of the div, regardless of the size of browser you are viewing the site in. I am able to get this to work with divs that have a background image using the style attribute cover. But since the featured image is not in the background this solution doesn't seem to work.

I have tried setting img for the div to 100% with no avail.

To reference the page in question, you can view http://mj2marketing.com/borror/2015/01/from-high-street-to-wall-street/. CSS is included below. I have not included size settings in functions.php.

#blog .featuredimg {
	
	width: 100%;
	height: 200px;
	padding-top: 300px;
	text-align: center;
	border-bottom: 5px solid #b51218;	
	
}

#blog .featuredimg img {
	
	width: 100%!important;
	-webkit-background-size: cover;
	-moz-background-size: cover;
	-o-background-size: cover;
	background-size: cover;	
}

Open in new window

0
Comment
Question by:43homes
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
The image has local html attributes for width and height and those override any styling.  The CSS rules are not being applied.

Cd&
0
 

Author Comment

by:43homes
Comment Utility
I thought about. I added it as a featured image using the dialogue in wordpress. I can see when trying to edit the image there that it has the dimensions set as 600 x 300 (which is the image's original size). I don't appear to have an option to not apply a size in the edit image options.  Any ideas on how to remove this html attribute that appears to be set by the featured image?
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
If the dialogue tool is not allowing you to do a simple thing like write a line of code then don't use it and write the code yourself.  If you are limited to working through and abstracted level and can't code then you need to be prepared to live with very limited capabilities, or hire a professional to do the work for you.

If you look at the backend of the dialogue you should see what variables are being set for the width/height, and then you just need to eliminate the bit of code that generates the image portion of the page.

Or you can wait and see if Jason or one of the other WP internals guys come along.  I don't do WP internals, and most of the time I would rather it did not exist.

Cd&
0
 

Author Comment

by:43homes
Comment Utility
I came for help, not lectures. I rather people who are snarky and have this attitude just chose not to respond. Best to you.
0
 
LVL 15

Expert Comment

by:eemit
Comment Utility
You can try to add this to your child theme's style.css:
#featuredimg img {
    max-width: 100%;
    height: auto;
    width: 100%;
}
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Accepted Solution

by:
Lucas Bishop earned 500 total points
Comment Utility
I can see when trying to edit the image there that it has the dimensions set as 600 x 300 (which is the image's original size). I don't appear to have an option to not apply a size in the edit image options.

I believe what you want to do is switch the wordpress wysiwyg editor from Visual (rich text) to Text (code) view. This will give you access to remove the height/width attributes from the img.

This feature is not part of the "edit image" console. It's on the main post editor in the top right.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
Snarky??? Oh I get it anyone who expects someone using a tool to actually be familiar with how it works is snarky.

To be a plumber you need a license and testing to demonstrate you actually know how to do the job; maybe we need the same for those who think they are web developers because they can get a WP page to render without hanging the browser.

Cd&
0
 
LVL 7

Expert Comment

by:Alicia St Rose
Comment Utility
You may also want to install the plugin called "Regenerate Thumbnails". Once you use an image as featured it's sort of cached at a specific size until you regenerate.

You can add a few lines of code and have your own featured image sizes:

In the functions.php you can add this code:

add_image_size('blog-archive',225,225, true);

Open in new window


This is an example of a new attachment image size I've created for my theme. The values are: name, height, width, and true/false for hard crop.

Once you've added this to your functions.php, simply add the name of new image size inside the parentheses your featured image code like this:

<?php the_post_thumbnail('blog-archive'); ?>

Open in new window

0
 

Author Comment

by:43homes
Comment Utility
I've requested that this question be deleted for the following reason:

No answers were sufficient.
0
 
LVL 7

Expert Comment

by:Alicia St Rose
Comment Utility
There were plenty of sufficient answers here. I believe that our answers were not able to be implemented do to the limited knowledge of the poster regarding WordPress development.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
I agree with laugh; if the user is not skilled enough to implement simple solutions, they need to either upgrade their skills or hire a professional to do the work for them.  The Experts did not fail to respond with appropriate solutions and should not be penalized because the skills required to implement are outside the range of the user.

Cd&
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now