CSS fixed width in a span
ul { list-style-type: none; padding-left: 0px;}
ul li span { float: left; width: 40px;}
<ul> <li><span></span> The lazy dog.</li> <li><span>AND</span> The lazy cat.</li> <li><span>OR</span> The active goldfish.</li></ul>
How to set fixed width for span
Set the display property of the spans to inline-block like:
.container span { display: inline-block;}
<div class="container"> <div class="row"><span style="width:60px;background-color: red;">prefix1</span><span>prpr</span> </div> <div class="row"><span style="width:60px;background-color: red;">pre2</span><span>prpr</span> </div></div>
Fixed width of span?
Add display: inline-block
to span to solve it:
span {
display: inline-block;
}
Fiddle:
#mybox { width: 400px;}
.myli { background-color: yellow !important;}
.mytext { width: 250px;}span { display: inline-block;}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/><div id="mybox">
<ol><li class="myli list-group-item clear-fix"><span class="mytext">Some text</span><span class="pull-right"><button>Button</button></span></li><li class="myli list-group-item clear-fix"><span class="mytext">Some text</span><span class="pull-right"><button>Button</button></span></li><li class="myli list-group-item clear-fix"><span class="mytext">Some very long text which interferes with the button on the following row oiwiowh wdoihsoih osdih ohsdih soidhoishisdhoidh soidh odih</span><span class="pull-right"><button>Button</button></span></li><li class="myli list-group-item clear-fix"><span class="mytext">Some text</span><span class="pull-right"><button>Button</button></span></li></ol>
</div>
Span tag text with fixed width
According to your question, I have inferred that, you want to make the span tag wide around 4 characters. Well, CSS does provide the solution for this problem.
You can use the ch
unit to set the 4 character width.
<span>9</span>
Style:
span {
display: inline-block;
width: 4ch;
word-break: break-word;
}
In CSS 1ch is equivalent to the width of "0" of the currently used font, in this case the span tag will have width of around four 0s. You also need word-break: break-word
property, suppose if you have "99999" (five 9's without any space),if you did not include it, the 5th character will span beside the 4th character instead of the new line, causing the overflow of the characters in the span tag.
Also, if you want to enable it for the span tag make sure you are including the display: inline-block
or display: block
style for the span.
Does height and width not apply to span?
Span is an inline element. It has no width or height.
You could turn it into a block-level element, then it will accept your dimension directives.
span.product__specfield_8_arrow
{
display: inline-block; /* or block */
}
fixing span width
<span>
s are inline elements, like <a>
and <img>
, therefore they cannot accept rules like width:, height: and others.
To allow the <span>
to accept these rules, add display: block;
to the Span's CSS.
This will allow it to accept the width rule and fill up your TD.
That or just change your <span>
to a <div>
.
If that doesn't work, post your code and we'll take a closer look :)
Span fix width in div
I don't know if i got it right but what i understand is that there should at least be an underlined block even if it contains no text. What you need to do is making div
out of span
because you can't apply a width to span tags. Then you should give the div
a height
and min-width
in css. With the min-width
you make sure that even if the div
is empty it has at least this minimum width.
Look at my fiddle here:
http://jsfiddle.net/e8t64vtk/2/
CSS : span in left with fixed width, span in right with fixed width, the center table fills up rest of the space
You can use float
, also using span
as a container is not a good idea. Instead use div
. Also put your table
inside a div
:
.container { overflow: hidden;}.left { float: left; width: 100px; background: yellow;}.right { float: right; width: 100px; background: yellow;}.main { background: orange; margin: 0 100px;}
<div class="container"> <div class="left">Left</div> <div class="right">Right</div> <div class="main"> Hello World </div></div>
Related Topics
Overflow:Hidden Dots At the End
Imitating a Blink Tag With Css3 Animations
Use Font Awesome Icon in Placeholder
Using "Margin: 0 Auto;" in Internet Explorer 8
How to Get Folder Directory from HTML Input Type "File" or Any Other Way
Angular 5 Formgroup Reset Doesn't Reset Validators
Why Would a Developer Place a Forward Slash At the Start of Each Relative Path
Displaying Unicode Symbols in Html
Youtube Autoplay Not Working on Mobile Devices With Embedded Html5 Player
Html: How to Have a Form Tag in Each Table Row in a Xhtml Valid Way
How Make Background Image on Newsletter in Outlook
Javaserver Faces 2.2 and Html5 Support, Why Is Xhtml Still Being Used
Hide Textfield Blinking Cursor
How to Use Tel: With * (Star, Asterisk) or # (Hash, Pound) on Ios
What Characters Can Be Used For Up/Down Triangle (Arrow Without Stem) For Display in Html
What Is "X-Content-Type-Options=Nosniff"