简体   繁体   English

CSS定位问题

[英]Css Positioning Trouble

I am having trouble positioning this: CSS 我在定位时遇到了麻烦:CSS

.about {
  height: 50vh;
  background: #1f7d5b;
  color: #f7f7f7;
}
.about img {
  float: left;
  max-width: 100%;
  max-height: 100%;
}
.wrap {
  float: right;
  text-align: justify;
  height: 50vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.wrap h1 {
  font-size: 1.5em;
  font-weight: 600;
  color: #232323;
  text-align: center;
  padding: 0.5em 0;
  float: right;
  width: 100%;
}
.wrap p {
  font-size: 1em;
  font-weight: 100;
  max-width: 50em;
  text-align: center;
  line-height: 150%;
}

HTML HTML

<div class="about"><img src="/img/abstract.jpg"/>
  <div class="wrap">
    <h1>About Me</h1>
    <p>Hello, I'm a Designer, Front-end Developer and of course a Tea Enthusiast. It is my mission to program simple and elegant, responsive websites while under the influence of tea.</p>
  </div>
</div>

You can go to mckelvey.me to look at it, its the About Me section. 您可以转到mckelvey.me上它的“关于我”部分进行查看。 I have the img the way I like it but I want the .wrap section to be 100% of the width all the time take away the img width so they are on the some part. 我以自己喜欢的方式获取了img,但是我希望.wrap节始终是宽度的100%,以除去img宽度,因此它们在某些部分上。 Hard to explain... blah. 很难解释...等等。 I have tried many things. 我已经尝试了很多东西。

I would approach this differently and have the image as a background and using a margin-left:33%; 我将采取不同的方法,将图像作为背景并使用margin-left:33%; or similar to give the image adequate space. 或类似的图像,以提供足够的空间。 You can use background-size:30%; 您可以使用background-size:30%; or similar to control the size and position on the image. 或类似的控件来控制图像的大小和位置。

<div class="about" style="background:url('/img/abstract.jpg') no-repeat 0 50%;">
    <div class="wrap" style="margin-left:33%;">
        <h1>About Me</h1>
        <p>Hello, I'm a Designer, Front-end Developer and of course a Tea    Enthusiast. It is my mission to program simple and elegant, responsive websites    while under the influence of tea.</p>
    </div>
</div>

If you want to stick with the <img> route then you will want to wrap the image in a <div> and float it along, like a responsive grid. 如果要坚持使用<img>路线,则需要将图像包装在<div> ,然后像响应网格一样将其浮动。 http://www.w3schools.com/html/html_responsive.asp http://www.w3schools.com/html/html_responsive.asp

Something like this should work, gives you the general idea: 这样的事情应该起作用,给您大致的想法:

<style>
*
{
    padding: 0;
    margin: 0;
}
.about
{
    display: table;
    background: #1f7d5b;
    color: #f7f7f7;
    width: 100%;
}
.about img
{
    float: left;
    width: 25%;
}
.wrap
{
    float: right;
    width: 75%;
    text-align: justify;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.wrap h1 
{
    font-size: 1.5em;
    font-weight: 600;
    color: #232323;
    text-align: center;
    padding: 0.5em 0;
    width: 100%;
}
.wrap p
{
    font-size: 1em;
    font-weight: 100;
    text-align: center;
    line-height: 150%;
    max-width: 50em;
    margin: 0 auto;
}
</style>
<div class="about">
  <img src="http://mckelvey.me/img/abstract.jpg"/>
  <div class="wrap">
    <h1>About Me</h1>
    <p>Hello, I'm a Designer, Front-end Developer and of course a Tea Enthusiast. It is my mission to program simple and elegant, responsive websites while under the influence of tea.</p>
  </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM