开发者

Is it possible to convert a CSS div based layout to a table layout programmatically?

开发者 https://www.devze.com 2023-03-17 07:21 出处:网络
We\'ve had a designer come in on a freelance basis to build us an awesome internal web app in HTML and CSS (div based). However, for part of our internal system we have a legacy system which has probl

We've had a designer come in on a freelance basis to build us an awesome internal web app in HTML and CSS (div based). However, for part of our internal system we have a legacy system which has problems rendering this and it needs a table layout structure with appropriate styling for it to work.

We can't convert things manually because it will take too long as there are lots and lots of pages.

So I am going to attempt to do this programmatically. Before I start, is 开发者_如何学Gothis possible? Are there any consideration I should think about? Maybe someone has done this already?

I'll be using PHP and its DOM Document class - good idea?

I really need help on this as we might have wasted a lot of money and time on this project.


It might be possible to programatically adapt a specific case, pulling data out of a page and inserting it into a different template, for instance.

You won't be able to write something for the general case though. CSS works in a completely different way to the table layouts of the last millenium.

I'd look at getting the out of date renderer improved instead.


Could your new site simply be wrapped in a table instead of completely rewritten to use tables everywhere? If the table is the width of your site, just put the whole existing HTML inside a single table cell.

Failing that, it wouldn't (shouldn't) be overly hard to deliver the new site inside an iframe instead, although you might need some cross-frame communication for dynamically adjusting the height of the iframe based on the content (so you avoid scroll bars within the page).

I have to agree with everyone else - programmatically converting the code from semantic to tablemush would be, at the very least, hugely problematic and only partially successful at best. It would probably be faster to just do it by hand.


If the div-based HTML is sanely generated, and follows a table-like layout, something like:

<div class="table">
    <div class="row>
        <div class="cell">...</div>
        <div class="cell">...</div>
    </div>
</div>

then it wouldn't be too hard to use some DOM manipulations to transform the individual cells into their direct table-based equivalents. However, if the html is nasty, not in logical order, etc... then you're in for a world of hurt and it'd be better to modify the code to output a table from the get-go.

0

精彩评论

暂无评论...
验证码 换一张
取 消