Ways to enhance the appearance of this button arrangement

Having trouble setting an image as the button and getting rid of the lines in-between the buttons. Any assistance would be greatly appreciated. Thank you.

All names, links, and files used here are just for illustrative purposes.

.button {
  width: 200px;
  height: 80px;
  font-weight: 700;
  font-size: 17px;
  margin: 20px;
  background: url(button1.jpg);
  background-size: cover;
}
<h1 style="text-align:center;">
  <div id=button12>
    <a href="https://www.youtube.com/">
      <button class="button">Test 1</button>
    </a>
    <a href="https://www.twitch.tv/directory">
      <button class="button">Test 2</button>
    </a>
  </div>
  <a href="https://duckduckgo.com/?q=translate&t=chromentp&atb=v314-1&ia=web">
    <button class="button">Test 3</button>
  </a>

Answer №1

Having the right tool is key.

A button nested inside an anchor tag is not valid in HTML. Avoid using javascript when plain HTML will suffice.

Simplify by using a link and customizing its style as needed. The crucial step is to set your a element to display:inline-block, then apply button-esque styling

.button {
  width: 200px;
  height: 80px;
  font-weight: 700;
  font-size: 17px;
  margin: 20px;
  /*Insert Your image*/
  background: url("http://www.fillmurray.com/g/200/80");
  /*Set it as an inline block*/
  display: inline-block;
  background-size: cover;
  border: 2px inset grey;
  /*remove default link styling*/
  text-decoration: none;
  color: black;
  /*Vertically align text - other methods are available but this is quick*/
  line-height: 80px;
  /*Enhance text readability*/
  text-shadow: 1px 1px 0px white;
}

.button:hover {
  /*Add hover effect*/
  text-shadow: 2px 2px 1px white;
}
<h1 style="text-align:center;">
  <div id=button12>
    <a href="https://www.youtube.com/" class="button">Test 1</a>
    <a href="https://www.twitch.tv/directory" class="button">Test 2</a>
  </div>
  <a href="https://duckduckgo.com/?q=translate&t=chromentp&atb=v314-1&ia=web" class="button">Test 3</a>
</h1>

Alternative methods like flex or CSS grid can be used for layout, but I'll stick to the basics for now.

Answer №2

To remove the line under the Anchor text, you can simply add text-decoration:none. However, I suggest delving into HTML and CSS tutorials to grasp a better understanding. You can achieve the same result without using <H1> tags which are primarily meant for headers.

There are other ways to center buttons and divs without relying on h1 tags. You can also style anchors to resemble buttons if that fits your preference. The possibilities are endless in the web development world.

<style>
  .button{
    width:200px;
    height:80px;
    font-weight:700;
    font-size:17px;
    margin:20px;
    background:url(button1.jpg);
    background-size: cover;
  }
  a {
    text-decoration:none;
  }
</style>
<head>
  <title>Registrations site</title>
</head>
<body>
  <h1 style="text-align:center;">
    <div id=button12>
      <a href="https://www.youtube.com/">
        <button class="button">Test 1</button>
      </a>
      <a href="https://www.twitch.tv/directory">
        <button class="button">Test 2</button>
      </a>
    </div>
    <a href="https://duckduckgo.com/?q=translate&t=chromentp&atb=v314-1&ia=web">
      <button class="button">Test 3</button>
    </a>
  </h1>
</body>

Answer №3

.wrap-all {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.rowone {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}
.rowtwo {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

.button {
  width: 200px;
  height: 80px;
  font-weight: 700;
  font-size: 17px;
  margin: 20px;
  background: url(button1.jpg);
  background-size: cover;
}

.button-div {
  border: 1px solid black;
  height: auto;
  width: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.wrapper {
  display: flex;
}

.img-wrapper {
  object-fit: fill;
  object-position: right;
  height: 100%;
  width: 100%;
}

.title-btn {
  position: absolute;
  z-index: 999;
  font-size: 12px;

}
<body>
  <h1 style="text-align:center;">
    <div class="wrap-all">

      <div class="rowone">
        <div class="button-div" onclick="location.href='https://www.youtube.com/';">
          <img class="img-wrapper" src="http://assets.stickpng.com/images/580b57fcd9996e24bc43c545.png" />
          <span class="title-btn">Youtube</span>
        </div>


        <div class="button-div" onclick="location.href='https://www.twitch.tv/directory/';">
          <img class="img-wrapper" src="https://www.freepnglogos.com/uploads/twitch-app-logo-png-3.png" />
          <span class="title-btn">Twitch</span>
        </div>
        </div>
      

     <div class="rowtwo">
        <div class="button-div" onclick="location.href='https://duckduckgo.com/?q=translate&t=chromentp&atb=v314-1&ia=web';">
          <img class="img-wrapper" src="https://download.logo.wine/logo/DuckDuckGo/DuckDuckGo-Logo.wine.png" />
          <span class="title-btn">Duck</span>
        </div>
        </div>



    </div>


</body>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A single snippet of JavaScript blocking the loading of another script

I've encountered an issue where the code seems to be conflicting with itself. The top part works fine, but the bottom part doesn't. However, when I remove the top portion, everything works as intended! You can see a working example of both compo ...

The Angular Table row mysteriously vanishes once it has been edited

Utilizing ng-repeat within a table to dynamically generate content brings about the option to interact with and manage the table contents such as edit and delete. A challenge arises when editing and saving a row causes it to disappear. Attempts were made ...

What is the reason that PHP has the ability to set Cookies but Local Storage does not?

Let's take a step back to the era of cookies, not too far back since they are considered old but still quite relevant. PHP allows you to set and read them even though they are a client-side technology; however, JavaScript can also be used completely o ...

The Python Django site is failing to detect and implement CSS updates

Currently, I am in the process of developing a Django website where I have successfully loaded my CSS and HTML files as static resources. In this project, I am utilizing two CSS files: one for Bootstrap and another for my custom styling. However, I encoun ...

React - Render an element to display two neighboring <tr> tags

I'm in the process of creating a table where each row is immediately followed by an "expander" row that is initially hidden. The goal is to have clicking on any row toggle the visibility of the next row. To me, it makes sense to consider these row pa ...

Using the ternary operator in a Python HTML template

Exploring various python ternary operators, I came across this one: a if b else 0 However, it didn't function as expected when I attempted to integrate it into a Django HTML template. {% a if b else 0 %} Here is the specific code snippet that I pl ...

Challenges with jQuery Image Sliders

Currently, I am learning from a tutorial on creating a custom jQuery content slider and you can find the tutorial here. Everything is working smoothly in terms of creating the image slider. However, I am facing an issue where I want to have the 'Next ...

Utilize CSS with dynamically created elements

I am currently figuring out how to use my .each() function with a $(document).ready and a click event. Here's what I have so far: $(document).ready(function(){ $(".help-inline").each(function() { $(this).css('display', 'none&apos ...

There is a single div sandwiched between two others, with each of the surrounding divs reaching the edge of the browser

Require a small space between the middle div and the two on each side. The middle bar should have a fixed width. Here is my attempt so far, but it seems messy: <!DOCTYPE html> <html> <head> <style> #container { width: auto; ...

Why is the image not disappearing even after using JavaScript to do so?

I'm having an issue with my JavaScript code that is supposed to make an image disappear when the data-slide-to attribute is equal to 1. However, the image remains visible even though the code seems correct. Can anyone help me understand why it's ...

Is there a way to showcase whitespacing in HTML?

I have a database full of content that includes whitespace formatting for display on a webpage. However, when viewed on Stackoverflow using the code tag, the formatting changes. The second way shows how it is stored in the database and how I want it to app ...

Retrieve the data stored in the HTML input field prior to transferring it to the SQL database

Currently, I have a form where users input latitude and longitude coordinates, which are then used to create markers and send them to the MySQL database. However, I would like to update it so that users can input an address instead. I attempted to use the ...

Learn how to dynamically insert input data into a table based on a specific ID in React JS!

[Help needed! I am trying to store the marks, id, and name values of each cell in objects of an array. However, I am not getting the correct answer. Can someone guide me on how to properly store the marks and id of each cell in objects of an array? const [ ...

Utilizing personalized CSS for specific ioslides

If I decide to stick with the default data and presentation of a new ioslides, changing only the second slide (## R Markdown) without affecting the entire item, how can I do this by setting up the css document accordingly? My goal is to simply adjust the f ...

Having trouble with imagecopyresampled function, unsure of the reason behind its malfunction

I am currently trying to use imagecopyresampled to crop a specific section of an image, in order to prevent users from uploading photos larger than the intended size on my website. However, I am facing an issue where imagecopyresampled seems to be resizing ...

Exploring the Power of Websharper with Sitelets and Forms

I have been working on developing a form using Websharper to gather user input. Currently, I have identified three actions for my website: type MyAction = | [<CompiledName "">] Index | [<Method "POST">] GetUser of username : string ...

flask - Transfer data from Python to HTML using a database

I have written code to fetch data from a database and now I want to display it in an HTML format. Below is the code snippet from app.py @app.route('/news') def news(): import pymysql import re host='localhost' user = ...

Setting the root position of a div: How can it be done?

Imagine a scenario where a div element is designed to follow the mouse cursor on the screen. This functionality is achieved by manipulating the document's `mousemove` event and adjusting the div's `left` and `top` positions based on the event dat ...

Any tips for modifying my jQuery script so that a div smoothly tracks my cursor's movement?

My jQuery code creates a span in the shape of a circle following my cursor, but I saw another website that uses transform: translate() instead of top and left properties for smoother cursor movement. Can someone help me modify the code to use transform: tr ...

Changing the navigation bar's position from fixed to static while scrolling using Bootstrap

I am attempting to keep the navbar at the top by setting a fixed position with 'top: 0' on scroll for navbar-default, and return the navbar to its original position when scrolling up (to top 300). Below is my code: var height = jQuery('.n ...