文字和图像的一半,彼此相邻排列

时间:2017-11-18 11:04:04

标签: html css

示例:https://gyazo.com/8d717ee1a21ed49033deece5a105239d(Photoshop)。 黑色=滑块,灰色=图像,白色=具有可变背景颜色的Textarea。

我也希望对手机设备等做出响应,但这也不起作用,如果我只拍摄一张距离页面一半的图像和高度。

我正在尝试将图像左侧和文本准确地放在旁边的容器中,文本的背景可以更改。我尝试使用左边的属性:;右:;,边距和填充,但不起作用。

图像和文本应位于名为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>

1 个答案:

答案 0 :(得分: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>

您可以使用flexbox对齐项目

.container-row{
  display: flex;
}

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

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