Targeting the text in an anchor element but not the image - html

I do not want the picture to be underlined, but I need the hyperlink in the text to be underlined. How can I do that? It is a wordpress theme so I can't change the html I have to stay with css
.post-desc a{
border-bottom: 1px solid #FBCF00;
}
.post-desc a img{
border-bottom: none;
}
<div class="post-desc">
<img class="alignnone wp-image-2763 size-full" src="http://www.montrealguidecondo.ca/news/wp-content/uploads/2016/01/exterieur-1.jpg" alt="extérieur de Tod condo" width="639" height="438">
</div>

You can remove it under the image using display:table; on image, like this:
.post-desc a img{
border-bottom: none;
display:table;
}
Snippet:
.post-desc a {
border-bottom: 1px solid #FBCF00;
}
.post-desc a img {
border-bottom: none;
display: table;
}
<div class="post-desc">
<a href="http://www.montrealguidecondo.ca/news/wp-content/uploads/2016/01/exterieur-1.jpg" target="_blank" rel="attachment wp-att-2763">
<img class="alignnone wp-image-2763 size-full" src="http://www.montrealguidecondo.ca/news/wp-content/uploads/2016/01/exterieur-1.jpg" alt="extérieur de Tod condo" width="639" height="438">
</a>
</div>

to make it simple you may use vertical-align with a negative value to drop img as much as needed under the base line:
a {
border-bottom: solid;
}
a img {
vertical-align: -0.5em;/* average -0.25em equals vertical-align:bottom */
/* demo purpose: see border under img */
opacity:0.75;
}
text
<a href="#">
<img src="http://dummyimage.com/60" />
</a>
within the last stylesheet of your website , test this
a img {
margin-top:0.5em;
vertical-align: -0.5em;
}
or if you like better:
a img {
position:relative;
top: 0.5em;
}
The idea is to hide the border with the image itself

Text decoration underline
<div><a style="text-decoration:underline" href="http://www.montrealguidecondo.ca/news/wp-content/uploads/2016/01/exterieur-1.jpg" target="_blank" rel="attachment wp-att-2763"><img class="alignnone wp-image-2763 size-full" src="http://www.montrealguidecondo.ca/news/wp-content/uploads/2016/01/exterieur-1.jpg" alt="extérieur de Tod condo" width="639" height="438"></a>

You have set the border attributes on the <a> tags, so you can't just remove them on the containing <img> elements. Unfortunately, there is no "conatining" selector in css (yet) and apparently you can't edit the html, so we have to stick with the informations we've got.
The links with the containing images have the word attachment in the attribute rel. This is how to select them and disable their border:
a[rel~="attachment"] {
border-bottom: none !important;
}

Related

How to make a text stand by the right side of an image using html and css

i need help to get the text to stand by the right side of the image on the same level i have this
<a class="following-row" href="index-2.html?pid=2306">
<img alt="Girls logo" src="photos/users/35257/resized/9fd79de3589edff68db18bb6141025c3.jpg">
<span class="following-row-text">Girls<span class="item-details"> · 78 followers</span></span>
</a>
i cant get to have a correct set of css styling that give me what i want, please i need help.
thanks
<div>
<img style="vertical-align:middle" src="http://cdn.jssor.com/demos/img/icons/icon_chrome.png">
<span style="">Girls · 78 followers</span>
</div>
Check this snippet
Updated the answer based on comments.
a.wrapper img {
cursor: pointer;
width: 100px;
height: 100px;
vertical-align: middle;
text-decoration: none;
}
a.wrapper span {
padding-left: 10px;
cursor: pointer;
}
a.wrapper:hover img {
margin: -1px;
border: 1px solid red;
}
a.wrapper:hover span {
color: red;
}
<a hre="#" class="wrapper">
<img src="http://pipsum.com/100x100.jpg" alt="Image">
<span>Girls · 78 followers</span>
</a>

CSS Link hover not for images

I have a scenario where I want to have the text links with border-bottom, and set-up the css like this
a:hover {
color: #492512;
border-bottom: 2px dashed #94705A;
}
The problem is that the images that are wrapped in links also have this border-bottom, eg.
<a href="home">
<img src="logo.jpg" alt="Logo" class="logo-img">
</a>
How can I target the a:hover that it is only for text links? Pure CSS would be preferable.
No problem.
Add a class to your text links. Then target those links like this.
a.testing:hover {
color: #492512;
border-bottom: 2px dashed #94705A;
}
<a href="home">
<img src="http://cdn.sstatic.net/stackoverflow/img/sprites.svg?v=bc7c2f3904bf" alt="Logo" class="logo-img">
</a>
<a class="testing" href="home">
TESTING
</a>
Hope this helps.
Added with EDIT
Here is Another Option
a:hover {
color: #492512;
border-bottom: 2px dashed #94705A;
}
a[href*='ignorethis'] {
text-decoration: none !important;
border-bottom: 0 none !important;
}
<a href="http://www.milk.com?ignorethis">
<img src="http://s.w.org/style/images/wp-header-logo.png" alt="Logo" class="logo-img">
</a>
<a href="http://www.milk.com">
TESTED
</a>
This achieves the same thing by targeting target all anchors whose href attribute contains the given value ('ignore this'). Other ways this can be used.
attribute *= contains value
attribute ^= begins with value
attribute $= ends with value
To use this just append '#special-test-value' to the end of the link or in the case of a targeted link append '?special-test-value=0' or in the case where the query string already exists use '&special-test-value=0'
I thought this was an interesting way to target links and that it might be new to a lot of people.
Another use case
If the case is that a single url or a specific set of urls you could use them to end target them and exclude the anchored images that way.
a[href$='somedomain.com/url1/'], a[href$='somedomain.com/url2/'], a[href$='somedomain.com/url.../'], a[href$='somedomain.com/urlN/'] {
text-decoration: none !important;
border-bottom: 0 none !important;
}
OK that's it have a great night.
Two ways, either wrap the text in a span (below sample) or set a unique class to links with text only.
a {
text-decoration: none;
}
a:hover {
color: #492512;
}
a:hover :not(img) {
border-bottom: 2px dashed #94705A;
}
<a href="home">
<img src="http://placehold.it/50/100/" alt="Logo" class="logo-img" />
</a>
<br>
<br>
<a href="home">
<span>Text</span>
</a>
It seems that pure CSS global styling doesn't work, so I resorted to jQuery to add a class to anchors which have images, like this:
jQuery("a").each(function(){
if ( jQuery(this).children('img').length > 0 ) {
jQuery(this).addClass("noborder");
}
});
And the CSS is:
a:hover {
border-bottom: 2px dashed #94705A;
}
a.noborder:hover {
border-bottom: none;
}
Thanks for all the comments and suggestions.
Cheers!
Well you can make a separate class for image links:
a:hover {
color: #492512;
border-bottom: 2px dashed #94705A;
}
a.image-anchor:hover {
border-bottom: 0 none;
}
<p>Text link</p>
<p><a class="image_anchor" href="stackoverflow.com"><img src="https://blog.stackoverflow.com/images/wordpress/stackoverflow-logo-300.png"></a></p>

HTML/CSS Adding a grey background to a table

so I am pretty much making a table with images that when you hover over show color. Right now it's pretty much just very simple, but I was wondering how I could add a border to do the table, and maybe a grey background?
My HTML:
<table>
<tbody>
<tr>
<td><a href="http://online.wsj.com/news/articles/SB10001424052702304626804579361520890893170" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/wsj1.png" alt="" />
</a></td>
<td><a href="http://www.forbes.com/sites/rodebrahimi/2013/12/12/how-crowdfunding-will-impact-real-estate-investing-an-interview-with-realtyshares/" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/forbes1-1.png" alt="" />
</a></td>
<td><a href="http://money.cnn.com/news/newsfeeds/gigaom/articles/2014_02_04_finally_you_can_do_something_useful_with_bitcoin_invest_in_real_estate.html" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/cnnmoney1.png" alt="" />
</a></td>
<td><a href="http://www.bizjournals.com/sanfrancisco/print-edition/2013/08/09/rebooting-real-estate.html?page=all" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/business_times1.png" alt="" />
</a></td>
<td><a href="http://www.inman.com/2013/11/13/realtyshares-real-estate-crowdfunder-launches-first-equity-deal/" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/inman1.png" alt="" />
</a></td>
<td><a href="http://www.investorsbeat.com/all-in-one-investing-made-easy-with-realtyshares/" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/investorsbeat1.png" alt="" />
</a></td>
</tr>
</tbody>
</table>
My CSS:
IMG.homepghovr
{
opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}
IMG.homepghovr:hover
{
opacity: 1.0;
filter: alpha(opacity=100); /* For IE8 and earlier */
}
Fiddle: http://jsfiddle.net/v2JA9/
I was also told that I shouldn't be using a table for something like this, but rather be using div's, and ul's? Is that true? If so can someone point me to the right direction to utilize those tags?
Thank you very much!
If you just need a border to the table or container and grey colored background,just add this to your css,
table{
border:1px solid #000;
background-color:#eee;
}
if you need border for each item then just use
table,tr,td{
border:1px solid #000;
background-color:#eee;
border-collapse: collapse;
}
Demo here
if you need to use divs like a table
then
use
the parent container(or div) as display:table in css
and inner divs as display:table-cell
I'll answer that by telling you to not use a table. Obsolete for this kind of stuff, really.
Change < td> to < li>, remove < tr>, < tbody>, < table>, you need just one tag around li elements: < ul>. And check this out:
http://jsfiddle.net/v2JA9/3/
li {
float: left;
list-style: none;
}
ul {
background: #ccc;
border: 2px solid black;
padding: 0;
}
ul:after {
clear: both;
content: "";
display: block;
}
Basically, let's float (google: "floats css") them. ul:after being there as clearfix (google that as well), so it's as big as floating elements inside of it.
http://jsfiddle.net/v2JA9/6/
li {
display: inline-block;
list-style: none;
}
ul {
background: #ccc;
border: 2px solid black;
padding: 0;
}
Make li inline instead, so many of them don't mind standing in one line. Here: "display: inline-block", "inline" will work as well, but is less flexible. On the flipside, older browsers (IE...) can have some problems with inline-block. Up to you.
EDIT:
Someone mentioned it, let's work with it. Making ul behave like a table, with css.
http://jsfiddle.net/v2JA9/7/
Basically: "display: table;" on < ul> (container) + "display: table-cell;" on < li> (actual list elements, err, table cells...).
Solving your question (by keeping the tables) is super basic: JSFiddle
table, tr, td {
border: 1px solid black;
background-color: #e6e6e6;
border-collapse: collapse;
}
Using DIVs is definetely the best approach for building your site in a way that will allow you to leverage current and future web technologies: JSFiddle
I used display: inline-block;, but you could accomplish similar layout with display: block; and float: left;
div {
display: inline-block;
border: 1px solid black;
background-color: #e6e6e6;
}
Hope this helps get you started.
Yes, this can be done with list items as well - this is preferable because you have more options
<ul>
<li>
<a href="http://online.wsj.com/news/articles/SB10001424052702304626804579361520890893170" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/wsj1.png" alt="" />
</a>
</li>
<li>
<a href="http://www.forbes.com/sites/rodebrahimi/2013/12/12/how-crowdfunding-will-impact-real-estate-investing-an-interview-with-realtyshares/" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/forbes1-1.png" alt="" />
</a>
</li>
<li>
<a href="http://money.cnn.com/news/newsfeeds/gigaom/articles/2014_02_04_finally_you_can_do_something_useful_with_bitcoin_invest_in_real_estate.html" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/cnnmoney1.png" alt="" />
</a>
</li>
<li>
<a href="http://www.bizjournals.com/sanfrancisco/print-edition/2013/08/09/rebooting-real-estate.html?page=all" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/business_times1.png" alt="" />
</a>
</li>
<li>
<a href="http://www.inman.com/2013/11/13/realtyshares-real-estate-crowdfunder-launches-first-equity-deal/" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/inman1.png" alt="" />
</a>
</li>
<li>
<a href="http://www.investorsbeat.com/all-in-one-investing-made-easy-with-realtyshares/" target="_blank">
<img class="homepghovr" src="https://www.realtyshares.com/Media/Default/Content%20Images/AsSeenOn/investorsbeat1.png" alt="" />
</a>
</li>
The CSS for the list could look like this
IMG.homepghovr
{
opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}
IMG.homepghovr:hover
{
opacity: 1.0;
filter: alpha(opacity=100); /* For IE8 and earlier */
}
li{
list-style:none;
float:left;
border: 1px dashed black;
background-color: lightgrey;
}
The CSS for ur Table would look like this:
table{
border: 1px dashed black;
background-color: lightgrey;
}
You can use this code for better output
table{
border: 1px solid gray;
border-spacing: 0;
border-collapse: collapse;
}
table td{
border-left: 1px solid gray
}
table td:first-child{
border: none;
}
Check this Demo
For a border, add this:
<table border="1">
...
</table>
A ul is an unordered list. See an example here.
A div "divides" a webpage into a section. See here.
EDIT
Based on what it looks like you're trying to do, I wouldn't recommend a ul because then you'd get bullet points next to each icon.

align an image with CSS

I have following HTML output which i can not change. These are just two links, one of them is text link, while other is the image.
The problem is that the image is appearing bit higher position than the text. I am trying to align the text in the middle of the image but not getting any success.
I have tried setting the padding-top, margin-top and vertical-align to the image, but none of them seem to work. I'll appriciate any help.
HTML:
<p>
<a href="#" class="link">
<img width="14" height="14" src="http://i50.tinypic.com/f08ehe.jpg">
</a>
my title
</p>
CSS:
.link img{
margin-top: 5px;
}
JSFiddle:
http://jsfiddle.net/e3vnQ/
Try using display: inline-block and vertical-align: middle: http://jsfiddle.net/e3vnQ/7/
add align="top"
<p>
<a href="#" class="link">
<img width="14" height="14" src="http://i50.tinypic.com/f08ehe.jpg" align="top">
</a>
my title
</p>
CSS:
.link img{
margin-top: 5px;
}
you can write the css like this :-
when anchor tag will come in p tag will stay vertical-align:middle; through mentioned below css
p{
font-size: 12px;
border: 1px solid red;
}
p a {
display:inline-block;
vertical-align:middle;
}
.link img{
margin-top: 5px;
}
or see the demo :- http://jsfiddle.net/e3vnQ/13/

Suggestion for gallery thumbnail on click?

I'm trying to build an image gallery with thumbnails and a display for a larger image. At present, its working when the the mouse hovers over the thumbnail which displays the larger image. However I wish to replace the hover feature with an on click so that the larger image does not disappear when the mouse leaves the thumbnail. From a bit of research I'm lead to believe that this can not be done with css as with the hover feature and that I would need to include some script. As I'm new to web development after this I'm a bit lost and would appreciate some help. Below is the html code for the gallery container and the corresponding css code......where do I start from here?
Thanks
A
html code
<div class="gallerycontainer">
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/101.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/101.jpg" width="405px" height="585px"/></span></a>
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/102.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/102.jpg" width="405px" height="585px"/></span></a>
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/103.jpg" width="56px" height="80px" border="0" /><span><img src="images/gallery/1one/103.jpg" width="405px" height="585px"/></span></a>
<a class="thumbnail" href="#thumb"><img src="images/gallery/1one/104.jpg" width="56px" height="80px"border="0" /><span><img src="images/gallery/1one/104.jpg" width="405px" height="585px"/></span></a>
<br />
</div>
css code
.gallerycontainer{
position: absolute;
/*Add a height attribute and set to largest image's height to prevent overlaying*/
}
.thumbnail img{
border: 1px solid white;
margin: 0 5px 5px 0;
}
.thumbnail:hover{
background-color: transparent;
}
.thumbnail:hover img{
border: 1px solid grey;
}
.thumbnail span{ /*CSS for enlarged image*/
position: absolute;
background-color: #000000;
padding: 5px;
left: -1000px;
border: none;
visibility: hidden;
color: black;
text-decoration: none;
}
.thumbnail span img{ /*CSS for enlarged image*/
border-width: 0;
padding: 2px;
}
.thumbnail:hover span{ /*CSS for enlarged image*/
visibility: visible;
top: 0;
left: 300px; /*position where enlarged image should offset horizontally */
z-index: 50;
}
Heres a simple start with jquery.
http://jsfiddle.net/8GKXM/
$('.thumbnail').each(function(){
$(this).click(function() {
$('.thumbnail span').hide();
$(this).find('span').show('slow');
});
});
This is what the jquery says basically:
On every individual .thumbnail click:
hide .thumbnail span ( as in every span it finds )
then
find clicked .thumbnail's span and show that
I would probably move the bigger images into their own container though...
You can use jQuery along with blockUI plugin:
<div class="gallerycontainer">
<a class="thumbnail" href="#thumb" class="imgthumb"><img src="images/gallery
/1one/101.jpg" width="56px" height="80px" border="0" /></a>
<a class="thumbnail" href="#thumb" class="imgthumb"><img src="images/gallery
/1one/102.jpg" width="56px" height="80px" border="0" /></a>
</div>
And then you can use the window onload event to attach the onclick event to fire the large image with blockUI:
$(function(){
$(".imgthumb").onclick(function() {
$.blockUI({
message: "<div><img src=" + $(this + " > img").attr("src") + " width='405' height='585' /></div>";
css: { border: '1px solid grey'}
});
});
});