【问题标题】:align three buttons horizontally (left, center, right)水平对齐三个按钮(左、中、右)
【发布时间】:2022-04-22 07:46:47
【问题描述】:

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;
            }
    }

update Fiddle

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

【问题讨论】:

标签: html css


【解决方案1】:

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

如果不行,你可以添加

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

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-08
  • 2020-12-20
相关资源
最近更新 更多