0

我在对齐页面中的“按钮”时遇到问题,这些按钮实际上只是使用 CSS 制作的看起来像按钮的文本链接。它在无序列表中使用(参见下面的 HTML)。

负责的 CSS 代码在这里:

ul.cms {
    width: 85%;
    margin: 0px auto !important;
    text-align: center;
}

ul.cms li {
    width: 24.99%;
    float: left;
    background: none !important;
    padding: 0px !important;
    margin: 0px ;
    text-align: center;
    color: #666
}

ul.cms .has-icon {
    margin: auto;
    display: block;
    background-position: center top;
    background-repeat: no-repeat;
    padding-top: 140px;
    margin: 0px 8px;
}

a.ja-typo-btn {
    display: inline-block;
    text-decoration: none;
    white-space: nowrap;
    border: none;
    color: #333;
    background: none;
    text-align: center;

}

a.ja-typo-btn:hover,
a.ja-typo-btn:active,
a.ja-typo-btn:focus {
    border: none;
    background-position: bottom;
    color: #333;
}

a.ja-typo-btn-big {
    text-align: center;
    border: none;
    font-size: 110%;
    line-height: normal;
    font-weight: normal;
}

a.ja-typo-btn-big span {
    padding: 15px 23px;
    border: none;
    display: inline-block;
    text-align: center;
}

a.btn-green { background-color: #74af57 !important; border: none; }
a.btn-green:hover,
a.btn-green:active,
a.btn-green:focus { border-color: #74af57;  color: #fff; }

a.btn-green span { border: none; }

使用以下 HTML 代码(如下图所示,我已经删除了不必要的文本信息):

<ul class="cms clearfix">   
    <li>
        <a class = "has-icon icon1" 
          href = "barista-course-melbourne/espresso-basics" 
          target = "_parent"></a>    
        <a class = "ja-typo-btn btn-green ja-typo-btn-big btn-big-green" 
          href="barista-course-melbourne/espresso-basics" 
          target="_parent"
          style="text-align: center; display: inline-block;">
            <span>COURSE INFO</span>
        </a>
    </li>
</ul>

并在按钮不居中的移动设备中呈现。

这是一个屏幕截图:

在此处输入图像描述

任何见解和帮助将不胜感激。

这是我使用的完整 HTML 代码:

<div style="display: block;">
    <p> </p>
    <ul class="cms clearfix">
        <li>
            <a class="has-icon icon1" href="barista-course-melbourne/espresso-basics" target="_parent">
            </a>
            <h4>LEVEL 1</h4>
            <h4>Espresso Basics</h4>
            <br />
            <h4>3 hours - $99</h4>
            <span>An introductory barista course where you will learn fundamental barista skills.</span> 
            <a class="ja-typo-btn btn-green ja-typo-btn-big btn-big-green" href="barista-course-melbourne/espresso-basics" target="_parent">
                <span>    COURSE INFO    </span>
            </a>
        </li>
        <li>
            <a class="has-icon icon2" href="barista-course-melbourne/latte-art" target="_parent">
            </a>
            <h4>LEVEL 2</h4>
            <h4>Latte Art</h4>
            <br />
            <h4>2 hours - $150</h4>
            <span>Learn to pour like a pro. You will learn to pour rosettas, hearts and tulips. </span>
            <a class="ja-typo-btn btn-green ja-typo-btn-big btn-big-green" href="barista-course-melbourne/latte-art" target="_parent" style="text-align: center;">  
                <span>    COURSE INFO    </span>
            </a>
        </li>
        <li>
            <a class="has-icon icon3" href="barista-course-melbourne/advanced-barista-training" target="_parent">
            </a>
            <h4>LEVEL 3</h4>
            <h4>Advanced Barista</h4>
            <br />
            <h4>3 hours - $250</h4>
            <span>Do you have what it takes to become a top barista? Take your career to the next level! <br />
            </span>
            <a class="ja-typo-btn btn-green ja-typo-btn-big btn-big-green" href="barista-course-melbourne/advanced-barista-training" target="_parent" style="text-align: center;">
                <span>    COURSE INFO    </span>
            </a>
        </li>
        <li>
            <a class="has-icon icon4" href="barista-course-melbourne/home-barista-training" target="_parent"></a>
            <h4>HOME</h4>
            <h4>Barista Classes</h4>
            <br />
            <h4>Various Classes</h4>
            <span>Take a range of our home barista classes in the comfort of your own home.<br /></span>
            <a class="ja-typo-btn btn-blue ja-typo-btn-big btn-big-blue" href="barista-course-melbourne/home-barista-training" target="_parent" style="text-align: center;">            
                <span>   LEARN MORE   </span>
            </a>
        </li>
</ul>
<div class="button-avartar clearfix">
    <p> </p>
    <p style="text-align: center;"> {modal href="barista-course-melbourne/index.php?tmpl=component&amp;id=2333" class="ja-typo-btn btn-red ja-typo-btn-big btn-big-red"}        
        <span>Upcoming Barista Course Dates</span>
        {/modal}
    </p>
<p> </p>
</div>

4

6 回答 6

0

li添加位置:相对和按钮使用position:absolute; top:0; left:50%;上应该可以帮助您。

于 2013-07-10T10:14:48.073 回答
0

在您的 CSS 中,您尝试应用两次边距:

ul.cms .has-icon {
    margin: auto; /* once here */
    display: block;
    background-position: center top;
    background-repeat: no-repeat;
    padding-top: 140px;
    margin: 0px 8px; /* again here */
}

尝试这个:

ul.cms .has-icon {
    margin: 0 auto; /* center button, change 0 to 5-10 if you want some margin top and bottom */
    display: block;
    background-position: center top;
    background-repeat: no-repeat;
    padding-top: 140px;
}
于 2013-07-10T12:15:58.970 回答
0

ul.cms liwidth: 24.99%;和取出float: left;

于 2013-07-10T06:03:10.817 回答
0

不确定问题出在哪里, li 上的 text-align:center 应该将所有内联块元素居中。你能展示完整的 HTML 结构吗?也许 has-icon 和 ja-typo-btn 之间有什么关系?

于 2013-07-10T08:42:26.503 回答
0

在 上li,使用按钮,设置text-align:centerfloat:none

于 2013-07-10T04:44:06.417 回答
0

将 li 的宽度设置为 100%。我是内联的,但你可以在外部 css 本身中完成。

<ul class="cms clearfix">   
    <li style="width: 100%">
        <a class = "has-icon icon1" 
          href = "barista-course-melbourne/espresso-basics" 
          target = "_parent"></a>    
        <a class = "ja-typo-btn btn-green ja-typo-btn-big btn-big-green" 
          href="barista-course-melbourne/espresso-basics" 
          target="_parent"
          style="text-align: center; display: inline-block;">
            <span>COURSE INFO</span>
        </a>
    </li>
</ul>

小提琴:http: //jsfiddle.net/nuxbox/LhDKb/

于 2013-07-10T08:47:16.013 回答