Solved

CSS looks different after html injection

Posted on 2013-06-03
3
343 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 250 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 250 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

735 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