2017-11-18 106 views
-1

示例:https://gyazo.com/8d717ee1a21ed49033deece5a105239d(Photoshop)。 黑色=滑塊,灰色=圖片,白色=可變背景顏色的Textarea。文本和圖像的一半,彼此相鄰排列

我也想讓這個響應電話設備等,但這也不起作用,如果我只是一個圖像,是頁面widht和高度的一半。

我正在嘗試將圖像對齊左側,文本恰好位於旁邊的容器中,文本背景可以更改。我嘗試使用剩下的屬性:正確的:,邊距和填充,但不起作用。

圖片和文字應該在名爲A3L_Slogan和A3L_Catchphrase的div下面。我希望任何人都能指出我的好方向。

下面你可以找到一個JS小提琴,沒​​有任何的代碼呢

body { 
 
    width: 100%; 
 
    margin: 0; 
 
    font-family: 'open sans', sans-serif; 
 
    zoom: 1; 
 
    overflow-x: hidden; 
 
} 
 

 
header { 
 
    padding: 20px 0; 
 
    background-color: #ffffff; 
 
    box-shadow: 0 4px 6px rgba(0,0,0,.2); 
 
} 
 
.container { 
 
    padding: 0 20px; 
 
    margin: 0 auto; 
 
} 
 
.logo-box { 
 
    float: left; 
 
    margin-right: 20px; 
 
} 
 
.logo-box a { 
 
    outline: none; 
 
    display: block; 
 
} 
 
.logo-box img {display: block;} 
 
nav { 
 
    overflow: hidden; 
 
} 
 
ul { 
 
    list-style: none; 
 
    margin: 0; 
 
    padding: 0px 10px 0px 0px; 
 
    float: right; 
 
} 
 
nav li { 
 
    display: inline-block; 
 
    margin-left: 25px; 
 
    height: 70px; 
 
    line-height: 70px; 
 
    transition: .5s linear; 
 
} 
 
nav a { 
 
    text-decoration: none; 
 
    display: block; 
 
    position: relative; 
 
    color: #868686; 
 
    text-transform: uppercase; 
 
} 
 
nav a:after { 
 
    content: ""; 
 
    width: 0; 
 
    height: 2px; 
 
    position: absolute; 
 
    left: 0; 
 
    bottom: 15px; 
 
    background: #868686; 
 
    transition: width .5s linear; 
 
} 
 
nav a:hover:after {width: 100%;} 
 

 
@media screen and (max-width: 660px) { 
 
    header {text-align: center;} 
 
    .logo-box { 
 
    float: none; 
 
    display: inline-block; 
 
    margin: 0 0 16px 0; 
 
    } 
 
    ul {float: none;} 
 
    nav li:first-of-type {margin-left: 0;} 
 
} 
 
@media screen and (max-width: 550px) { 
 
nav {overflow: visible;} 
 
nav li { 
 
    display: block; 
 
    margin: 0; 
 
    height: 40px; 
 
    line-height: 40px; 
 
} 
 
nav li:hover {background: rgba(0,0,0,.1);} 
 
nav a:after {content: none;} 
 
} 
 
.A3L_Slogan, .slideshow{ 
 
    position: relative; 
 
} 
 
.slideshow{ 
 
    height: 600px; 
 
} 
 
.fadein img { 
 
    width: 100%; 
 
    position: absolute; 
 
    max-height: 600px; 
 
    left:0; 
 
    top:0; 
 
} 
 

 
.A3L_Slogan { 
 
margin-top: 20px; 
 
margin-bottom: 20px; 
 
text-align: center; 
 
} 
 

 
.slogan_title { 
 
    font-size: 46px; 
 
    font-weight: 700; 
 
    padding: 15px; 
 
    text-transform: uppercase; 
 
} 
 

 
.slogan_catchphrase { 
 
    font-size: 30px; 
 
    font-weight: 500; 
 
    text-transform: uppercase; 
 
} 
 

 
@media only screen and (max-width: 640px) { 
 
    .slideshow{ 
 
     height: 300px; 
 
    } 
 
    .fadein img { 
 
    width: 100%; 
 
    position: absolute; 
 
    max-height: 300px; 
 
    left:0; 
 
    top:0; 
 
    } 
 
} 
 

 
@media only screen and (max-width: 600px) { 
 
    .slideshow{ 
 
     height: 200px; 
 
    } 
 
    .fadein img { 
 
    width: 100%; 
 
    position: absolute; 
 
    max-height: 200px; 
 
    left:0; 
 
    top:0; 
 
    } 
 
} 
 

 
@media only screen and (max-width: 480px) { 
 
    .logo { 
 
    max-width: 270px; 
 
    } 
 
    } 
 

 
}
<html> 
 
    <head> 
 
    <title></title> 
 
    <link rel="stylesheet" type="text/css" href="css/style.css" /> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
    <script> 
 
    $(function() { 
 
    $('.fadein img:gt(0)').hide(); 
 
    setInterval(function() { 
 
     $('.fadein :first-child').fadeOut().next('img').fadeIn().end().appendTo('.fadein'); 
 
    }, 4000); 
 
    }); 
 
    </script> 
 

 

 
    </head> 
 
    <body> 
 
    <header> 
 
     <div class="container"> 
 
     <div class="logo-box"> 
 
      <a href="/"> 
 
      <img class="logo" src="images/logo.png"> 
 
      </a> 
 
     </div> 
 
      <nav> 
 
      <ul> 
 
       <li><a href="">Forums</a></li> 
 
       <li><a href="">Rules</a></li> 
 
       <li><a href="">Monetization</a></li> 
 
       <li><a href="">Sign-up</a></li> 
 
       <li><a href="">Staff</a></li> 
 
      </ul> 
 
     </nav> 
 
     </div> 
 
    </header> 
 
    <div class="slideshow"> 
 
     <div class="fadein"> 
 
     <img src="http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-159465.jpg" alt=""> 
 
     <img src="http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-160434.png" alt=""> 
 
     <img src="http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-150988.jpg" alt=""> 
 
     </div> 
 
    </div> 
 
    <div class="A3L_Slogan"> 
 
     <div class="slogan_title"> 
 
     Hardcore Roleplay Community 
 
     </div> 
 
     <div class="slogan_catchphrase"> 
 
     The next level roleplay experience 
 
     </div> 
 
    </div> 
 
    </body> 
 
</html>

回答

0

把你的圖片和文字在一個容器中,如:

<div class="container-row"> 

    <div class="hero-image"> 
     <img src="http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-159465.jpg" alt=""> 
    </div> 
    <div class="A3L_Slogan"> 
     <div class="slogan_title"> 
     Hardcore Roleplay Community 
     </div> 
     <div class="slogan_catchphrase"> 
     The next level roleplay experience 
     </div> 
    </div> 
    </div> 

和您可以使用彈性盒對齊項目

.container-row{ 
    display: flex; 
} 

.container-row .hero-image{ 
    flex: 1; 
} 

.container-row .A3L_Slogan { 
    flex: 2; 
} 
+0

你好,我已經試過了,看起來並不奏效。它只會使圖像變成全寬。 A3L口號div應該保持在原來的位置,應該放在這個口號下面,用不同的文字和標題。 – BPrepper

+0

您必須設置圖片的寬度。 – bhansa

+0

對於響應能力,最好是在css中還是在img部分中設置最大寬度? – BPrepper