Set paragraph as wide as possible

Asked

Viewed 34 times

-1

I’m trying to perfectly fit a paragraph p in a list item li to make a header with options menu (same as the site python.org/downloads, that I am recreating to practice), being the text of each of these options centered vertically and horizontally.

The problem is that when I define width: 100% for the paragraph, it simply ignores this instruction and gets the shortest possible width, i.e., the width of the word. By defining width: 198px, which is the size of li in my viewport, it works absolutely perfect. It even regulates its own size by decreasing the width of the browser. Only I want to tailor my page to larger resolutions, so this is not an option. Follow my snippet in HTML:

<div id = interface>
    <header id = header_superior>
        <nav id = nav_superior>
            <ul>
                <li id = hs_python><p>Python</p></li>
                <li id = hs_psf><p>PSF</p></li>
                <li id = hs_docs><p>Docs</p></li>
                <li id = hs_pypi><p>PyPI</p></li>
                <li id = hs_jobs><p>Jobs</p></li>
                <li id = hs_community><p>Community</p></li>
            </ul>
        </nav>
    </header>
</div>

And my excerpt in CSS (the rest I did not put to not be too extensive, but I believe that is right here the problem):

#header_superior ul {
    list-style: none;
    width: 100%;
    height: 100%;
    margin: 0 auto;
    padding: 0;
    font-size: 0;
}

#header_superior li {
    display: inline-block;
    color: #999;
    width: 16.4%;
    height: 47px;
    border-left: 1px solid #273643;
    border-right: 1px solid #1f3b47;
    font-size: 12pt;
}

#header_superior p {
    width: 198px;
    height: 47px;
    display: table-cell;
    vertical-align: middle;
    text-align: center;
    margin: 0 auto;
}
  • 1

    Taking a look at this example for a while: https://jsfiddle.net/yLhjok05/ can help you with something. In Inspector some properties are in :Hover, :active or others. Click with the button.

1 answer

2


tip 1: open the html inspector on the site you are copying to access the css settings

#header_superior ul {
    list-style: none;
    width: 100%;
    height: 100%;
    margin: 0 auto;
    padding: 0;
    font-size: 0;
}

#header_superior li {
    display: inline-block;
    color: #999;
    width: 16%;
    height: 47px;
    border-left: 1px solid #273643;
    border-right: 1px solid #1f3b47;
    font-size: 12pt;
}
#header_superior li:hover{
    color: #000;
}

#header_superior p {
    width: 100%;
    height: 47px;
    line-height: 47px;
    text-align: center;
    margin: 0 auto;
}
<div id = interface>
    <header id = header_superior>
        <nav id = nav_superior>
            <ul>
                <li id = hs_python><p>Python</p></li>
                <li id = hs_psf><p>PSF</p></li>
                <li id = hs_docs><p>Docs</p></li>
                <li id = hs_pypi><p>PyPI</p></li>
                <li id = hs_jobs><p>Jobs</p></li>
                <li id = hs_community><p>Community</p></li>
            </ul>
        </nav>
    </header>
</div>

  • Thank you very much! It worked, I don’t know why it was going wrong before, but it worked out your solution. About the inspector, I think only appear some of the properties of the objects, I found almost nothing there.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.