0

I'm not sure if the title uses accurate terminology; HTML is not my strong point. I'm trying to create a WordPress page and avoid using a table to accomplish what I want. I have several sections, each with an associated image. The text is flowing around the right-aligned image. I want each "section" to start on it's own line, or to NOT flow around the image from the previous section. If I were doing this with a table I would have a single column with a row for each "section" I wanted. Like I said, I don't want to use a table.

A picture is worth 1k words, so here we go. This is what I want: enter image description here

and this is what I do not want (but what I'm getting just using < p > and < h2 > tags): enter image description here

I'd like to know if there is a technique that will allow me to force the "Section 2" tag to start below the image for section 1? I added the green dashed line to illustrate where I would like to have the new section start.

scubasteve
  • 2,718
  • 4
  • 38
  • 49
  • 1
    add the css `clear: both;` to whatever container element holds section 2. If you'll post your html code, we can provide more specific help. – Lee Sep 08 '13 at 03:44
  • @Lee I'd post the HTML but WordPress is disappointing in that it strips out tags and doesn't present the true HTML. I wish it did. :( – scubasteve Sep 08 '13 at 04:08
  • Use your web browser's View Source function. – Lee Sep 08 '13 at 04:36
  • @Lee as it turns out I can't really use any of the suggestions presented here because WordPress is removing

    tags. I'm new to WordPress so maybe there is an option somewhere for it to NOT screw with your HTML, but for now I'm stuck.

    – scubasteve Sep 28 '13 at 03:44
  • If it didn't solve your problem, then you shouldn't mark an answer as accepted. Doing so can serve to confuse folks who come across this question in the future. That said, I'm fairly certain that each of your section headings is wrapped in a heading element (probably `

    ` or `

    `), and if you'll add a css rule that applies `clear:both` to that heading element, you'll get the behavior you're looking for. Again, if you'll "view source" in your browser, and cut/paste the relevant html into your question, I'll be able to give you a definitive answer.

    – Lee Sep 30 '13 at 20:28

4 Answers4

0

What is the issue, the issue might be because, you are having all of the content wrapped in one div, and you are just writing it all in that one div like this:

<div>
  <div class="content_one">
    <span style="float: left;">Some Text</span>
    <img style="float: right" src="~/folder/file.png" alt="photo" />
    // and the second one starts just under that!
    <span style="float: left;">Some Text</span>
    <img style="float: right" src="~/folder/file2.png" alt="photo" />
  </div>
</div>

This will cause whole of the body to be alike, and there will be almost no barrier to control the style of the elements. If only you start it like this, it would create a distance! Also to make them fix inside a div, using clearfix is also a solution. But margins would be good if you try to get the divs seperately. Suppose:

Solution:

<div>
  <div class="content_one">
   <div class="each_content">
    <span style="float: left;">Some Text</span>
    <img style="float: right" src="~/folder/file.png" alt="photo" />
   </div>
    // and the second one starts just under that!
   <div class="each_content">
    <span style="float: left;">Some Text</span>
    <img style="float: right" src="~/folder/file2.png" alt="photo" />
   </div>
  </div>
</div>

Now, for this you would try to set margin:

.each_content {
 margin: 5px;
}

It will set a margin, to the divs for 5px. You can also try to use a border, to make sure and also it would be helpfull for you to check where the divs start and where they end.

.each_content {
 margin: 5px;
 border: 4px dashed green;
}

I hope it helps you out.

Afzaal Ahmad Zeeshan
  • 15,669
  • 12
  • 55
  • 103
0

Create a wrapper element, float your p as well as img element to the left like

Demo

.wrap {
    width: 800px;
}

.wrap p {
    float: left;
    width: 500px;
}

.wrap img {
    float: left;
    width: 200px;
    border: 1px solid #f00;
}

Now your .wrap element contains floating child elements so you need to clear them, so either use overflow: hidden; on the parent element which is .wrap here, else use the snippet below to self clear parent

.clear:after {
    clear: both;
    display: table;
    content: "";
}

Why Clear Floats?

In this example am using background-color for .wrap but I don't see any color there, it's simply because the container element has no idea about the dimensions of floated elements, inorder to fix that, we clear the floats like this


You can refer this or this answer of mine which is related to the topic.

Community
  • 1
  • 1
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
  • This doesn't provide what the OP requested. First of all, it creates a fixed-width layout. Second, floating the `

    ` elements constrains all the text to its own column, not allowing it to flow around the image as the OP's graphic indicates that it should. Assuming that the images are already floated *right* (as shown in the graphics), it would be sufficient to simply wrap the content (as suggested), and then "clear" the wrapper (as also suggested). The other aspects of this answer are superfluous.

    – Lee Sep 30 '13 at 20:42
0

After trying the various suggestions presented here I'm unable to use any of them because wordpress strips out HTML tags like

so creating a container isn't supported.

I'm using tables. Ah, the evolved web...

scubasteve
  • 2,718
  • 4
  • 38
  • 49
-1

Use a clearfix class on each new section.

From Gallagher's post:

/**
 * For modern browsers
 * 1. The space content is one way to avoid an Opera bug when the
 *    contenteditable attribute is included anywhere else in the document.
 *    Otherwise it causes space to appear at the top and bottom of elements
 *    that are clearfixed.
 * 2. The use of `table` rather than `block` is only necessary if using
 *    `:before` to contain the top-margins of child elements.
 */
.cf:before,
.cf:after {
    content: " "; /* 1 */
    display: table; /* 2 */
}

.cf:after {
    clear: both;
}

/**
 * For IE 6/7 only
 * Include this rule to trigger hasLayout and contain floats.
 */
.cf {
    *zoom: 1;
}
probablyup
  • 7,636
  • 1
  • 27
  • 40
  • Please don't use clearfix. It is an ancient hack that is now almost always unnecessary. If you want a container element to expand to hold all of its children (floating and otherwise), you just need that element to become a "flow root" ([it's defined here](http://www.w3.org/TR/css3-box/#flow-root)). One easy way to get that is to add `overflow: hidden;`. – Lee Sep 08 '13 at 04:41
  • It's a time-tested technique that works in pretty much every browser. Just because something is old, doesn't mean it's worth a downvote. Submit your own solution as an answer. – probablyup Sep 08 '13 at 05:01
  • 1
    @Lee `overflow: hidden;` will cause problems when we use `box-shadow` – Mr. Alien Sep 08 '13 at 06:44
  • @ultraviol3tlux my complaint is not that it's old, but rather that it's a hack. It uses invalid css attributes (like `*zoom: 1;`), and hacky application of the `content` attribute to force the desired behavior in known versions of existing browsers. But because it relies on non-standard application of the css language, it is impossible to ensure that the hack will continue to work as intended on *future* browser versions. Just because something works, doesn't mean you should use it without considering the available alternatives. – Lee Sep 30 '13 at 20:14