Anchor image issue in css - html

I have tried lot but did not find any solution so that that can be helpful for me. I have a menu which look like as below. The Menu has multiple menu item and each item is an anchor that consists of image, text and arrow.
Problem:
Image height will fit according to anchor height and every element
of anchor must be middle.
Arrow would be down or right, every arrow will fit to right.
HTML CODE:
<a href="javascript:void(0);" class="" data-toggle="dropdown">
<span>
<img src="http://www.wpclipart.com/toys/blocks/abc_blocks.png" alt="" />ADMIN
<i class="fa fa-caret-down"></i>
</span>
</a>
CSS CODE:
a {
text-decoration: none;
width: 300px;
border: 1px solid red;
}
img {
width: 1.5em;//do not fix.
}
a:hover {
text-decoration: none;
}
plunker

Here is the working solution:
<a href="javascript:void(0);" class="" data-toggle="dropdown">
<img src="http://www.wpclipart.com/toys/blocks/abc_blocks.png" alt="" /> ADMIN
<div>
<i class="fa fa-caret-down"></i>
</div>
</a>
And the CSS:
a {
text-decoration: none;
width: 300px;
border: 1px solid red;
display:inline-block;
line-height: 1.5em;
}
a div{
display:inline-block;
float:right;
}
img {
height: 1em;
vertical-align:middle;
}
The trick here is to use the line-height on anchor tag along with vertical-align:middle on the img.
Note that you cannot use // for commenting in CSS. Only /*... */ is supported.
Here is the demo.

Related

mouse over css sprite

I have an anchor like this:
<a href="#">
<i class="ico01"></i>
<span>Text</span>
</a>
ico01 applies an image with CSS sprite. I would like to change the background color of the anchor content (span + i) on mouse over, however it just applies to the text (span). Is there any trick that I`m missing?
Here`s a JS Fiddle. I need the background not only in the span, but also wrapping the image:
https://jsfiddle.net/0esbmusq/1/
Thanks in advance
a {
display:block;
}
a:hover {
background-color:black;
}
Try this:
a{
display:block;
}
.ico01 {
background: url('https://download.seaicons.com/icons/marcus-roberto/google-play/512/Google-Chrome-icon.png') no-repeat -10px -24px;
width: 492px;
height: 488px;
display:block;
}
a{
display:block;
}
a:hover {
background-color:red;
}
<a href="#">
<span>Google</span>
<i class="ico01"></i>
</a>
You mean?
a:hover span{background-color:black};
<a href="#">
<i class="ico01"></i>
<span>Text</span>
</a>
You need to use display:block for link.

Extra padding is added in mozilla for content

Below is my code:
#sam_ul li {
height: 41px;
border-bottom: 1pt solid #DEDEDE;
background-color: #F8F8F8;
}
#sam_ul li {
list-style-type: none;
}
#u_l_add:before {
content: '\0FBF';
}
<ul id="sam_ul" style="margin:0px;">
<li>
<a href="#">
<span id="u_l_add" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Add</div>
</a>
</li>
<li>
<a href="#">
<span id="u_l_sear" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Search Artifact</div>
</a>
</li>
</ul>
The content pseudo element is displayed differently in both IE and mozilla. By different I mean in IE it is displaying correctly while in mozilla it is adding some extra padding and displaying the content.
check the difference between the first li element and the second li element.
Can anyone help me with this?
Add padding:0 to unordered list
#sam_ul{
padding:0
}
#sam_ul li {
height: 41px;
border-bottom: 1pt solid #DEDEDE;
background-color: #F8F8F8;
list-style-type: none;
}
#u_l_add:before {
content: '\0FBF'; }
#u_l_sear:before {
content: '\0FBF'; }
<body>
<ul id="sam_ul" style="margin:0px;">
<li>
<a href="#">
<span id="u_l_add" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Add</div>
</a>
</li>
<li>
<a href="#">
<span id="u_l_sear" style="font-size:36px;line-height:20px;"></span>
<div style="width:130px;position:relative;top:-20px;left:40px;">Search Artifact</div>
</a>
</li>
</ul>
</body>
Try to normalize everything. HTML and body has default margin and padding for every browser that could ruin your design. Almost all block elements has that.
Try:
html,body{
margin: 0;
padding:0;
}
Or download and add normalize.css

Image in link is moving the link location

I'm making a basic navigation bar that consists of inline links all containing text and some also containing images. When an image is within the link, it moves the link element background (it does not move the link text apparently). The background moves more if the image is set to a larger size. I want all the elements to be exactly lined up.
Here is an image of the problem
Here is the relevant HTML:
<!--navigation bar-->
<div id="nav">
<a class="navLinks" href="">Resume</a>
<a class="navLinks" href="mylinkedinprofileURL">
<img class="logo" id="logo_linkedin" src="images/logoLinkedin.png">LinkedIn</a>
<a class="navLinks" href="wordpress">
<img class="logo" id="logo_wordpress" src="images/logoWordpress.png">WordPress</a>
<a class="navLinks" href="travels">Travels</a>
</div>
And here is the relevant CSS:
#nav {
position: relative;
top: 10px;
text-align: center;
}
.navLinks {
border-radius: 3px;
text-decoration: none;
color:white;
text-align: center;
width:110px;
height:20px;
padding:15px;
background-color: #353841;
display:inline-block;
}
.logo {
height:20px;
position:relative;
right:10px;
}
I'm very new to web development, so if there is a much better or more elegant way to be doing this, please let me know!
Add vertical-align:top to the tabs.
.navLinks {
vertical-align:top;
}
See DEMO here.

CSS/HTML: a tag with a span inside, span margin creating white space on hover underline

I have a link with a span inside, I want to place a margin on the span so it is distanced from the link title, however, when I use the :hover for underline, a white space is created where there is no underline. I want the underline to be the full width of the link element. How do I do this? Thank you.
http://jsfiddle.net/EY387/
HTML
<div>
<a href="#" class="link-1">
<span class="span-1">1</span>
Hello
</a>
</div
CSS
.link-1 {
font-size: 16px;
text-decoration: none;
}
.link-1:hover {
text-decoration: underline;
}
.span-1 {
font-size: 12px;
margin-right: 5px;
}
Though it may not be exactly what you're looking for, why not try a border?
HTML
<div>
<a href="#" class="link-1">
<span class="span-1">1</span>
Hello
</a>
</div>
CSS
.link-1 {
font-size: 16px;
text-decoration: none;
}
.link-1:hover {
border-bottom:1px solid #000;
}
.span-1 {
font-size: 12px;
margin-right: 5px;
}
Demo
As #DavidThomas explained, if having a border move elements underneath is a problem, the use of a box-shadow could be easily swapped for the border-bottom.
Illustrated here
Remove margin to span. margin space not taking underline on hover.
For space use . As in this following markup:
<div>
<a href="#" class="link-1">
<span class="span-1">1 </span>
Hello
</a>
</div>
Css:
.link-1 {
font-size: 16px;
text-decoration: none;
}
.link-1:hover {
text-decoration: underline;
}
.span-1 {
font-size: 12px;
}
DEMO

html image moves when zoomed in

I have a nav bar with a few images as the navigation buttons and when I zoom to 110% on chrome (only) the right image falls out of the nav bar. It is for a school project.
Here is the HTML for the nav bar as well as the CSS.
CSS
nav {
width: 960px;
height: 54px;
background-color: #191a19;
margin: auto;
}
.menu_button {
border: 2px solid #19242e;
}
.menu_button:hover {
background-color:#000;
opacity:0.5;
}
html
jsfiddle
<style>
nav {
width: 960px;
height: 54px;
background-color: #191a19;
margin: auto;
overflow:hidden;
}
.menu_button {
border: 2px solid #19242e;
}
.menu_button:hover {
background-color:#000;
opacity:0.5;
}
nav a{
display:block
width:233;
float:left;
height:50;
}
nav img{
width:233;
height:50;
}
</style>
<nav>
<a href="index.html">
<img class="menu_button" src="images/home_button.jpg" alt="home button">
</a>
<a href="overview.html">
<img class="menu_button" src="images/overview_button.jpg" alt="overview button">
</a>
<a href="tools.html">
<img class="menu_button" src="images/tools_button.jpg" alt="tools button">
</a>
<a href="tutorials.html">
<img class="menu_button" src="images/tutorials_button.jpg" alt="tutorials button">
</a>
</nav>
try this one dude, please vote for my answer so that i can help you again in the future. thanks
You should change either the width of your nav css element to a higher number (965px) or lower your .menu_button class' border to 1px;
Hope it helps.