将文本环绕按钮

发布于 2025-01-10 04:24:31 字数 1936 浏览 0 评论 0原文

我试图在页面上创建一个框,主要是文本,左上角有一个小图像,右下角有一个按钮。环绕图像很好(多年来我已经这样做了几十次),但放置按钮似乎打败了我。无论我做什么,它总是将自己置于文本下方。

.profile-container {
  margin: 1em;
  padding: 1em;
  width: calc(100% - 4em);
  background: #fff;
  border: 1px solid #2c687b
}

.profile img {
  float: left;
  height: 200px;
  width: 150px;
  margin-right: 1em
}

.profile h2 {
  font-family: 'Neuropol', sans-serif;
  font-weight: 300;
  transform: scale(1, 1.3);
  margin-bottom: .5em
}

form {
  float: right;
  margin-left: 1em
}
<div class="profile-container">
  <div class="profile">
    <img src="images/paul.jpg" alt="alt" />
    <h2>Heading</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse molestie diam consectetur suscipit tincidunt. Fusce ipsum mauris, bibendum nec massa sed, sodales mollis lacus. Sed dignissim semper neque in semper.</p>
    <p>Praesent lobortis tellus quis eros mollis congue. Nunc vel turpis vel enim vehicula commodo. Duis lectus ante, viverra ut lacinia ac, varius a nunc. Vivamus odio dui, pellentesque faucibus odio et, placerat convallis leo.</p>
    <p>Curabitur et tellus vitae massa tincidunt luctus. Fusce lacus nunc, facilisis id lobortis at, lobortis sed ante. Morbi sagittis eget nisl a lobortis. Donec interdum scelerisque erat ut blandit.</p>
    <form action="reviews.php" method="post" name="reviews">
      <input name="hiddenname" type="hidden" value="hiddenvalue">
      <input type="submit" class="button" value="My Reviews">
    </form>
  </div>
</div>

这里有一个 JSFiddle: https://jsfiddle.net/yd5v7zrf/

似乎表单总是根据其顶部边缘定位,但我需要根据其底部边缘定位它。

I am trying to create a box on a page which is mainly text with a small image at top-left and a button at bottom-right. Wrapping around the image is fine (I've done that dozens of times over the years) but placing the button seems to have beaten me. Whatever I do it always places itself below the text.

.profile-container {
  margin: 1em;
  padding: 1em;
  width: calc(100% - 4em);
  background: #fff;
  border: 1px solid #2c687b
}

.profile img {
  float: left;
  height: 200px;
  width: 150px;
  margin-right: 1em
}

.profile h2 {
  font-family: 'Neuropol', sans-serif;
  font-weight: 300;
  transform: scale(1, 1.3);
  margin-bottom: .5em
}

form {
  float: right;
  margin-left: 1em
}
<div class="profile-container">
  <div class="profile">
    <img src="images/paul.jpg" alt="alt" />
    <h2>Heading</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse molestie diam consectetur suscipit tincidunt. Fusce ipsum mauris, bibendum nec massa sed, sodales mollis lacus. Sed dignissim semper neque in semper.</p>
    <p>Praesent lobortis tellus quis eros mollis congue. Nunc vel turpis vel enim vehicula commodo. Duis lectus ante, viverra ut lacinia ac, varius a nunc. Vivamus odio dui, pellentesque faucibus odio et, placerat convallis leo.</p>
    <p>Curabitur et tellus vitae massa tincidunt luctus. Fusce lacus nunc, facilisis id lobortis at, lobortis sed ante. Morbi sagittis eget nisl a lobortis. Donec interdum scelerisque erat ut blandit.</p>
    <form action="reviews.php" method="post" name="reviews">
      <input name="hiddenname" type="hidden" value="hiddenvalue">
      <input type="submit" class="button" value="My Reviews">
    </form>
  </div>
</div>

There's a JSFiddle here: https://jsfiddle.net/yd5v7zrf/

It seems as though the form is always positioned according to its top edge, but I need to position it according to its bottom edge.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤檠 2025-01-17 04:24:31

似乎是一个崩溃的保证金问题。只需将 display: inline-block; 添加到 .profile 即可。

.profile-container {
  margin: 1em;
  padding: 1em;
  width: calc(100% - 4em);
  background: #fff;
  border: 1px solid #2c687b
}

.profile {
  display: inline-block;
}

.profile img {
  float: left;
  height: 200px;
  width: 150px;
  margin-right: 1em
}

.profile h2 {
  font-family: 'Neuropol', sans-serif;
  font-weight: 300;
  transform: scale(1, 1.3);
  margin-bottom: .5em
}

form {
  float: right;
  margin-left: 1em
}
<div class="profile-container">
  <div class="profile">
    <img src="images/paul.jpg" alt="alt" />
    <h2>Heading</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse molestie diam consectetur suscipit tincidunt. Fusce ipsum mauris, bibendum nec massa sed, sodales mollis lacus. Sed dignissim semper neque in semper.</p>
    <p>Praesent lobortis tellus quis eros mollis congue. Nunc vel turpis vel enim vehicula commodo. Duis lectus ante, viverra ut lacinia ac, varius a nunc. Vivamus odio dui, pellentesque faucibus odio et, placerat convallis leo.</p>
    <p>Curabitur et tellus vitae massa tincidunt luctus. Fusce lacus nunc, facilisis id lobortis at, lobortis sed ante. Morbi sagittis eget nisl a lobortis. Donec interdum scelerisque erat ut blandit.</p>
    <form action="reviews.php" method="post" name="reviews">
      <input name="hiddenname" type="hidden" value="hiddenvalue">
      <input type="submit" class="button" value="My Reviews">
    </form>
  </div>
</div>

Appears to be a collapsed margin issue. Just add display: inline-block; to .profile.

.profile-container {
  margin: 1em;
  padding: 1em;
  width: calc(100% - 4em);
  background: #fff;
  border: 1px solid #2c687b
}

.profile {
  display: inline-block;
}

.profile img {
  float: left;
  height: 200px;
  width: 150px;
  margin-right: 1em
}

.profile h2 {
  font-family: 'Neuropol', sans-serif;
  font-weight: 300;
  transform: scale(1, 1.3);
  margin-bottom: .5em
}

form {
  float: right;
  margin-left: 1em
}
<div class="profile-container">
  <div class="profile">
    <img src="images/paul.jpg" alt="alt" />
    <h2>Heading</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse molestie diam consectetur suscipit tincidunt. Fusce ipsum mauris, bibendum nec massa sed, sodales mollis lacus. Sed dignissim semper neque in semper.</p>
    <p>Praesent lobortis tellus quis eros mollis congue. Nunc vel turpis vel enim vehicula commodo. Duis lectus ante, viverra ut lacinia ac, varius a nunc. Vivamus odio dui, pellentesque faucibus odio et, placerat convallis leo.</p>
    <p>Curabitur et tellus vitae massa tincidunt luctus. Fusce lacus nunc, facilisis id lobortis at, lobortis sed ante. Morbi sagittis eget nisl a lobortis. Donec interdum scelerisque erat ut blandit.</p>
    <form action="reviews.php" method="post" name="reviews">
      <input name="hiddenname" type="hidden" value="hiddenvalue">
      <input type="submit" class="button" value="My Reviews">
    </form>
  </div>
</div>

执手闯天涯 2025-01-17 04:24:31

将最后一段更改为跨度: https://jsfiddle.net/57a6gwyk/

<span></span>
<form style="float:right"></form>

或者只是制作段落显示:内嵌;

回应评论:

如果您将表单移至段落上方,否则保留原样怎么样:

https://jsfiddle.net/oq9pu3vy/

Change the last paragraph to a span: https://jsfiddle.net/57a6gwyk/

<span></span>
<form style="float:right"></form>

Or just make the paragraph display:inline;

In response to the comment:

How about if you move the form up above the paragraph, and otherwise leave it as you had it:

https://jsfiddle.net/oq9pu3vy/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文