Woes: Layout a page using CSS

Webnoob

Member
Joined
Jul 6, 2016
Messages
16
Reaction score
0
Ok so in my adventure to start with web programming, I have struck a brick wall. According to the interwebz, you should not use tables to layout a page, but as I understand, use CSS/HTML combo. I am really battling with this. Any good resources on this for someone needing a quick overview. I want to do as Here

Top left & top right an icon of 32x32. The header must fill the top of the page ie width - 64px

The error display must be at the bottom and fill the width. For the life of me I cannot event get this right. Here is the HTML and CSS. The #connected, #connecting, #disconnected divs are set visile/invisible by JS on the page.

The page must be responsive so that when the tablet orientation is changed, it adjusts accordingly.

Can anyone help? Somehow I dont understand the whole positioning/layout thing.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
      <title>Test</title>
      <link rel="stylesheet" type="text/css" href="RemoteDisplay.css" media="screen" />
      <script type="text/javascript" src="jquery.js"></script>
    </head>
  <body>
    <div id="header">
      <div id="home"><img src="images/Back32.png" alt=""/></div>
      <div id="clientIdentifier">Client</div>
      <div id="connecting"><img src="images/Connecting32.gif" alt=""/></div>
      <div id="connected"><img src="images/Connected32.png" alt=""/></div>
      <div id="disconnected"><img src="images/Disconnected32.png" alt=""/></div>
    </div>
    <div id=content>
      <div id="viewState"></div>
      <div id="labelIdentifier"></div>    
      <div id="weight"></div>     
      <div id="packContent"></div>
    </div>
    <div id="errorMessage">Error</div>
  </body>
</html>

Code:
#header
{
  height: 32px;
}
#home
{
  display:inline;
  width: 32px;
  height: 32px;
  background-color: dimgray;
}

#clientIdentifier 
{
  display:block;
  width: calc(100% - 64px);
  height: 32px;
  background-color: dimgray;
}

#connecting
{
  display:inline;
  float:right;
  background-color: dimgray;
  max-width:32px;
  max-height:32px;
}
#connected
{
  display:inline;
  float:right;
  visibility:hidden;
  background-color: dimgray;
  max-width:32px;
  max-height:32px;
}
#disconnected
{
  display:inline;
  float:right;
  visibility:hidden;
  background-color: dimgray;
  max-width:32px;
  max-height:32px;
}
#viewState
{
  display:block;
    visibility: visible
  float:right;
}

#errorMessage
{
  display:block;
  background-color: dimgray;
}
 
Last edited:
If you're only starting now, what tutorials are you looking at that is advising divs over tables? That's like... 2008 type stuff?

You should be getting "here is how it works" type tutorials these days, even from w3schools
 
Handcrafting a responsive website is going to be a major pain. Rather use a framework like bootstrap or similar.

I would say if you just want to get something done as quickly as possible, sure but it you actually want to learn HTML, try doing it from scratch, even just once.
 
Ok so in my adventure to start with web programming, I have struck a brick wall. According to the interwebz, you should not use tables to layout a page, but as I understand, use CSS/HTML combo. I am really battling with this. Any good resources on this for someone needing a quick overview. I want to do as Here

Top left & top right an icon of 32x32. The header must fill the top of the page ie width - 64px

The error display must be at the bottom and fill the width. For the life of me I cannot event get this right. Here is the HTML and CSS. The #connected, #connecting, #disconnected divs are set visile/invisible by JS on the page.

The page must be responsive so that when the tablet orientation is changed, it adjusts accordingly.

Can anyone help? Somehow I dont understand the whole positioning/layout thing.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
      <title>Test</title>
      <link rel="stylesheet" type="text/css" href="RemoteDisplay.css" media="screen" />
      <script type="text/javascript" src="jquery.js"></script>
    </head>
  <body>
    <div id="header">
      <div id="home"><img src="images/Back32.png" alt=""/></div>
      <div id="clientIdentifier">Client</div>
      <div id="connecting"><img src="images/Connecting32.gif" alt=""/></div>
      <div id="connected"><img src="images/Connected32.png" alt=""/></div>
      <div id="disconnected"><img src="images/Disconnected32.png" alt=""/></div>
    </div>
    <div id=content>
      <div id="viewState"></div>
      <div id="labelIdentifier"></div>    
      <div id="weight"></div>     
      <div id="packContent"></div>
    </div>
    <div id="errorMessage">Error</div>
  </body>
</html>

Code:
#header
{
  height: 32px;
}
#home
{
  display:inline;
  width: 32px;
  height: 32px;
  background-color: dimgray;
}

#clientIdentifier 
{
  display:block;
  width: calc(100% - 64px);
  height: 32px;
  background-color: dimgray;
}

#connecting
{
  display:inline;
  float:right;
  background-color: dimgray;
  max-width:32px;
  max-height:32px;
}
#connected
{
  display:inline;
  float:right;
  visibility:hidden;
  background-color: dimgray;
  max-width:32px;
  max-height:32px;
}
#disconnected
{
  display:inline;
  float:right;
  visibility:hidden;
  background-color: dimgray;
  max-width:32px;
  max-height:32px;
}
#viewState
{
  display:block;
    visibility: visible
  float:right;
}

#errorMessage
{
  display:block;
  background-color: dimgray;
}

Use this my son:

getbootstrap.com

HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Bootstrap CDN Template</title>

    <!-- Bootstrap -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
    
    <!-- Custom CSS -->
    <style>
    body {
        padding-top: 70px;
        /* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */
    }
    </style>
    
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
  
    <!-- Navigation -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">Home</a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li>
                        <a href="#">About</a>
                    </li>
                    <li>
                        <a href="#">Services</a>
                    </li>
                    <li>
                        <a href="#">Contact</a>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>

    <!-- Page Content -->
    <div class="container">

        <div class="row">
            <div class="col-lg-12 text-center">
                <h1>USER CONNECT SCREEN</h1>
                <p class="lead">Complete with pre-defined CND links that you won't have to change!</p>
                <ul class="list-unstyled">
                    <li>Bootstrap v3.3.6</li>
                    <li>jQuery v1.11.1</li>
                </ul>
            </div>
        </div>
        <!-- /.row -->

    </div>
    <!-- /.container -->

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
  </body>
</html>
 
You could also hard set the positions of those two icons divs ie:

#home{
top:0;
left:0;
z-index:9999
}
#disconnected{
top:0;
right:0;
z-index:9999
}
#clientIdentifier{
margin-left:32px;
margin-right:32px;
width:100%
}

Something like that, a bit messy I know but using hard set widths will always cause that.

Rather use a larger image and set it's width to 10% and then the bar to 80% and float email all left.
Then as the screen widens the image will expand and Shrink.
 
Hahahahaha, I feel for you! Having to support IE8 in 2009 was hard enough, I can't imagine that now.

Show whoever is costing your company/you money this http://www.w3schools.com/browsers/browsers_explorer.asp and ask them if it's worth the extra man hours to support it.

Unfortunately it comes from a certain client, who standardised their staff on IE 8, they are not allowed to use anything else... They think it's more secure that way :sick:
 
I would say if you just want to get something done as quickly as possible, sure but it you actually want to learn HTML, try doing it from scratch, even just once.

I agree with this.

Get your fundamentals down before moving off to a 'framework/library' that does the work for you.
 
!00% Listen to this man I would have repped If I could.

I went into frameworks first very successfully, but I am only now starting to get to grips with it all so much so that I make my own frameworks now, but it took much longer than it would have if I started on my own and not with a framework.
 
I had the same problems. Did a couple of pluralsight courses and was enlightened. Was well worth it. Seriously, do a few courses. Oh and use brackets. It renders to the browser while you type. Best thing since sliced bread to try and test css/html
 
Top
Sign up to the MyBroadband newsletter
X