I have the following code on a wordpress site. I can't change the html, so, only using css #media queries I would like to make the list go from 4 per row on a desktop, down to 2 per row in a viewport of under 767px.
Is that possible?
.recent_view_prod ul.product_list_widget li {
width: 22%;
margin-right: 2%;
}
.recent_view_prod ul.product_list_widget li img {
width: 100%;
float: left;
}
.recent_view_prod ul.product_list_widget li {
display: inline-block;
}
.recent_view_prod span.product-title {
display: none;
}
a:hover > .attachment-shop_thumbnail + span {
display: block;
position:absolute;
}
<div class="wpb_widgetised_column wpb_content_element recent_view_prod">
<div class="wpb_wrapper">
<div id="woocommerce_recently_viewed_products-3" class="widget woocommerce widget_recently_viewed_products">
<h3 class="widget-title element-title">Recently Viewed Products</h3>
<ul class="product_list_widget">
<li>
<a href="http://uc.petekirkwood.co.uk/shop/opulent-bloom-card-holder/" title="Opulent Bloom Card Holder">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/TedBaker_CardHolderOpulentBloom_2-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="TedBaker_CardHolderOpulentBloom_2"> <span class="product-title">Opulent Bloom Card Holder</span>
</a>
</li>
<li>
<a href="http://uc.petekirkwood.co.uk/shop/store-ms/" title="Store-M's Nesting Food Boxes">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/StoreMs1-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="StoreMs1"> <span class="product-title">Store-M's Nesting Food Boxes</span>
</a>
</li>
<li>
<a href="http://uc.petekirkwood.co.uk/shop/happy-jackson-crackers-tin/" title="Happy Jackson Crackers Tin">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/HappyJCrackersTIn-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="HappyJCrackersTIn"> <span class="product-title">Happy Jackson Crackers Tin</span>
</a>
</li>
<li>
<a href="http://uc.petekirkwood.co.uk/shop/happy-jackson-snack-box-set/" title="Happy Jackson Snack Box Set">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/SnackBoxSetx4_2-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="SnackBoxSetx4_2"> <span class="product-title">Happy Jackson Snack Box Set</span>
</a>
</li>
</ul>
</div>
</div>
</div>
Try using float: left in the under 767px and increase the width of <li>.
For example try this code:
.recent_view_prod ul.product_list_widget li {
float: left;
margin-right: 2%;
width: 40%;
}
It's entirely possible to do this. You could have your default code as something like this (mobile first approach) - you may need to play around with the percentage to make sure the two fit side by side:
.recent_view_prod ul.product_list_widget li {
display: block;
float: left;
width: 47%;
margin-right: 2%;
}
.recent_view_prod ul.product_list_widget li img {
width: 100%;
float: left;
}
.recent_view_prod ul.product_list_widget li {
display: inline-block;
}
.recent_view_prod span.product-title {
display: none;
}
a:hover > .attachment-shop_thumbnail + span {
display: block;
position:absolute;
}
and then add a media query at the end (again adjust the min-width to suit you) that brings them back to the four column layout as you currently have it, as the screen widens.
#media (min-width: 25em){
.recent_view_prod ul.product_list_widget li {
width: 22%;
}
}
Related
I wish too have text directly below my images so I tried the following but it did not work. I want the text direclty below and to the centre of the picture
<div class="our_partners">
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12">
<ul>
<li><img src="<?php echo esc_url(wp_get_attachment_url( $image1, 'full' )); ?>" alt="">
<span>High Speed Wifi</span> </li>
<li><img src="<?php echo esc_url(wp_get_attachment_url( $image2, 'full' )); ?>" alt="">
<span> Latest Av Technology</span>
</li>
<li><img src="<?php echo esc_url(wp_get_attachment_url( $image3, 'full' )); ?>" alt="">
<span> Online Booking</span>
</li>
<li><img src="<?php echo esc_url(wp_get_attachment_url( $image4, 'full' )); ?>" alt="">
<span> Concierge Service</span>
</li>
<li><img src="<?php echo esc_url(wp_get_attachment_url( $image5, 'full' )); ?>" alt=""></li>
</ul>
</div>
</div>
</div>
</div>
You can see the result here
and you can see it live here if you scroll down to services
http://ubtanz.solitudesoftware.co.uk/
Give img
.our_partners ul li a img {
padding: 29px 0;
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
}
Remove margin-right: 15px; to margin-right: 0;
.our_partners ul li a {
margin-right: 0;
}
to li
.our_partners ul li {
display: inline-block;
margin: 0px 5px;
}
and
span {
display: block;
text-align: center;
}
.our_partners ul li a {
margin: auto;
}
.our_partners ul li a img {
padding: 10px 0;
max-width: 100%;
max-height: 100%;
}
.our_partners ul li a {
width:230px;
text-align:center;
}
Throw this in your custom.css - makes it centered.
I'd recommend using the margin-right: 15px property on the list element, and not the anchor element because it makes more sense. You are separating between the list elements and not the anchors.
With that change in mind, all you need to do now is set the span element to take 100% of the available width, and center align its content.
.our_partners li {
margin-right: 15px;
}
.our_partners a li span {
text-align: center;
display: inline-block;
width: 100%;
}
and remove your current margin set from the anchor element:
.our_partners ul li a {
margin-right: 15px; // <- remove this line
}
Easy way, use <br/>:
<ul>
<li>
<img src="..." alt=""><br/>
<span>High Speed Wifi</span>
</li>
(...)
A better way, threat one of the part as a block, by default, a img and span tags are inline:
<ul>
<li>
<img src="..." alt="">
<span>High Speed Wifi</span>
</li>
(...)
Externalize the css style in a class. You could even wrap the linked image into a block span:
# foo.css:
span.span-block { display: block; }
...
# 42.html
<span class="span-block"><a ...><img .../></a></span>
...
Put the text inside the <a></a> tag, like so:
<li>
<a href="#"><img src="...s2-3.png" alt="">
<span style="display:block;">High Speed Wifi</span>
</a>
</li>
EDIT To ensure that all images are aligned, you can set the last image up as:
<li>
<a href="#"><img src="...cons-2.png" alt="">
<span style="display:block;"> </span>
</a>
</li>
Further, you can obviously set a style on the <span> element in your css file, to cut down on repetition.
I'm trying to make image two appear below image one when a mouse hovers over image one.
<ul>
<li>
<img id="img1" src="imageone.png">
<br>
<img id="img2" src="imagetwo.png">
</li>
</ul>
Help is appreciated!
So far I have this CSS which does not seem to work
#img2 {
display: none;
position: absolute;
}
#img1:hover + #img2,
#img2:hover {
display:block;
}
The + selects siblings that are immediately after. Your images are not, because they are separated with a <br>.
Use ~ instead:
#img1:hover ~ #img2
You are very close.
First, remove the <br> tag since it breaks the adjacent sibling selector.
The hover works as long as you over over the first image.
If you apply display: block to the img, then you don't need the <br> tag.
Depending on your layout, the tilde (~) selector could also work but it depends on whether you have other images in the layout (I am thinking a photo gallery).
ul {
list-style: none;
}
#img2 {
display: none;
}
#img1:hover + #img2 {
display: block;
}
<ul>
<li>
<img id="img1" src="http://placehold.it/150x50">
<img id="img2" src="http://placehold.it/150x50">
</li>
</ul>
use the tilde instead of the + sign, because you have a br inbetween
#img2 {
display: none;
position: absolute;
}
#img1:hover ~ #img2,
#img2:hover {
display:block;
}
<ul>
<li>
<img id="img1" src="imageone.png">
<br>
<img id="img2" src="imagetwo.png">
</li>
</ul>
You may be after something like this:
.parent{
position: relative;
}
.holder{
position: fixed;
width: 100px;
height:100px;
background-color: #efefef;
}
.img{
width: 100px;
height:100px;
background-color: #ffefef;
}
#img2{
display: none;
}
.holder:hover #img2{
display: block;
}
<ul>
<li class="parent">
<div class="holder">
<img class="img" id="img1" src="imageone.png">
<br>
<img class="img" id="img2" src="imagetwo.png">
</div>
</li>
</ul>
I have a wordpress recently viewed products widget. I would like the name of the product to show up over the image, when you hover over it.
I have it working elsewhere, the difference is than with this widget, the li do not have a class attached. I know the line I need to fix is:
.product_list_widget ul li .attachment-shop_thumbnail:hover span.product_title {
I just don't know what it should be changed to, to show the span when the image is hovered!
For the first time I got a fiddle to work!
Any ideas?
.recent_view_prod ul.product_list_widget li {
width: 22%;
margin-right: 2%;
}
.recent_view_prod ul.product_list_widget li img {
width: 100%;
float: left;
}
.recent_view_prod ul.product_list_widget li {
display: inline-block;
}
.recent_view_prod span.product-title {
display: none;
}
.product_list_widget ul li .attachment-shop_thumbnail:hover span.product_title {
display: block!important;
z-index: 100;
position: absolute;
font-size: 1vw;
line-height: 1.5em;
text-align: left;
padding-left: .5em!important;
padding-right: .5em!important;
color: white;
background-color: rgba(160, 163, 162, 0.8);
left: 0px;
bottom: 25px;
width: 75%;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
<div class="wpb_widgetised_column wpb_content_element recent_view_prod">
<div class="wpb_wrapper">
<div id="woocommerce_recently_viewed_products-3" class="widget woocommerce widget_recently_viewed_products">
<h3 class="widget-title element-title">Recently Viewed Products</h3>
<ul class="product_list_widget">
<li>
<a href="http://uc.petekirkwood.co.uk/shop/opulent-bloom-card-holder/" title="Opulent Bloom Card Holder">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/TedBaker_CardHolderOpulentBloom_2-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="TedBaker_CardHolderOpulentBloom_2"> <span class="product-title">Opulent Bloom Card Holder</span>
</a>
<span class="amount">£19.95</span>
</li>
<li>
<a href="http://uc.petekirkwood.co.uk/shop/store-ms/" title="Store-M's Nesting Food Boxes">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/StoreMs1-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="StoreMs1"> <span class="product-title">Store-M's Nesting Food Boxes</span>
</a>
<span class="amount">£11.95</span>
</li>
<li>
<a href="http://uc.petekirkwood.co.uk/shop/happy-jackson-crackers-tin/" title="Happy Jackson Crackers Tin">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/HappyJCrackersTIn-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="HappyJCrackersTIn"> <span class="product-title">Happy Jackson Crackers Tin</span>
</a>
<span class="amount">£6.99</span>
</li>
<li>
<a href="http://uc.petekirkwood.co.uk/shop/happy-jackson-snack-box-set/" title="Happy Jackson Snack Box Set">
<img width="180" height="135" src="http://uc.petekirkwood.co.uk/wp-content/uploads/2015/06/SnackBoxSetx4_2-180x135.jpg" class="attachment-shop_thumbnail wp-post-image" alt="SnackBoxSetx4_2"> <span class="product-title">Happy Jackson Snack Box Set</span>
</a>
<span class="amount">£9.99</span>
</li>
</ul>
</div>
</div>
</div>
If you want to use css only solution, you could use adjacent selector:
img.attachment-shop_thumbnail.wp-post-image:hover + span {
display: block;
position:absolute;
}
This targets element immediately after your img element, and you don't need to know the class of your span for that.
Only requirement, you'll need to stick to, is that span has to be immediately after imgin your markup.
Another alternative might be sibling combinator selector:
img.attachment-shop_thumbnail.wp-post-image:hover ~ span {
display: block;
position:absolute;
}
which only require your span element to be after img but not necessary immediately.
Here is the JSFiddle with that.
You should use following selector:
ul.product_list_widget li .attachment-shop_thumbnail:hover span.product-title {
//styles as above
}
Your <ul> tag has class "product_list_widget" so following selector:
.product_list_widget ul li .attachment-shop_thumbnail:hover + span.product-title
wouldn't work, because that would require <ul> to be inside element that has class "product_list_widget".
ive been stuck trying to float these pictures into two columns for days. They just stay centered no matter how small i make them. They will be very small and still not float, one time they did float but i cant get back to that and even when they did they were all messy and not making columns, i just want to make columns. i used the .group1 and .group2 classes to target the things to float
<ul class="secondary-content group">
<div class="group1">
<li>
<img src= "MB6.jpg" alt="Wonderful evening">
<p>I've had a perfectly wonderful evening. But this wasn't it.</p>
<p>-Groucho Marx</p>
</li>
<li>
<img src="love3.jpg" alt="Marilyn Monroe">
<p>"A man's only as old as the woman he feels."</p>
<p>-Groucho Marx</p>
</li>
<li>
<img src="MB5.png">
<p>"I intend to live forever, or die trying."</p>
<p>-Groucho Marx</p>
</li>
</div>
<div class="group2">
<li>
<img src="MB2.jpg">
<p>Groucho: "Get outta here before I get arrested."</p>
<p>Chico: "Nah I'd like to stay and see that."</p>
<p>-Groucho Marx</p>
</li>
<li>
<img src="MB4.jpeg">
<p>"honk honk"</p>
<p>Harpo Marx</p>
</li>
<li>
<img src="MB9.jpg">
<p>Groucho: "Do you follow me?"</p>
<p>Margaret Dumont: "Yes!"</p>
<p>Groucho: "Well, you better stop following me, or I'll have you arrested."</p>
</li>
</div>
</ul>
* {
box-sizing: border-box;
}
a {
text-decoration: none;
}
img {
max-width: 100%;
}
a h1 {
text-align: center;
}
.main-header{
padding-top: 50px;
height: 1000px;
background: linear-gradient(#fff, transparent 60%),
linear-gradient(0deg, #fff, transparent 50%),
url('../MarxBros.jpg') no-repeat center;
}
.intro{
text-align: center;
}
.secondary-content{
width: 40%;
padding-left: 20px;
padding-right: 20px;
margin: 0 auto;
max-width:300px;
text-align: center;
;
}
.secondary-content img{
max-width:300px;
}
.group1 li {
float: left;
}
.group2 li {
float:right
}
.group:after {
content: "";
display: table;
clear: both;
}
You need to fix your HTML structure. Only <li> elements can be direct children of <ul> elements. In this new structure I created two <ul> elements and changed the float to the <ul>'s rather than the <li>'s: jsfiddle
<ul class="secondary-content group group1">
<li>
<img src= "MB6.jpg" alt="Wonderful evening">
<p>I've had a perfectly wonderful evening. But this wasn't it.</p>
<p>-Groucho Marx</p>
</li>
...
</ul>
<ul class="secondary-content group group2">
<li>
<img src="MB2.jpg">
<p>Groucho: "Get outta here before I get arrested."</p>
<p>Chico: "Nah I'd like to stay and see that."</p>
<p>-Groucho Marx</p>
</li>
...
</ul>
.group1 {
float: left;
}
.group2 {
float:right
}
.group:after {
content: "";
display: table;
clear: both;
}
In this situation what would be the best way to get my products aligned horizontally?
I have created a fiddle: http://jsfiddle.net/bxSE6/
CSS:
.cart-collaterals .cross-sells,
.cart-collaterals .cart_totals,
.cart-collaterals .shipping_calculator {
width: 48%;
float: right;
}
.cart-collaterals .cross-sells {
float: left;
}
.cart-collaterals .cross-sells ul.products li {
width: 48%;
margin-right: 3.8%;
}
.cart-collaterals .cross-sells ul.products li:nth-child(2n) {
margin-right: 0;
}
.cart-collaterals .cross-sells ul.products li.last {
margin-right: 3.8%;
}
HTML:
<div class="cross-sells">
<h2>You may be interested in…</h2>
<ul class="products">
<li class="post-430 product type-product status-publish hentry first instock">
<a href="http://www.drdermacare.co.nz/product/skin-polishing-cloth/">
<div class="img-wrap"><img width="400" height="319" src="http://www.drdermacare.co.nz/wp-content/uploads/2013/05/SkinPolishingCloth_7-400x319.jpg" class="attachment-shop_catalog wp-post-image" alt="SkinPolishingCloth_7" /></div> <!--/.wrap-->
<h3>Skin Polishing Cloth</h3>
<span class="price">NZD <span class="amount">$12.95</span></span>
</a>
Learn MoreBuy Now
</li>
<li class="post-436 product type-product status-publish hentry last instock">
<a href="http://www.drdermacare.co.nz/product/sos-acne-prevention-pen-new/">
<div class="img-wrap"><img width="328" height="400" src="http://www.drdermacare.co.nz/wp-content/uploads/2013/05/SOS-AcnePen-HIGH-RES_7-328x400.jpg" class="attachment-shop_catalog wp-post-image" alt="SOS-AcnePen HIGH RES_7" /></div> <!--/.wrap-->
<h3>SOS Acne Prevention Pen NEW!</h3>
<span class="price">NZD <span class="amount">$24.95</span></span>
</a>
Learn MoreBuy Now
</li>
</ul>
</div>
Try this
.product { display: inline-block; }
I just tried it and it works.
I hope that this is ok?
http://jsfiddle.net/bxSE6/1/
.products li {
list-style-type:none;
text-align:center;
}
I'd suggest:
.prooducts li {
float: left;
}