I have the following structure for html:-
<div>
<span>
<a href="wherever">Wherever</a>
</span>
</div>
If I want the span to cover the entire width of the div, how can I do that in chrome?
I tried in css using
span{
background:#FFF;
width:100%;
}
It works in firefox and ie but not in chrome.
The width property is used to fill a div remaining horizontal space using CSS. By setting the width to 100% it takes the whole width available of its parent. Example 1: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.
The <span> element shows the inline portion of a document. The <div> elements show a block-level portion of a document. A div is a block-level element and a span is an inline element. The div should be used to wrap sections of a document, while use spans to wrap small portions of text, images, etc.
The main thing to remember about a span element is that it is an inline element, which means that you will not be able to set the width or height of it as is. So to give our span element a width, we must convert it to a block, or inline-block element.
span
elements are inline. Inline elements adjust their width automatically and ignore your width:
expressions.
Make it block-level:
span {
display: block;
}
But then it's basically just a <div>
.
There are two ways to resolve your issue.
As span tags adjust their width according to the contents in it. So to assign width to this tag we will use float left with width.
span{
background:#FFF;
width:100%;
float: left;
}
secod way is to use display block with the code
span{
background:#FFF;
width:100%;
display: block;
}
Change span's CSS to:
span {
display: block;
}
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