Search code examples
htmlcsswidthfixed

div background with fixed width


I'm looking for a way to give a div a background with a fixed width. In particular I want the div to have a 5 pixel one-colored background (no percentages, no gradient) and the rest of the div being transparent. In this case I don't want to use a border!


Solution

  • enter link description hereYou can use a pseudo-element and then style that. Make it 5px wide and 100% height of the div to make sure it covers the whole lot.

    See this fiddle.

    .bg {
        height: 100px;
    }
    
    .bg:after {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        width: 5px;
        background-color: blue;
    }