CSS fixed width in a span

cannot set width of span
span width percentage
html span
inline width css
css width
how to give width and height to span
does span have width
span max-width

Within an unordered list:

<li><span></span> The lazy dog.</li>
<li><span>AND</span> The lazy cat.</li>
<li><span>OR</span> The active goldfish.</li>

Adding a class or style attribute is permitted but padding the text and adding or changing tags is not allowed.

The page is rendering with Courier New.

Goal is to have text after span lined up.

    The lazy dog.
AND The lazy cat.
OR  The active goldfish.

Justification of the "OR" is unimportant.

The lazy animal text may be wrapped in an additional element but I'll have to double check.

ul {
  list-style-type: none;
  padding-left: 0px;

ul li span {
  float: left;
  width: 40px;
  <li><span></span> The lazy dog.</li>
  <li><span>AND</span> The lazy cat.</li>
  <li><span>OR</span> The active goldfish.</li>

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� In an ideal world you’d achieve this simply using the following css <style type="text/css"> span { display: inline-block; width: 50px; } </style> This works on all browsers apart from FF2 and below. Firefox 2 and lower don’t support this value. You can use -moz-inline-box, but be aware that it’s not the same as

In an ideal world you'd achieve this simply using the following css

<style type="text/css">

span {
  display: inline-block;
  width: 50px;


This works on all browsers apart from FF2 and below.

Firefox 2 and lower don't support this value. You can use -moz-inline-box, but be aware that it's not the same as inline-block, and it may not work as you expect in some situations.

Quote taken from quirksmode

span Set Fixed Width, The <span>tag is described in more detail below. Original code: <style type="text/ css"> .sc { width: 300px; list-style: none� The <span> element is an inline element, so you can not assign a fixed width to the element as long as it remains an inline element. You have to set the <span> element to display:block, so that it becomes a block element and only then, it is sensitive to width specifications.

Unfortunately inline elements (or elements having display:inline) ignore the width property. You should use floating divs instead:

<style type="text/css">
div.f1 { float: left; width: 20px; }
div.f2 { float: left; }
div.f3 { clear: both; }

<div class="f1"></div><div class="f2">The Lazy dog</div><div class="f3"></div>
<div class="f1">AND</div><div class="f2">The Lazy cat</div><div class="f3"></div>
<div class="f1">OR</div><div class="f2">The active goldfish</div><div class="f3"></div>

Now I see you need to use spans and lists, so we need to rewrite this a little bit:

<style type="text/css">
        span.f1 { display: block; float: left; clear: left; width: 60px; }
    li { list-style-type: none; }

<li><span class="f1">&nbsp;</span>The lazy dog.</li>
<li><span class="f1">AND</span> The lazy cat.</li>
<li><span class="f1">OR</span> The active goldfish.</li>

Making A Span With Fixed Width, html. css (original- incorrect). <span class="fixed-time-column-width"> <span ng- bind="message.startTime"></span> </span> <span><img� Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

The <span> tag will need to be set to display:block as it is an inline element and will ignore width.


<style type="text/css"> span { width: 50px; display: block; } </style>

and then:

<li><span>AND</span>something else</li>

height and width not work with span tag | Community Central, There is a problem with HTML and CSS designing. When i use <span> tag, height and width are not working but the block looks great. so bad that i can't resize it. i want the block look Oh ok. i just fixed it. thank you very much for your help. CSS fixed width in a span ; CSS fixed width in a span. 0 votes . 1 view. asked Sep 2, 2019 in Web Technology by Tech4ever (22.4k points) Within an unordered list:

<style type="text/css">

span {
  width: 50px;


You can do this method for assigning width for inline elements

CSS min-width property, Set the minimum width of a <span> element to 500 pixels: span.ex1 { If the content is larger than the minimum width, the min-width property has no effect. By defining the the full span as display:inline-block you might have a hard time displaying images. Therefore I prefer to define a span like so: span { display:block; width:150px; word-wrap:break-word; } p span, a span, h1 span, h2 span, h3 span, h4 span, h5 span { display:inline-block; } img{ display:block; }

Div and span, practical differences, Div. The <div> tag is a block-level element, so a rectangular object which can not be broken over several lines. It has the attributes margin, padding, width, height. Step 2) Add CSS: To create a full-width button, add a width of 100% and make it into a block element:

Set width of <span> programmatically - ionic-v3, Fixed values of the width of <span> I can set e.g. with <span style="display: inline -block; width: 150px;"> I want to set the width inst… position: fixed; An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element. A fixed element does not leave a gap in the page where it would normally have been located.

Why i cant use span in the place if div???, span is an inline tag A block element defaults to being the width of its container . It can have its width set using CSS, but either way it is a fixed� We could use the width of the browser window in our CSS math. The amount we want to “pull” to the left and right is half the width of the browser window plus half the width of the parent. (Assuming the parent is centered.) So, so our parent is 500px wide:

  • <span> is an inline element by default - and floating it won't give it a width.
  • The float property generates a "block box" which does have a width.
  • Should it be diplay: inline-block; width: 32px; will do in most modern browsers.
  • @Randy Marsh - no, the width property only has an effect because the float property changes the element to a block display, as Stephen Caldwell describes above.
  • @PauloBueno can you change diplay to read display, BTW, it works for me. thanks
  • @NicholasPickering .. how about wkhtmltopdf?
  • Hm, not sure. It's just a minor setback. Ended up having to use tables to get the desired effect.
  • Well, I can recommend wkhtmltopdf if you ever need something that is CSS3 compliant.
  • Meanwhile, 10 years later, this is definitely the way to go.
  • That's a great solution. Floating divs mimic the intended behavior of spans as they line up horizontally. It's important to remember the clear:both line break. It's a great way to avoid tables in this context.
  • I don't understand, button is inline or inline-block element, why "width" will apply to it? Button seems like a inline element right? Is there any doc showing the default "display" properties of all html element?
  • No, I don't think this works. "something" goes to the next line. And there is a missing "<"
  • As I said, it does NOT work! Check jsfiddle.net/m156a0qp out. Also, it is never good to meddle with the CSS of all span elements!