具有属性位置的外形(相对,绝对)或浮动

时间:2017-11-20 20:01:39

标签: html css shape geometry

我正在尝试构建一个圆形的div(border-radius:50%)并剪切这个元素周围的空间,以便文本采用我的div的形状(shape-outside:circle(50%) )。

到目前为止,问题很好但是我无法使用该位置的属性来设置它,因为:

  1. 如果我在我的形状上使用position:absolute,则div将从其他元素的流中取出(包括我的段落),因此如果我将它放在元素附近,文本将不会移动

  2. 如果我使用属性position:relative with float:left我的div的位置将保留在那里,所以shape-outside:circle(50%)将起作用,我的div不会移动,但是在这种情况下,shape-outside的属性将应用于真实空间(div的高度和高度将占据整个空间加上元素的位置。

  3. 这是我的属性位置示例:relative:

    <div class="box">
        <div class="half">
            <div class="rounded">
                <img src="myimage" alt="logo new path">
            </div>
            <div class="shapeout"></div>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
        </div>
        <div class="half">
            <h1>Holiday Clinic Hours</h1>
            <p>All walk-in clinic locations will be closed for the following holidays in December & January.</p> 
            <p>We are closed:</p>
            <ul>
                <li>Friday, December 22nd</li>
                <li>Monday, December 25th</li>
                <li>Tuesday, December 26th</li>
                <li>Friday, December 29th</li>
            </ul>
    
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
        </div>
    </div>
    

    和css:

    .box {
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        -webkit-box-flex: 0;
        -ms-flex: 0 1 auto;
        flex: 0 1 auto;
        -webkit-box-orient: horizontal;
        -webkit-box-direction: normal;
        -ms-flex-direction: row;
        flex-direction: row;
        -ms-flex-wrap: wrap;
        flex-wrap: wrap;
    }
    .half {
        padding: 40px;
        color: white;
    }
    .half:nth-of-type(1) {
        background: #333333;
        -ms-flex-preferred-size: 25%;
        flex-basis: 25%;
        max-width: 25%;
    }
    .half ul {
        padding: 0;
    }
    .half li {
        font-weight: bold;
        list-style-type: none;
    }
    .half:nth-of-type(2) {
        background: #0154A6;
        -ms-flex-preferred-size: 75%;
        flex-basis: 75%;
        max-width: 75%;
    }
    .half h1 {
        color: white;
    }
    .rounded {
        width: 100px;
        height: 100px;
        background: white;
        padding: 33px;
        border-radius: 50%;
        position: relative;
        top: -1%;
        left: -11%;
        float: left;
        shape-outside: circle(50%);
    }
    .rounded img {
        width: 80px;
    }
    

    有没有人有同样的问题?

    为了清楚起见,我正试图获得类似的东西:

    enter image description here

1 个答案:

答案 0 :(得分:1)

我删除了(评论过)属性&#34; display:flex;&#34;在css中,我能够复制你在屏幕截图中显示的布局。

这对您的情况有帮助吗?

&#13;
&#13;
.box {
  display: -webkit-box;
  display: -ms-flexbox;
/*  display: flex; */
  -webkit-box-flex: 0;
  -ms-flex: 0 1 auto;
  flex: 0 1 auto;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
}

.half {
  padding: 40px;
  color: white;
}

.half:nth-of-type(1) {
  background: #333333;
  -ms-flex-preferred-size: 25%;
  flex-basis: 25%;
  max-width: 25%;
}

.half ul {
  padding: 0;
}

.half li {
  font-weight: bold;
  list-style-type: none;
}

.half:nth-of-type(2) {
  background: #0154A6;
  -ms-flex-preferred-size: 75%;
  flex-basis: 75%;
  max-width: 75%;
}

.half h1 {
  color: white;
}

.rounded {
  width: 100px;
  height: 100px;
  background: white;
  padding: 33px;
  border-radius: 50%;
  position: relative;
  top: -1%;
  left: -11%;
  float: left;
  shape-outside: circle(50%);
}

.rounded img {
  width: 80px;
}
&#13;
<div class="box">
  <div class="half">
    <div class="rounded">
      <img src="myimage" alt="logo new path">
    </div>
    <div class="shapeout"></div>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
  </div>
  <div class="half">
    <h1>Holiday Clinic Hours</h1>
    <p>All walk-in clinic locations will be closed for the following holidays in December & January.</p>
    <p>We are closed:</p>
    <ul>
      <li>Friday, December 22nd</li>
      <li>Monday, December 25th</li>
      <li>Tuesday, December 26th</li>
      <li>Friday, December 29th</li>
    </ul>

    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
  </div>
</div>
&#13;
&#13;
&#13;