Mohamed Ali
Mohamed Ali

Reputation: 782

Image floating HTML

Working on creating a personal website.

When I shrink my screen the image in the first row goes all the way to the top. I have tried playing with the float in my css but it's not helping. There's a snapshot from the code below.

I have put it all in one file because I didn't want to separate it.

<!DOCTYPE html>
<html>
    <head>
        <title> My Life</title>
        <link rel="stylesheet" type="text/css" href="MyLife.css">
        <link href="https://fonts.googleapis.com/css?family=Contrail+One" rel="stylesheet">

        <style type="text/css">
         
            ul {
                list-style-type: none;
                margin: 0;
                padding: 0;
                overflow: hidden;
                background-color: #333;
            }

            li {
                float: left;
            }

            li a {
                display: block;
                color: white;
                text-align: center;
                padding: 14px 16px;
                text-decoration: none;
            }

            /* Change the link color to #111 (black) on hover */
            li a:hover {
                background-color: #111;
            }

            h1{
                width:20%
                text-align:center;
            }

            h2{
                text-align: center;
            }

            body{
                background-color: white;
            }
            img{
                width: 30%;
                float: left;


                margin: 1.66%;
            }

            p{
                margin-left: 1.66%;
                font-family: 'Contrail One', cursive;
                font-size: 35px;
                text-transform: uppercase;
                border-bottom: 2px solid black;
                width: 30%;
                padding-bottom: 20px;

            } 

            div.a{
                text-align: center;
            }
            
        </style>
    </head>
    <body>

        <!-- 
        This is the code for the Home Page -->

        <div class ="a">
            <h1> My Name is John </h1>
        </div>
        <h2> Welcome to my Website!</h2>


        <ul>
            <li><a href="">Home</a></li>
            <li><a href="MyHistory.html">My History</a></li>
            <li><a href="MyEducation.html">My Education</a></li>
            <li><a href="MyTravels.html">My Travels</a></li>
            <li><a href="">My Form Page</a></li>
            <li><a href="">What I Like to Do</a></li>

            <img src = "http://c1.staticflickr.com/9/8450/8026519634_f33f3724ea_b.jpg">
            <img src = "http://c2.staticflickr.com/8/7218/7209301894_c99d3a33c2_h.jpg ">
            <img src = "http://c2.staticflickr.com/8/7231/6947093326_df216540ff_b.jpg ">
            <img src = "http://c1.staticflickr.com/9/8788/17367410309_78abb9e5b6_b.jpg ">
            <img src = "http://c2.staticflickr.com/6/5814/20700286354_762c19bd3b_b.jpg ">
            <img src = "http://c2.staticflickr.com/6/5647/21137202535_404bf25729_b.jpg ">
            <img src = "http://c2.staticflickr.com/6/5588/14991687545_5c8e1a2e86_b.jpg">
            <img src = "http://c2.staticflickr.com/4/3888/14878097108_5997041006_b.jpg ">
            <img src = "http://c2.staticflickr.com/8/7579/15482110477_0b0e9e5421_b.jpg">

        </ul>

    </body>
</html>

Upvotes: 0

Views: 141

Answers (2)

Pavlo Shandro
Pavlo Shandro

Reputation: 808

You have an error in HTML. Move all the images outside of <ul>...</ul> block.

According to the HTML specification ordered <ol>...</ol> or unordered <ul>...</ul> lists may contain only <li>...</li> elements.

Upvotes: 1

Priom Sarkar
Priom Sarkar

Reputation: 342

I think you want this.Check it out.

<!DOCTYPE html>
<html>
    <head>
        <title> My Life</title>
        <link rel="stylesheet" type="text/css" href="MyLife.css">
        <link href="https://fonts.googleapis.com/css?family=Contrail+One" rel="stylesheet">

        <style type="text/css">
         
            ul {
                list-style-type: none;
                margin: 0;
                padding: 0;
                overflow: hidden;
                background-color: #333;
            }

            li {
                float: left;
            }

            li a {
                display: block;
                color: white;
                text-align: center;
                padding: 14px 16px;
                text-decoration: none;
            }

            /* Change the link color to #111 (black) on hover */
            li a:hover {
                background-color: #111;
            }

            h1{
                width:20%
                text-align:center;
            }

            h2{
                text-align: center;
            }

            body{
                background-color: white;
            }
            img{
                width: 30%;
                float: left;


                margin: 1.66%;
            }

            p{
                margin-left: 1.66%;
                font-family: 'Contrail One', cursive;
                font-size: 35px;
                text-transform: uppercase;
                border-bottom: 2px solid black;
                width: 30%;
                padding-bottom: 20px;

            } 

            div.a{
                text-align: center;
            }
            
        </style>
    </head>
    <body>

        <!-- 
        This is the code for the Home Page -->

        <div class ="a">
            <h1> My Name is John </h1>
        </div>
        <h2> Welcome to my Website!</h2>


        <ul>
            <li><a href="">Home</a></li>
            <li><a href="MyHistory.html">My History</a></li>
            <li><a href="MyEducation.html">My Education</a></li>
            <li><a href="MyTravels.html">My Travels</a></li>
            <li><a href="">My Form Page</a></li>
            <li><a href="">What I Like to Do</a></li>
        </ul>
<ul>                <img src = "http://c1.staticflickr.com/9/8450/8026519634_f33f3724ea_b.jpg">
            <img src = "http://c2.staticflickr.com/8/7218/7209301894_c99d3a33c2_h.jpg ">
            <img src = "http://c2.staticflickr.com/8/7231/6947093326_df216540ff_b.jpg ">
            <img src = "http://c1.staticflickr.com/9/8788/17367410309_78abb9e5b6_b.jpg ">
            <img src = "http://c2.staticflickr.com/6/5814/20700286354_762c19bd3b_b.jpg ">
            <img src = "http://c2.staticflickr.com/6/5647/21137202535_404bf25729_b.jpg ">
            <img src = "http://c2.staticflickr.com/6/5588/14991687545_5c8e1a2e86_b.jpg">
            <img src = "http://c2.staticflickr.com/4/3888/14878097108_5997041006_b.jpg ">
            <img src = "http://c2.staticflickr.com/8/7579/15482110477_0b0e9e5421_b.jpg">
</ul>
    </body>
</html>

Upvotes: 0

Related Questions