How to make span width to be maximum using CSS?

Tags: html,css

Problem :

Consider the following example: (live demo)




p {
    background-color: #aaa;
span {
    background-color: #777;

How could I make <span>'s width to be all the available space?

Note: <strong> and <span> should be on the same line.

Solution :

If you want the items on the same line with the full width taken up you could do this.

p {
    background-color: #aaa;

strong {
    float: left;    

span {
    display: block;
    background-color: #777;
    margin-left: 40px;

But a better alternative would be to get the background-color run from the parent element.

    CSS Howto..

    How to prevent outside CSS from overriding web component styles

    How to override a css !important property using jQuery with transitions

    How to create the timetabling with div properly?

    How to vertically center text span in fixed position div?

    how to position div with css and force text to wrap around

    How to center in
    without text-align?

    CSS: How do I 'raise' the last photo in this page?

    How to customize Twitter Bootstrap from Illustrator design

    How do I (by default) style different types of labels differently?

    How to make all the content placed in the center of div?

    How to find the relevant stylesheet for a specific CSS code [closed]

    How to set 0% css of keyframes as current css value for the element?

    How to create a standing up 3D text effect with Css3 transforms

    How to get just the responsive grid from Bootstrap 3?

    How to display child elements of
  • at 100% height?
  • Selecting the first-child with a given class, how? [duplicate]

    How to add css class by default for all the images

    How to get a small div bar to slide down a menu on mouseover

    How to use add/subtract in css propert?

    how to use {{$variable}} in css , Laravel 5.1 [closed]

    How can I be sure that a website is responsive by only looking the code?

    How to apply CSS to Selected One in Meteor?

    How to put text over img on hover - width and height are variable

    How to make rounded border in IE8 with CSS?

    CSS and JQuery: how to remove “right:0” style

    How can I add a border INSIDE this element?

    How does browser layout adjacent div to a floating div

    CSS: how to apply margin to a container with floats?

    How to achieve cellpadding with divs or likeiwse?

    CSS: How do I make text indent for a label with long text?