Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CSS looks different after html injection

Posted on 2013-06-03
3
Medium Priority
?
348 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
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
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).

783 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