Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

html - How can I centre items inside a list item?

I have the following html:

<ul class="navbar-nav flex-row ml-md-auto d-none d-md-flex">
    <li *ngIf="showDeltaButton()">
        <a class="col-sm-1" pTooltip="delta geometry" tooltipPosition="bottom" (click)="showDeltaGeometry()">
            <i [style.color]="navBar.getIconStyle(showDelta)" class="fa fa-window-restore"></i>
            <span [style.color]="navBar.getIconStyle(showDelta)">Delta</span>
        </a>
    </li>

    <li>
        <a class="col-sm-1" pTooltip="model" tooltipPosition="bottom" (click)="openCameraPanel()">
            <i [style.color]="navBar.getIconStyle(showCameraPanel)" class="fa fa-camera-retro"></i>
            <span [style.color]="navBar.getIconStyle(showCameraPanel)">Camera</span>
        </a>
    </li>


    ...

    <li>
        <a class="col-sm-1" pTooltip="close" tooltipPosition="bottom" (click)="closeDialog()">
            <i class="fa fa-close"></i>
            <span>Close</span>
        </a>
    </li>
</ul>

and this is the result using bootstrap 4:

enter image description here

but I would like the layout to be like:

enter image description here

With the a, i and span elements horizontally centred inside the li.

How can I do that?

question from:https://stackoverflow.com/questions/65923324/how-can-i-centre-items-inside-a-list-item

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

FYI: I managed to answer my own question after a little digging into the bootstrap 4 documentation. It is necessary to add the class "text-center" to the i and spam elements. I am posting the solution in the hope it will help someone facing the same problem.

HTML:

<ul class="navbar-nav">
        <ul class="navbar-nav flex-row ml-md-auto d-none d-md-flex">
            <li *ngIf="showDeltaButton()">
                <a class="col-sm-1" pTooltip="delta geometry" tooltipPosition="bottom" (click)="showDeltaGeometry()">
                    <i [style.color]="navBar.getIconStyle(showDelta)" class="fa fa-window-restore text-center"></i>
                    <span [style.color]="navBar.getIconStyle(showDelta)" class="text-center">Delta</span>
                </a>
            </li>

            <li>
                <a class="col-sm-1" pTooltip="model" tooltipPosition="bottom" (click)="openCameraPanel()">
                    <i [style.color]="navBar.getIconStyle(showCameraPanel)" class="fa fa-camera-retro text-center"></i>
                    <span [style.color]="navBar.getIconStyle(showCameraPanel)" class="text-center">Camera</span>
                </a>
            </li>

            ...

            <li>
                <a class="col-sm-1" pTooltip="close" tooltipPosition="bottom" (click)="closeDialog()">
                    <i class="fa fa-close text-center"></i>
                    <span class="text-center">Close</span>
                </a>
            </li>
        </ul>
    </ul>

CSS:

li>a>i.fa {
    display: block;
}

li>a>span {
    display: block;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...