2

I'm working on a small HTML page that would include some buttons on the page. I would like to add a background image to these buttons and have the background image continue where the last one left off (plus the margin in between them).

Here is a quick mock up I made in Photoshop of what I mean by this (mock up shown on the top and the background used is shown in the bottom):

Mock up of how the buttons should look

If I were to write pseudo code for to solve this problem it would probably be:

if Button and Image intersect: 
    Button.Background_image = Image_intersection 

The HTML and CSS code that I've written for this HTML page is:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Main Document</title>

    <style>
        *{
            background: lightblue;
        }
        p{
            color:Black;
        }
        button{
            color:red;
            padding: 30px;
            margin-right: 50px;
            border-radius: 40px;
            border:2px black solid;
            background-image: url('images/im.jpg')
            width:50%
            height:50%
        }
    </style>

</head>
<body>
    <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quasi, harum.</p>
    <div class="buttons">
        <button>Button 1</button>
        <button>Button 2</button>
        <button>Button 3</button>
        <button>Button 4</button>
        <button>Button 5</button>
    </div>
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Id quaerat dignissimos aperiam incidunt molestias officiis ullam iusto consequuntur, obcaecati impedit nemo nesciunt ratione similique cumque? Deserunt reprehenderit pariatur officiis nisi natus. Cupiditate culpa mollitia ad beatae voluptates similique quos obcaecati magnam saepe commodi quae, facilis a assumenda suscipit ab? Aut?</p>
    
</body>
</html>

This HTML code however doesn't do what I have set out to do (shown in the mock up). How can I get around this?

James Ronald
  • 81
  • 1
  • 4
  • https://stackoverflow.com/a/2738992/11222429[enter link description here](https://stackoverflow.com/a/2738992/11222429) this will help you – ritheesh Jun 22 '19 at 10:37
  • I just gave it a try. Now the container that has the buttons is the one with the background and the buttons themselves don't have the background image. It looks different from the mock up. – James Ronald Jun 22 '19 at 10:45
  • You can try `.buttons{ background:url("images/im.jpg"); } button{ background: transparent; }` but the main problem is that all background get transparent – Ritesh Khandekar Jun 22 '19 at 12:02

0 Answers0