Replace a img using only CSS and cannot change HTML - html

I'm working on a project that has 2 different CSS, one light and one dark. And a few images are inside the <img> tag, and I need to change their colors, only using css, since I'M NOT ALLOWED TO CHANGE HTML OR JAVASCRIPT
So, I thought on using their ID to overlap them.
I actually got the image to be on the same place, however, behind the original image.
Any ideas?
The HTML
<div id="div-icones" style="width: 164px;">
<ul id="ulIcones" class="icones">
<li>
<a href="#" class="" title="Trocar para a versão simplificada" onclick="ChangeVersionHB('min');">
<img title="Trocar para a versão simplificada" id="imgChangeVersion" src="images/ico_hb_min.png" width="16" height="16">
</a>
</li>
<li>
<a href="#" class="" title="Salvar Configuração" onclick="saveCfg();">
<img title="Salvar Configuração" id="imgSave" src="images/ico_sv.png" width="16" height="16">
</a>
</li>
<li>
<a href="#" class="" title="Restaurar Configuração Padrão" onclick="resetCfgDefault();">
<img title="Restaurar Configuração Padrão" id="imgConfDefault" src="images/folder_image.png" width="16" height="16">
</a>
</li>
<li>
<a href="#" class="" title="Bloquear funções de Layout" onclick="oSTBroker.fixLayout();">
<img title="Bloquear funções de Layout" id="imgCadeado" src="images/lock_open.png" width="16" height="16">
</a>
</li>
<li>
<a href="#" class="" title="Configuração do Cliente" onclick="showCfgCli();">
<img title="Configuração do Cliente" id="imgCliCfg" src="images/ico_cg.png" width="16" height="16">
</a>
</li>
<li>
<a href="#" class="" title="Teclas de Atalho" onclick="showHotkeys();">
<img title="Teclas de Atalho" id="imgHotkeys" src="images/ico_hk.png" width="16" height="16">
</a>
</li>
<li>
<a href="#" class="" title="Manual" onclick="AbrePagina(ConfigHB.urlManual, 'WINmn', '', 'no', 'yes', '780', '560', false);">
<img title="Manual" id="imgAjuda" src="images/ico_aj.png" width="16" height="16">
</a>
</li>
<li>
<a href="#" class="" title="Seleciona CSS" onclick="AbrePagina('LstEstilos.aspx', 'LstEstilos', '', 'no', 'yes', '780', '300', false);">
<img title="Selecione o layout" id="imgSelCss" src="images/ico_ml.png" width="16" height="16">
</a>
</li>
</ul>
My CSS to change the image
#imgChangeVersion {
box-sizing: border-box;
background: url(images/ico_hb_minc.png);
background-size: 16px;
}

Since you cannot have pseudo elements with <img> tag (although it might work in some browsers, but it's certainly non-standard). So you'll have to use parent selectors if they have unique classes, ids or attributes.
In your example, all the <a> have different title values. So you can do:
a[title="Trocar para a versão simplificada"] {...}
a[title="Trocar para a versão simplificada"] img {...}
a[title="Salvar Configuração"] {...}
a[title="Salvar Configuração"] img {...}
You can hide the img by applying display:none (collapse) or visibility:hidden (keep space).
Then apply background image on each a tag, you probably also want to set it to display:block or inline-block and give it some width and height.

Try using the "content" property, like so:
#imgChangeVersion {
box-sizing: border-box;
content:url(images/image.png); /* change image here */
background-size: 16px;
}
JSFiddle

Sounds like you should use the solution that was described in some of the comments on the initial question along with css selectors like nth-of-type() or nth-child() since your <a> tags don't have classes.
img {
display: none;
}
a:nth-of-type(){
background-image: url('');
width: 16px;
height: 16px;
}
Read up on the nth-of-type selector and nth-child selector
Also consider using + selector to target <a> elements immediately within <li> elements such as:
li + a:nth-of-type(){
background-image: url('');
width: 16px;
height: 16px;
}
In both of these solutions make sure to put a number inbetween the parentheses following nth-of-type, i.e. nth-of-type(3) to target the 3rd element.

Related

Why is the border only adding around the first <li> item despite all <li> items being in the <aside> element

Here is the HTML and then the CSS. As you can see the aside is covering all the li items. The CSS is using the aside tag to add the border around all of these elements, but it is only adding a border around the first li item. I have tried adding a separate aside element around each li to overcome this but this didn't work. I have inspected using chrome dev tools and couldn't understand why this is happening.
<aside>[enter image description here][1]
<h5><strong>Related posts</strong></h5>
<ul>
<li class="related-post">
<img
src="img/mantyping.jpg"
alt="mantyping"
width="100"
height="70"
/>
<div>
<a href="Howtolearnwebdevelopment.html" class="related-link"
>How to learn web development</a
>
<p class="related-author"><strong>By Jonas Schmed</strong></p>
</li>
</div>
<li class="related-post">
<img
src="img/csspower.jpg"
alt="lightning"
width="100"
height="70"
/>
<div>
<a href="Unknownpowersofcss.html" class="related-link"
>The unknown powers of css</a
>
<p class="related-author"><strong>By Jim Dillon</strong></p>
</li>
</div>
<li class="related-post">
<img
src="img/javascriptcode.png"
alt="javascript code"
width="100"
height="70"
/>
<div>
<a href="javascriptisawesome.html" class="related-link"
>Why Javascript is awesome</a
>
<p class="related-author"><strong>By Matilda</strong></p>
</li>
</div>
</ul>
</aside>
aside {
background-color: #f7f7f7;
border-top: 5px solid #1098ad;
border-bottom: 5px solid #1098ad;
padding: 50px;
width: 500px;
}````
[1]: https://i.stack.imgur.com/1hIls.png
I am not sure if you are looking forward to adding a border to all list items or want to add a border to the entire aside. In this solution, I'm showing how you can add borders to each list of items. If you want to add a border to the entire <aside>, just replace the .related-post class with aside. Be careful about the code formatting with correct opening and closing tags, else it may break the UI.
/* aside { */
.related-post {
background-color: #f7f7f7;
border: 5px solid #1098ad;
padding: 50px;
width: 500px;
list-style-type: none; /* It removes the bullet */
}
<aside>
<h5>
<strong>Related posts</strong>
</h5>
<ul>
<li class="related-post">
<img src="https://image.shutterstock.com/image-photo/smiling-young-man-sit-table-600w-1939452445.jpg" alt="mantyping" width="100" height="70" />
<div>
How to learn web development
<p class="related-author">
<strong>By Jonas Schmed</strong>
</p>
</div>
</li>
<li class="related-post">
<img src="https://image.shutterstock.com/image-vector/vector-illustration-abstract-electric-lightning-600w-1706216764.jpg" alt="lightning" width="100" height="70" />
<div>
The unknown powers of css
<p class="related-author">
<strong>By Jim Dillon</strong>
</p>
</div>
</li>
<li class="related-post">
<img src="https://image.shutterstock.com/image-photo/digital-technology-software-development-concept-600w-2111828198.jpg" alt="javascript code" width="100" height="70" />
<div>
Why Javascript is awesome
<p class="related-author">
<strong>By Matilda</strong>
</p>
</div>
</li>
</ul>
</aside>
Hope it helps.

HTML div end tag seen too early closing error

I just started practicing HTML and some CSS,
while working on a task from the course i'm taking online I have encountered an issue with closing a div
I have created a .section3 on css
font-family: 'Handlee', cursive;
font-size: 13pt;
background-color: #fff;
padding: 15px;
margin-bottom: 10px;
border-radius: 10px;
and on the <body> i've created a span with a ul which has inside text and images along with an a href and the result looks as desired.
however, while trying to close the div I get the following error ```End tag (form) seen too early. Expected other end tag.
the code is as follows;
<div class="section2">
<h4><span>COMPLETED COURSES</span></h4>
<ul>
<li>
HTML on <strong>SoloLearn</strong> - <small>link to certificate</small>
</li>
<a href="https://www.sololearn.com/Certificate/1014-6538353/pdf/" add target="_blank">
<img src="https://www.sololearn.com/Certificate/HTML/jpg/" width="100px" height="65px" alt="">
</a>
<li>
SQL on <strong>SoloLearn and Pluralsight</strong> - <a href="https://www.sololearn.com/Certificate/1014-6538353/pdf/">
<small>link to certificate</small></a>
</li>
<a href="https://www.sololearn.com/Certificate/1014-6538353/pdf/" add target="_blank">
<img src="https://www.sololearn.com/Certificate/HTML/jpg/" width="100px" height="65px" alt=""></a>
<!--error line--> </div>
I tried everything I could, please advice.
Thank you.
You did not close your <ul> tag. You should insert </ul> tag just before your </div>.
<div class="section2">
<h4><span>COMPLETED COURSES</span></h4>
<ul>
<li>
HTML on <strong>SoloLearn</strong> -
<a href="https://www.sololearn.com/Certificate/1014-6538353/pdf/">
<small>link to certificate</small></a
>
</li>
<a
href="https://www.sololearn.com/Certificate/1014-6538353/pdf/"
add
target="_blank"
>
<img
src="https://www.sololearn.com/Certificate/HTML/jpg/"
width="100px"
height="65px"
alt=""
/>
</a>
<li>
SQL on <strong>SoloLearn and Pluralsight</strong> -
<a href="https://www.sololearn.com/Certificate/1014-6538353/pdf/">
<small>link to certificate</small></a
>
</li>
<a
href="https://www.sololearn.com/Certificate/1014-6538353/pdf/"
add
target="_blank"
>
<img
src="https://www.sololearn.com/Certificate/HTML/jpg/"
width="100px"
height="65px"
alt=""
/></a>
</ul>
<!--error line-->
</div>
First of all, inside a <ul> there can only be multiple <li> elements.
In your code your <a> elements are siblings to your <li>, try putting them inside.
Then you forgot to close your <ul> tag !
My advice for you is to keep your code indented, noticing missing tags will become easier.

Can anyone tell me how to make my these images have a hover?

I am building a site in HTML & CSS and I have a section where I would like to have my images change when hovered over. My problem is I can get the first one to do what I want, but when I try the same method on the images that are side by side, everything gets moved or it just doesn't work. You can see the example of the first hexagon that changes in the "Core Values" section of the site. You can either pull my Githib repo here or I have also added a fiddle . Thank you!
.hex-image {
padding-top: 70px;
}
.hexy-hex {
position: relative;
margin-top: 60px;
height: 900px;
}
.hexy-hex-2 {
position: relative;
top: -45px;
}
.hexy-hex-3 {
position: relative;
top: -45px;
}
.hexy-hex-4 {
position: relative;
top: -45px;
}
.hexy-hex-5 {
position: relative;
top: -45px;
}
.lt-blue-hex {
margin: 0px;
}
.drk-grey-hex {
margin: 0px;
}
.lt-grey-hex {
margin: 0px;
}
#Spirituality {
background-image: url('http://i.imgur.com/DPTzosk.png');
height: 200px;
width: 175px;
}
#Spirituality:hover {
background-image: url('http://i.imgur.com/Ha9YgEG.png');
}
<section class="hex-image">
<h1 style="color: #686868" align="center">Core Values</h1>
<div class="hexy-hex" align="center">
<div id="Spirituality"></div>
<!-- <a class="lt-blue-hex cv" href="http://"><img src="images/blue-hex-up-sm.png" title="JDI" /></a> -->
<div class="hexy-hex-2" align="center">
<div id="Honesty"></div>
<div id="Innovation"></div>
<a class="drk-grey-hex" href="http://"><img src="http://i.imgur.com/n87uvmk.png" title="JDI" /></a>
<a class="lt-grey-hex" href="http://"><img src="http://i.imgur.com/vCNrceH.png" title="JDI" /></a>
<div class="hexy-hex-3" align="center">
<a class="lt-grey-hex" href="http://"><img src="http://i.imgur.com/vCNrceH.png" title="JDI" /></a>
<a class="lt-blue-hex" href="http://"><img src="http://i.imgur.com/DPTzosk.png" title="JDI" /></a>
<a class="drk-grey-hex" href="http://"><img src="http://i.imgur.com/n87uvmk.png" title="JDI" /></a>
<div class="hexy-hex-4" align="center" >
<a class="lt-blue-hex-2" href="http://"><img src="http://i.imgur.com/DPTzosk.png" title="JDI" /></a>
<a class="drk-grey-hex-2" href="http://"><img src="http://i.imgur.com/n87uvmk.png" title="JDI" /></a>
<a class="lt-grey-hex-2" href="http://"><img src="http://i.imgur.com/vCNrceH.png" title="JDI" /></a>
<a class="lt-blue-hex-2" href="http://"><img src="http://i.imgur.com/DPTzosk.png" title="JDI" /></a>
<div class="hexy-hex-5" align="center" >
<a class="drk-grey-hex-2" href="http://"><img src="http://i.imgur.com/n87uvmk.png" title="JDI" /></a>
<a class="lt-grey-hex-2" href="http://"><img src="http://i.imgur.com/vCNrceH.png" title="JDI" /></a>
<a class="lt-blue-hex-2" href="http://"><img src="http://i.imgur.com/DPTzosk.png" title="JDI" /></a>
<a class="drk-grey-hex-2" href="http://"><img src="http://i.imgur.com/n87uvmk.png" title="JDI" /></a>
<a class="lt-grey-hex-2" href="http://"><img src="http://i.imgur.com/vCNrceH.png" title="JDI" /></a>
</div>
</div>
</div>
</div>
</div>
<div class="clear"></div>
</section>
So onto your problem: It seems what you try to achieve is a mouseover effect like on the first hexagon. It further seems you already tried it a failed because the hexagons (<div>s) did get displayed over each other. Instead you builded your hexagon pyramid with <a>-tags but now there is no mouseover effect because the <a>-tags have hard coded <img>s which cannot be changed with CSS.
Like in all cases you have several possibilities. One could be to change the <img>s on mouseover via JavaScript/jQuery. Another (out of even more) would be to try an approach via CSS and as you already tried that yourself (at least from the comments in your code it looks that way), lets go with that.
So your <div>s in the second row get displayed over each other because by default a <div> is a block element. If you want them to stack up just like your <a>-tags from which you built the pyramid now you need them to behave like inline elements (because thats what <a>-tags are). This can be done (for example) by adding the following CSS rule to your <div>s in question:
display: inline-block;
Now you can use them just like <a>s and so set the initial background image via CSS and change it as well via CSS and :hover selectors. I've updated your fiddle and have done that for the second line (obviously not with the images you intended but it should be understandable): https://jsfiddle.net/7k50bhva/5/
You can follow that example for the other lines.
Note that if you want to have real links I would place transparent <a>-tags within the <div>s. On those transparent (so contentless) <a>-tags you will have to specify width and height.

how can i remove this weird mark in html ?

in this piece of html,
<div>
<a href="http://www.facebook.com/" target="_blank">
<img border="0" width="26" height="25" src="facebook.gif" alt="Facebook"/>
</a>
<a href="http://twitter.com/" target="_blank">
<img border="0" width="26" height="25" src="twitter.gif" alt="Twitter"/>
</a>
</div>
when it's displayed in the browser, there's a small mark next to the first image. Why does it appear and how can i remove it?
Here's an image to show it :
Just try setting the text-decoration: none for the two links above.
The problem you are facing is that the links are underlined by default, and there might be a line-break after the image that is causing a white-space characters, and the default text-decoration: underline; is showing an underline under that white-space character.
Remove the white-space between <img ...> and </a> like this:
<div>
<a href="http://www.facebook.com/" target="_blank">
<img border="0" width="26" height="25" src="facebook.gif" alt="Facebook"/></a>
<a href="http://twitter.com/" target="_blank">
<img border="0" width="26" height="25" src="twitter.gif" alt="Twitter"/></a>
</div>
I don't know the reason as I too have been struggling with this for a long time (something to do with white-space). However, what I have found is that if you set the display to inline-block, this problem goes away.
a { display: inline-block; }
See this fiddle: http://jsfiddle.net/mznMY/
You are using an a anchor which contains underline symbol
Put text-decoration: none to your a.

Arrangement of "list items" in listview using html

This is my first "phonegap" application project, so done with the listview in html based on the requirement but listview is not properly formatted (ie one below the other), how to make the items to display one below the other. please help me.
here's my code for listview
<div>
<ul data-role="listview" data-inset="true">
<li><a href="#">
<img src="images/c3.jpeg" align="left">
<h3>CONGRATULATIONS</h3>
</a>
</li>
<li><a href="#">
<img src="images/c2.jpeg" align="left">
<h3>HOLYDAY</h3>
</a>
</li>
<li><a href="#">
<img src="images/card1.jpeg" align="left">
<h3> I'M SORRY </h3>
</a>
</li>
<li><a href="#">
<img src="images/c4.jpg" align="left">
<h3> HAPPY BIRTHDAY </h3>
</a>
</li>
<li><a href="#">
<img src="images/c5.jpg" align="left">
<h3> MISSING U</h3>
</a>
</li>
<li><a href="#">
<img src="images/images.jpg" align="left">
<h3> ENGAGEMENT</h3>
</a>
</li>
![device output][1]
First of all you cannot use <br /> as direct ul child and secondly am sure you are using float: left; for the images which are inside li tag and thus it is spoiling the layout. Inorder to fix it, use the CSS property block below
ul.class_name li {
overflow: hidden;
/* Other styles goes here */
}
Just assign a class to ul element, replace the .class_name in CSS with the class you assigned to the ul element in your HTML.
Also, you can use the below declaration to self clear the parent element like
.clear:after {
display: table;
content: "";
clear: both;
}
This will self clear the parent element just like overflow: hidden; does, but in a better way.