繁体   English   中英

水平对齐三个按钮(左,中,右)

[英]align three buttons horizontally (left, center, right)

HTML

<div class="download-buttons">
                <div class="download-button-wrapper">
                    <div id="dd" class="desktopBackground downloadFontIcons" tabindex="1">DESKTOP
                        <ul class="dropdown">
                            <li><a href="#">2560 x 1440</a></li>
                            <li><a href="#">1800 x 900</a></li>
                        </ul>
                    </div>
                </div>
                <div class="download-button-wrapper">
                    <div id="de" class="tabletBackground downloadFontIcons" tabindex="1">PHONE
                        <ul class="dropdown">
                            <li><a href="#">640 x 960</a></li>
                            <li><a href="#">1136 x 640</a></li>
                            <li><a href="#">720 x 1280</a></li>
                        </ul>
                    </div>
                </div>  
                <div class="download-button-wrapper">
                    <div id="df" class="phoneBackground downloadFontIcons" tabindex="1">TABLET
                        <ul class="dropdown">
                            <li><a href="#">2560 x 1600</a></li>
                            <li><a href="#">2048 x 1536</a></li>
                        </ul>
                    </div>
                </div>
            <div style="clear:both"></div>
        </div>

CSS

/*-----------download buttons------------------------*/
.download-button-wrapper{
    *zoom: 1;
    float: left;
    width: 180px;
    position: relative;
    border: 1px solid #eaedf1;
    color: #9ea7b3;
    background-color: #F9FAFC;
    text-align: center;
    line-height: 44px;
    font-size: .8em;
    margin: 15px 12.700534759358288770053475935829% 0 0;
}
.download-buttons div:nth-child(3){
    float: right;
    margin-right: 0;
}

/* -----------GLOBALS - Dropdowns---------------*/
.downloadFontIcons{
    cursor: pointer;
    outline: none;
}

/*----------actual dropdown list----------------*/
.downloadFontIcons .dropdown{
    /* Size & position */
    position: absolute;
    top: 110%;
    left: 0px;
    right: 0px;

    /* Hiding */
    opacity: 0;
    pointer-events: none;
}

/*-------Media Queries---------*/
    @media only screen
            and (max-width : 1000px) {
            #wallpaper-wrapper{
                margin-left: 1.0416666666666666666666666666667%;    /* 10px / 960px */
                margin-right: 1.0416666666666666666666666666667%;   /* 10px / 960px */
            }
    }
    @media only screen
            and (max-width : 820px) {
            .download-button-wrapper{
                margin: 15px 10.700534759358288770053475935829% 0 0;
            }
    }

更新小提琴

首先,抱歉代码/标记混乱。 但是我的问题是按钮的对齐方式。 我无法相应地对齐它们(左,中,右),当前我正在使用浮点数来实现该目的,但是当窗口调整大小时,即使我对两个按钮使用了%边距,最后一个元素也会降至下方。 还有其他方法可以做到这一点吗? 左右对齐按钮并使它们同时响应。

您可以尝试在每个按钮上设置margin: auto

如果这样不起作用,您可以添加

.download-buttons {
  display: flex;
  display: ms-flex;
  display: -webkit-flex;
{

到您的CSS。 它似乎在jsfiddle中工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM