Solved

Featured Image 100% Width

Posted on 2015-02-05
11
100 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40592249
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
ID: 40592271
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
ID: 40592318
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:43homes
ID: 40592373
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
ID: 40592532
You can try to add this to your child theme's style.css:
#featuredimg img {
    max-width: 100%;
    height: auto;
    width: 100%;
}
0
 
LVL 17

Accepted Solution

by:
Lucas Bishop earned 500 total points
ID: 40593086
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
ID: 40594052
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
ID: 40595300
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
ID: 40639790
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
ID: 40639791
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
ID: 40640659
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
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.

749 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