How to set a:link height/width with css?
add display: block;
a-tag is an inline element so your height and width are ignored.
#header div#snav div a{
display:block;
width:150px;
height:77px;
}
Set link height to 100% of it's parent
Add:
display: block;
height: 100%;
Though I don't know if you mind the link spanning the width of the <div>
If you do just set the <a>
to display: inline-block;
jsFiddle
CSS - Why am I not able to set height and width of a href elements?
As the others have said, by default <a>
is an inline element, and inline elements can't specify a width or height. You can change it to be a block element like this:
a {
display: block;
}
Though it will then display (unsurprisingly) as a block, sitting on its own, outside the flow of the surrounding text. A better solution is to use display: inline-block
which might be a best-of-both-worlds solution depending on your situation.
See PPK's writeup about it.
The real use of this value is when you want to give an inline element a width. In some circumstances some browsers don't allow a width on a real inline element, but if you switch to display: inline-block you are allowed to set a width.
CSS: width of a link doesn't change by setting the width attribute
Then <a>
tag is an inline element. Therefore it's width is determined by the length of the text within the tag. To fix this you can add display:block;
to your .media_link
class and it will perform as expected.
How to assign height and width to anchor tag link
Add display: inline-block;
in the css.
<div class="tag">
<a href="#">Book Form</a>
</div>
in css
.tag a
{
display: inline-block;
background-color:#899898;
height:125px;
width:250px;
color:#000;
font-family:Arial;
font-size:25px;
}
Anchor (<a>
) are inline elements. (here is a complete list of elements that are inline by default). Inline elements can't have width
and height
. So if you want inline
elements to maintain it's native property, i.e. be in the normal flow of line, and still have width, height and vertical-align properties.. then inline-block
is the property you should be using.
Relevant Links
- https://developer.mozilla.org/en-US/docs/CSS/display *
Edit: added explanation
Height equal to dynamic width (CSS fluid layout)
Using jQuery you can achieve this by doing
var cw = $('.child').width();
$('.child').css({'height':cw+'px'});
Check working example at http://jsfiddle.net/n6DAu/1/
Related Topics
How Is CSS Applied by The Browser, and Are Repaints Affected by It
Get Custom Data-Attribute in Select2 with <Select>
100% Width Background Image with an 'Auto' Height
Assign Variables to Child Template in {% Include %} Tag Django
Multi-Coloured Circular Div Using Background Colours
Convert HTML Character Entity Encoding in R
With HTML5 Url Input Validation Assume Url Starts with Http://
How to Show a Image Preview in The Browser Without Uploading The Image File to The Server
Center Text Vertically Within <Div>
Styling Autocomplete Dropdowns in Browsers
Flexbox Not Working in Internet Explorer 11
How to Get a Div to Resize Its Height to Fit Container
Textarea to Fill a Parent Container Exactly, with Padding
Break Long Word in Table Cell with Percentage Widths
Svg Fill Animation for The Given Path
How to Construct a Table Header Than Spans Multiple Rows in HTML