LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-31-2016, 10:27 AM   #1
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Rep: Reputation: 24
HTML - CSS - Removing Whitespace


OK, next simple HTML - CSS question.

I'm trying to make a simple checkerboard pattern using div, and CSS for positioning for color.

Here's the code:
Code:
<!DOCTYPE html>
<html lang="en-US">

<head>
    <meta charset="utf-8">
    <title>div test</title>
    <style>
        body {
            font-size: 0;
        }
        
        .box {
            width: 50px;
            height: 50px;
            display: inline-block;
            padding: 0;
            margin: 0;
            border: collapse;
            float: left;
            font-size: 12;
            column-width: 0;
            z-index: -1;
        }
        
        .blackSquare {
            background: black;
        }
        
        .whiteSquare {
            background: red;
        }
    </style>
</head>

<body>
    <div class="box blackSquare column1"></div>
    <div class="box whiteSquare column2"></div>
    <div class="box blackSquare column3"></div>
    <div class="box whiteSquare column4"></div>
    <div class="box blackSquare column5"></div>
    <div class="box whiteSquare column6"></div>
    <div class="box blackSquare column7"></div>
    <div class="box whiteSquare column8"></div>
</body>

</html>
See the attachment for what I get. (Whitespace between divs.)

You can see in my style that I've used all I can find for removing whitespace.

Please tell me what I am missing.

Thanks,
Doug
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2016-10-31 at 11.18.28 AM.png
Views:	14
Size:	11.7 KB
ID:	23406  
 
Old 10-31-2016, 10:43 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Works just fine under Chromium ... I would therefore guess it is a Safari issue
 
Old 10-31-2016, 10:56 AM   #3
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Yeah. Looks good.

https://jsfiddle.net/t3undmwm/
 
Old 10-31-2016, 11:29 AM   #4
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Original Poster
Rep: Reputation: 24
Weird. Because I am looking at it in Chrome. It is, however, Chrome for OS X.

Quote:
Originally Posted by grail View Post
Works just fine under Chromium ... I would therefore guess it is a Safari issue
 
Old 10-31-2016, 11:47 AM   #5
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Original Poster
Rep: Reputation: 24
OK. Really weird.

I just installed Chromium. Getting the exact same result.
 
Old 10-31-2016, 12:19 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Ok ... silly question, how are you opening the file?
 
Old 10-31-2016, 12:52 PM   #7
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Original Poster
Rep: Reputation: 24
Open Chrome/Safari/Chromium.
Press COMMAND-O.
Navigate to the file.
Click the file.
Click button that says, "Open."

Quote:
Originally Posted by grail View Post
Ok ... silly question, how are you opening the file?
 
Old 10-31-2016, 03:10 PM   #8
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Original Poster
Rep: Reputation: 24
Note: I'm getting the same thing on my Centos box in Firefox.

Edit: And in Chrome and IE on my Windows 7 VDI at work.

Yet, it works in jsfiddle.

Last edited by killingthemonkey; 10-31-2016 at 05:36 PM.
 
Old 10-31-2016, 05:44 PM   #9
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Did you try a minimal css properties set for .box? I mean
Code:
.box {
    width: 50px;
    height: 50px;
    padding: 0;
    margin: 0;
    float: left;
}
Not sure if border-collapse applies in a div, no need of column-width, nor z-index, (font-size?)
 
Old 10-31-2016, 07:21 PM   #10
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Original Poster
Rep: Reputation: 24
Truthfully, keefaz, that's where I started.

As I tried more and more solutions I found online, stuff accreted. Going back to that, leaves me in the same place.

Quote:
Originally Posted by keefaz View Post
Did you try a minimal css properties set for .box? I mean
Code:
.box {
    width: 50px;
    height: 50px;
    padding: 0;
    margin: 0;
    float: left;
}
Not sure if border-collapse applies in a div, no need of column-width, nor z-index, (font-size?)
 
Old 10-31-2016, 07:34 PM   #11
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Maybe it sounds silly but did you try removing newline chars between div's?
Like
Code:
<div class="box blackSquare column1"></div><div class="box whiteSquare column2"></div><div class="box blackSquare column3"></div>...

Last edited by keefaz; 10-31-2016 at 07:37 PM.
 
Old 10-31-2016, 09:20 PM   #12
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Original Poster
Rep: Reputation: 24
Just tried it. No luck.

Quote:
Originally Posted by keefaz View Post
Maybe it sounds silly but did you try removing newline chars between div's?
Like
Code:
<div class="box blackSquare column1"></div><div class="box whiteSquare column2"></div><div class="box blackSquare column3"></div>...
 
Old 10-31-2016, 10:00 PM   #13
killingthemonkey
Member
 
Registered: Mar 2011
Location: Winston-Salem, NC
Distribution: Fedora, CentOS, Linux Mint
Posts: 259

Original Poster
Rep: Reputation: 24
OK. I started over. I got one row to work without an issue.
The second row, however, wants to position itself at the right side of the first.

Code:
<!--<!DOCTYPE html>-->
<html lang="en-US">

<head>
    <meta charset="utf-8">
    <title>div test</title>
    <style>
        body {
            background-color: #AAAAAA;
        }
        
        .box {
            width: 50px;
            height: 50px;
            padding: 0;
            margin: 0;
            float: left;
        }
        
        .blackSquare {
            background: black;
        }
        
        .whiteSquare {
            background: white;
        }
        
        .row2 {
        	position: relative;
        	top: 50px;
        }
    </style>
</head>

<body>
    <div class="box blackSquare"></div><div class="box whiteSquare"></div><div class="box blackSquare"></div><div class="box whiteSquare"></div><div class="box blackSquare"></div><div class="box whiteSquare"></div><div class="box blackSquare"></div><div class="box whiteSquare"></div>
    <div class="box blackSquare row2"></div><div class="box whiteSquare row2"></div><div class="box blackSquare row2"></div><div class="box whiteSquare row2"></div><div class="box blackSquare row2"></div><div class="box whiteSquare row2"></div><div class="box blackSquare row2"></div> <div class="box whiteSquare row2"></div>
</body>

</html>
See new attachment.
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2016-10-31 at 10.56.08 PM.png
Views:	7
Size:	5.9 KB
ID:	23409  
 
Old 10-31-2016, 11:35 PM   #14
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Quote:
Originally Posted by killingthemonkey View Post
OK. I started over. I got one row to work without an issue.
The second row, however, wants to position itself at the right side of the first.
I think that your row2 style needs a little more thought. As shown, it simply offsets the top position but continues at the current horizontal position - just as your results show.

Also, if you are building a checkerboard you would need to then have a row3, row4, etc. style to follow that same model.

Try the code below and see what you get.

I have reordered the second row of divs for a checkerboard effect and replaced your row2 style with newrow which is only applied to the first box of trailing rows.

Code:
<!--<!DOCTYPE html>-->
<html lang="en-US">

<head>
    <meta charset="utf-8">
    <title>div test</title>
    <style>
        body {
            background-color: #AAAAAA;
        }

        .box {
            width: 50px;
            height: 50px;
            padding: 0;
            margin: 0;
            float: left;
        }

        .blackSquare {
            background: black;
        }

        .whiteSquare {
            background: white;
        }

        .newrow {
                clear: both;
        }
    </style>
</head>

<body>
    <div class="box blackSquare"></div><div class="box whiteSquare"></div><div class="box blackSquare"></div><div class="box whiteSquare"></div><div class="box blackSquare"></div><div class="box whiteSquare"></div><div class="box blackSquare"></div><div class="box whiteSquare"></div>
    <div class="box whiteSquare newrow"></div><div class="box blackSquare "></div><div class="box whiteSquare "></div><div class="box blackSquare "></div><div class="box whiteSquare "></div><div class="box blackSquare "></div> <div class="box whiteSquare "></div><div class="box blackSquare "></div>
</body>

</html>
 
Old 10-31-2016, 11:53 PM   #15
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Ultimately the question has changed seeing as you solved your original problem, however, you have not advised what it was you changed that made the difference? Remember, others will find
your question and would like to know what changed without having to go through the code and miss the subtlety, especially when you have now changed the code to perform an additional task (like more rows)
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: removing whitespace filled element from array ezekieldas Linux - Newbie 4 09-30-2013 08:43 PM
[SOLVED] sed regex and removing 'whitespace' uncle-c Linux - Newbie 5 04-23-2012 08:25 AM
CSS - Is there a way to put several lines of HTML into one line using CSS? Chronothread Programming 12 01-05-2011 06:06 AM
HTML/CSS/JS: Problem with <p> not having an absolute position with CSS. RHLinuxGUY Programming 7 03-03-2007 12:21 AM
BASH: Removing ALL whitespace from variable eur0dad Programming 1 09-07-2006 10:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration