Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CSS looks different after html injection

Posted on 2013-06-03
3
Medium Priority
?
347 Views
Last Modified: 2013-06-04
Please have a look at http://jsfiddle.net/rgcBs/
A .js interval injects html divs equal to other divs already there. CSS rules apply the same to all divs, but the injected divs do not look the same as the divs already there.
Demo source:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
#divScroll div span
{
    display: inline-block;
    border: 1px solid black;
    margin: 0px;
    padding: 0px;
}

.col1 { width: 5%; }
.col2 { width: 25%; }
.col3 { width: 10%; }
.col4 { width: 30%; }

    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript">
        var hInterval;
        var iCount = 0;
        $(document).ready(function () {
            hInterval = setInterval(function () {
                html = '<div class="row"><span class="col1">'+iCount+'</span><span class="col2">asdfsadfasdfsdf</span><span class="col3">Test3</span><span class="col4">Teasdasdfasasdasdfst4</span></div>';
                $('#divScroll div.heading').after(html);
                iCount++;
                if (iCount == 10) clearInterval(hInterval);
            }, 1000);
        });
    </script>
</head>
<body>
    <div id="divScroll">
        <div class="heading">
            <span class="col1">Col1</span>
            <span class="col2">Column2</span>
            <span class="col3">Col3</span>
            <span class="col4">This is Col4</span>
        </div>
        <div class="row">
            <span class="col1">15</span>
            <span class="col2">Long long</span>
            <span class="col3">Sh</span>
            <span class="col4">Even longer</span>
        </div>
        <div class="row">
            <span class="col1">15</span>
            <span class="col2">Long long</span>
            <span class="col3">Sh</span>
            <span class="col4">Even longer</span>
        </div>
    </div>
</body>
</html>

Open in new window


Please, tell me how I can make it look like a table, and that the cells are the same width wether they are injected or there already.
0
Comment
Question by:lefodnes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:lefodnes
ID: 39217619
I made it have the exact same HTML and content of elements : http://jsfiddle.net/rgcBs/1/
0
 
LVL 58

Accepted Solution

by:
Gary earned 1000 total points
ID: 39217691
Add \n after each of your spans in the js
0
 
LVL 25

Assisted Solution

by:Kyle Hamilton
Kyle Hamilton earned 1000 total points
ID: 39217778
you can do above if you want the spaces that those inline elements create between each other.

the other thing you can do is display:block; and float:left; This will remove the spaces between elements:

http://jsfiddle.net/rgcBs/5/
0

Featured Post

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question