Solved

CSS looks different after html injection

Posted on 2013-06-03
3
338 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
Comment Utility
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 250 total points
Comment Utility
Add \n after each of your spans in the js
0
 
LVL 25

Assisted Solution

by:Kyle Hamilton
Kyle Hamilton earned 250 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now