【问题标题】:Can't get these divs to display inline无法让这些 div 内联显示
【发布时间】:2013-07-28 19:50:31
【问题描述】:

我有一个位于here 的网站。

我很难将一些标签显示为内联。 HTML 中没有中断,也没有明确的属性。这里缺少一些东西,但我不知道是什么。

基本上,我希望它们像这样设置......

[标志图像][滑块][标志标题]

我已经按百分比更改了滑块大小,并尝试将所有内容包装在一个新的 div 中并添加“in-line block”属性。

这是我的 HTML...

<div id="top">

    <div id="logo">
            <a href="http://dev.mpirebooking.com"><img id="logoimage" src="images/logo_mpire_management.png" width="80" height="56" alt="logo"></a></div>   <!-- Logo image -->

        <section id="slideshow">    <!-- Slideshow Start -->
        <div class="html_carousel">
            <div id="slider">
                <div class="slide">
                    <img src="images/slideshow/sliderimage1.jpg" width="3000" height="783" alt="2 Chainz"/><!-- Replace these images with your own but make sure they are 3000px wide and 783px high or the same ration -->
                </div><!--/slide-->

                <div class="slide">
                    <img src="images/slideshow/sliderimage2.jpg" width="3000" height="783" alt="French Montana"/><!-- Replace these images with your own but make sure they are 3000px wide and 783px high or the same ration -->
                </div><!--/slide-->

                <div class="slide">
                    <img src="images/slideshow/sliderimage3.jpg" width="3000" height="783" alt="2 Pistols"/><!-- Replace these images with your own but make sure they are 3000px wide and 783px high or the same ration -->
                </div><!--/slide-->

                                <div class="slide">
                <img src="images/slideshow/sliderimage4.jpg" width="3000" height="783" alt="Juicy-J"/><!-- Replace these images with your own but make sure they are 3000px wide and 783px high or the same ration -->
                </div><!--/slide-->

                                <div class="slide">
                <img src="images/slideshow/sliderimage5.jpg" width="3000" height="783" alt="Kendrick Lamar"/><!-- Replace these images with your own but make sure they are 3000px wide and 783px high or the same ration -->
                </div><!--/slide-->

                                <div class="slide">
                <img src="images/slideshow/sliderimage6.jpg" width="3000" height="783" alt="Artist Name"/><!-- Replace these images with your own but make sure they are 3000px wide and 783px high or the same ration -->
                </div><!--/slide-->



            </div><!--/slider-->
          <!--<div class="clearfix"></div>-->
        </div><!--/html_carousel-->
    </section>  <!-- Slideshow End -->

        <div id="logo">
            <a href="http://dev.mpirebooking.com"><h1 id="logotitle">MPIRE Booking</h1></a> <!-- Logo text -->
        </div><!--/logo-->

        <nav>   <!-- Navigation Start -->
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">Services</a></li>
                <li><a href="booking.html">Booking</a></li>
                <li><a href="#footer">Contact</a></li>               
            </ul>      
        </nav>  <!-- Navigation End -->

    </div><!--/top-->

这是我的 CSS...(对于您在上面看到的 div) (点击here查看完整样式表)

#top{
    height:20px;
}

#logo {
    margin-top:1%;
    text-decoration:none;
    }

#logo a:hover { color: #8f1929; text-decoration: none; }

#logoimage{
    width:200px;
    height: 141px;
    padding-right:10px;
    float:left;
}

#logotitle{
    margin-top: 50px;
    float:right;
    font-family: Broadway, Arial, Helvetica, sans-serif;
    font-weight:normal;
    font-size:200%;
    text-shadow: 0 1px 1px #FFF;
    text-decoration: none;
}

nav {
    float:right;
    width:100%;
    display:block;
    height:40px;
}

nav ul li{
    display:block;
    width:25%;
    float:left;
    text-align:center;  
}

nav ul li a{
    font-family:Lato, Helvetica, Arial, sans-serif;
    width:90%;
    text-decoration:none;
    text-transform:uppercase;
    font-weight:400;
    line-height:250%;
    display:block;
    color:#FFFFFF;
}

nav ul li a:hover{
    color:#8f1929;
}

nav ul li p{
    font-family:Lato, Helvetica, Arial, sans-serif;
    width:90%;
    text-decoration:none;
    text-transform:uppercase;
    font-weight:400;
    line-height:250%;
    display:block;
    color:#8f1929;
}

.html_carousel {
}
.html_carousel div.slide {
    position: relative;
}   
.html_carousel div.slide img {
    width: 30%;
    height: auto;
    border-radius:15px;
}

.clearfix {
    float: none;
    clear: both;
}

#slideshow{
    width:100%;
    margin-top:0%;
}

.clearfix {
    float: none;
    clear: both;
}

【问题讨论】:

    标签: html css


    【解决方案1】:

    你的代码中有一些奇怪的东西,比如巨大的宽度属性,比如幻灯片的3000px,甚至你的&lt;div id="slider"&gt; 上的14326px (!),它们没有为徽标标题留下空间。请全部检查。

    还有浮动属性:float:right 用于 logotitle 的 div 没有意义。如果它有足够的空间,则可以使用另一个float:left,因为它是最后一个。

    这里有一个使用左浮动元素创建水平内联布局的示例:www.w3schools.com/css/tryit.asp?filename=trycss_float5

    【讨论】:

    • 我明白你在说什么。这不是我设置 div 的大小,而是我在 Chrome 中检查代码时显示的内容。不过我没有设置。我不知道为什么会这样。
    • 一旦我开始使用正在渲染的图像尺寸,我就能够将它降低到我想要的位置。它现在正在工作。 Here是你想看的链接。
    • 我很高兴知道它 :) 小心你的身份证。不要对两个 div 使用相同的。我推荐使用 float:left 作为 logotitle。这样它就会有一个合适的高度,并且 1% 的边距就会生效。
    【解决方案2】:

    尝试添加此类

    .slide
    {
        display:inline-block;
    }
    

    【讨论】:

    • 我这样做了,但滑块本身显示正常。您放置的 div 处理 class="slide" 中的所有内容,但问题是它两侧的 logoimage 和 logotitle。我正在尝试让 logoimage、slider 和 logotitle 分别显示在行内。
    • 很难分辨出什么不起作用,请看这个小提琴jsfiddle.net/danield770/3yg7Z - 从您发布的代码中
    猜你喜欢
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多