I have created a top bar that have height: 50px
, then an anchor element inside it, the anchor element with it's padding supposed to be exact as the top bar height.
Testing the code in major browsers, Firefox has given the exact pixels height of top bar to anchor element, but in Chrome and IE, it have -1px result. Fiddle Here
HTML:
<div > <a href="">Text Here</a> </div>
CSS:
div {
width: auto;
height: 50px;
background-color: #333;
}
a {
padding: 10px;
display: inline-block;
font-size: 24px; /* Adjusting this would affect element block size */
color: white;
font-family:'Bebas Neue';
background-color: #777;
}
a:hover { background-color: green; }
How could I fill the dimensions of the <a>
anchor element up to the div's height?
Syntax: To set a div element height to 100% of the browser window, it can simply use the following property of CSS: height:100vh; Example: HTML.
For a responsive full page height, set the body element min-height to 100vh. If you set a page width, choose 100% over 100vw to avoid surprise horizontal scrollbars.
css: <style> li { width: 110px; height: 42px; background-color: black; } li a { width: 32px; height: 32px; color: white; } </style> html page: <li><a href="#">write something</a></li> you need to set anchor tag's display property as block :: 'display:block;' , then only it will accept values of height and width.
height: 100% gives the element 100% height of its parent container. height: auto means the element height will depend upon the height of its children.
As no one seems to have shown you the box-sizing css property: Add the following to your <a>
height:100%;
box-sizing:border-box;
EDIT:
display table-cell
on the <a>
element and display: table
on its parent.div {
width: auto;
height: 100px;
background-color: #333;
}
a {
padding: 10px;
display: table;
font-size: 24px;
color: white;
font-family: 'Bebas Neue';
background-color: #777;
height: 100%;
box-sizing: border-box;
}
a > span {
display: table-cell;
vertical-align: middle;
}
a:hover {
background-color: green;
}
<div>
<a href=""><span>Text Here</span></a>
</div>
Fiddle Here
Here is the another way :-
Fiddle :http://jsfiddle.net/nikhilvkd/4YQtA/3/
a {
height: 30px;/*changes here*/
padding:10px;
display: inline-block;
font-size: 24px;
color: white;
font-family:'Bebas Neue';
background-color: #777;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With