css - 如何让文字环绕图像?

标签 css image ruby-on-rails-4 styles styling

我正在设计一个博客,我正在使用 CarrierWave 和 MiniMagic 上传图像文件。截至目前,每篇文章的顶部都会显示一张图片。我首先尝试将图片调整为矩形,但似乎即使我在调整大小下更改尺寸,图片也始终显示为正方形。 现在,我试图将文字环绕在图像周围。更具体地说,我希望图像显示在文章的左上角,文本显示在图像的右侧和图像下方:

-图像---- -----文本--------



--------文本----------------


这是我的文章索引 View :

<%= will_paginate %>
 <% @articles.each do |article| %>
 <div class="container1">
 <h4><%= link_to article.title, article_path(article) %></h4>
 <%= image_tag article.picture.url if article.picture? %>
 <p>
 <%= article.body %></p>
 <p><small><strong> Date:</strong> <%= article.created_at.to_s %></p></small>
 </p>
 </div>
 <br>
 <br>
 <% end %>
 <%= will_paginate %>
 <h6>
 <% if logged_in? %>
 <%= link_to "Create a New Article", new_article_path, class: "new_article" %>
 <% end %>
 </h6>

这是我的 CSS 样式:

@import "bootstrap-sprockets";
@import "bootstrap";
/* mixins, variables */
/* universal */
html {
overflow-y: scroll;
}
body {
padding-top: 60px;
position: relative;
}
section {
overflow: auto;
}
textarea {
resize: vertical;
}
.center {
text-align: center;
h1 {
margin-bottom: 10px;
}
}
/* typography */
h1, h2, h3, h4, h5, h6 {
line-height: 1;
}
h1 {
font-size: 3em;
letter-spacing: -2px;
margin-bottom: 30px;
text-align: center;
}
h2 {
font-size: 1.2em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: #3BB9FF;
}
p {
font-size: 1.1em;
line-height: 1.7em;
}
/* 
footer{
background-color: #222;
div ul li{
display:block;
vertical-align: top;
width: 50%;
float: left;
}
}
*/
@mixin box_sizing {
-moz-box-sizing:    border-box;
-webkit-box-sizing: border-box;
box-sizing:         border-box;
}
/* miscellaneous */
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
@include box_sizing;
}
/* forms */
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
@include box_sizing;
}
input {
height: auto !important;
}
#error_explanation {
color: red;
ul {
color: red;
margin: 0 0 30px 0;
}
}
.field_with_errors {
@extend .has-error;
.form-control {
color: $state-danger-text;
}
}
/* articles */
.container1 {
opacity: 0.75;
border: 1px solid #000000;
border-radius: 10px;
padding: 30px 75px 75px 100px;
overflow: scroll ;
 }
 .container2 {
 position: fixed;
 padding: 0px 75px 20px 100px;
 clear: both;
 background-color: #FFFFFF; /*#F8F8F8;*/
 border-radius: 5px;
 overflow: scroll;
 }

这是我的文件 uploader :

class PictureUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
 # include CarrierWave::RMagick
 # include CarrierWave::MiniMagick
 # Choose what kind of storage to use for this uploader:
 storage :file
 # storage :fog
 include CarrierWave::MiniMagick
 process resize_to_limit: [660, 660]
 if Rails.env.production?
 storage :fog
 else
 storage :file
 end
 # Override the directory where uploaded files will be stored.
 # This is a sensible default for uploaders that are meant to be mounted:
 def store_dir
 "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
  # Provide a default URL as a default if there hasn't been a file uploaded:
  # def default_url
  #   # For Rails 3.1+ asset pipeline compatibility:
  #   # ActionController::Base.helpers.asset_path("fallback/" + [version_name,        "default.png"].compact.join('_'))
  #
  #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  # end
  # Process files as they are uploaded:
  # process :scale => [200, 300]
  #
  # def scale(width, height)
  #   # do something
  # end
  # Create different versions of your uploaded files:
  # version :thumb do
  #   process :resize_to_fit => [50, 50]
  # end
  #Add a white list of extensions which are allowed to be uploaded.
  #For images you might use something like this:
  def extension_white_list
  %w(jpg jpeg gif png)
  end
  #Override the filename of the uploaded files:
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
  # def filename
  #"something.jpg" if original_filename
  #end
  end.

如何让图像位于页面的左上角,文本位于页面的右上角、左下角和右下角,以便文本环绕图像?是否可以将图像调整为矩形?我如何使用 CarrierWave 做到这一点?

最佳答案

如果图像在 p 标签中,您只需将其 float 到左侧即可。

CSS

.container1 p img {
    float: left;
    margin-right: 15px;
    margin-bottom: 15px;
}

我做了一个JSFiddle给你。

关于css - 如何让文字环绕图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47716330/

相关文章:

javascript - 如何通过@input 属性应用样式,我想增加 mat-autocomplete 的宽度

html - Chrome 中的绝对定位输入字段

ruby-on-rails - 在同一个 Controller 中使用两个不同的布局模板?

ruby-on-rails - 带有 CA 证书的 Mongo SSL 配置仅适用于 Rails 控制台,不适用于 Rails 服务器

ruby-on-rails - Rails 4 - 按未存储在数据库中的内容排序

html - 移动图像旁边带有 hr 的段落元素?

javascript - 如何更改范围 slider 标记?

image - 识别 photoshop 图像上的文字效果

javascript - Fabricjs objectCaching : zoom image content, 保持图像边框

html - 页脚背景图像顶部的图标