Building a Soccer Pitch with HTML and CSS

I've been attempting to design a Football Field using HTML & CSS, but I've hit a roadblock. Despite spending hours debugging, I haven't been able to figure it out.

Here is the code snippet I'm working with:

#EndZone {
  float: left;
  width: 300px;
  height: 500px;
  background-color: red;
}
.TopHash div {
  margin-left: 300px;
  width: 30px;
  height: 30px;
  border-right: 1px solid white;
}
#MiddleTopHash div {
  margin-top: 170px;
  width: 30px;
  height: 30px;
  border-right: 1px solid white;
  float: left;
}
.MiddleBottomHash div {
  margin-top: 270px;
  width: 30px;
  height: 30px;
  border-right: 1px solid white;
  float: left;
}
.BottomHash div {
  margin-top: 470px;
  width: 30px;
  height: 30px;
  border-right: 1px solid white;
  float: left;
}
<div class="FootballField">
  <div id="EndZone"></div>
  <div class="TopHash">
    <div id="OneYardLineTopHash"></div>
    <div id="TwoYardLineTopHash"></div>
    <div id="ThreeYardLineTopHash"></div>
    <div id="FourYardLineTopHash"></div>
  </div>
  <div id="FiveYardLine"></div>
  <div class="TopHash">
    <div id="SixYardLine"></div>
    <div id="SevenYardLine"></div>
    <div id="EightYardLine"></div>
    <div id="NineYardLine"></div>
    <div id="TenYardLine"></div>
  </div>
  <div class="MiddleTopHash">
    <div id="OneYardLineMiddleTopHash"></div>
    <div id="TwoYardLineMiddleTopHash"></div>
  </div>
  <div class="MiddleBottomHash">
    <div id="OneYardLineMiddleBottomHash"></div>
    <div id="TwoYardLineMiddleBottomHash"></div>
  </div>
  <div class="BottomHash">
    <div id="OneYardLineBottomHash"></div>
    <div id="TwoYardLineBottomHash"></div>
  </div>
</div>

Edit: How can I ensure that each hash appears 30px to the right of the other, according to this CSS rule?

.TopHash div {
    left: 300px;
    width: 30px;
    height: 30px;
    border-right: 1px solid white;
}

Edit 2: This is the desired outcome:

The only adjustment needed is to have the yard hashes spaced 30px apart from each other.

Answer №1

Seems like I'll be tackling this challenge the difficult way

HTML:

    <div class="SoccerField">
    <div id="GoalBox"></div>
    <div class="TopHashes">
    <div id="OneYardLineTopHash"></div>
    <div id="TwoYardLineTopHash"></div>
    .
    . // Truncated for brevity
    .
    <div id="TwentyYardLineBottomMark">&lt20</div>

CSS:

#GoalBox{float: left; width: 300px; height: 500px; background-color: green;}
.TopHashes div{width: 30px; height: 30px; border-right: 1px solid black; position: absolute;}
#OneYardLineTopHash{left: 300px;}
#TwoYardLineTopHash{left: 330px;}
.
. // CSS properties continue similarly for other elements
.
#TwentyYardLineBottomMark{left: 875px; top: 400px; color: black; position: absolute; font-size: 24px;}

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

In a jQuery conditional statement, selecting the second child of the li element for targeting

I'm encountering an issue where I can't target the second child of an li element and use it in a conditional statement. Are jQuery conditionals not compatible with li:nth-child(2)? if($(".steps ul li:first-child").attr('aria-selected') ...

tips for rotating a bootstrap background image

I would like to know if it is possible to flip the background image of a section that contains both a navbar and a row in Bootstrap 5. I am aware of using <<transform: scaleX(-1)>> but this flips all the container elements. Is there a way to ac ...

When receiving a parameter in Javascript, one common issue is that the

So far, I have attempted to use both 'cv' and "cv" in the code, but it still returns as undefined. Using HTML (Laravel Blade) <button class="btn btn-danger" onclick="deleteType({{$cv->id,"cv"}})"> ...

`Incorporating width and vertical alignment in an image`

I am trying to figure out a way to make the image fill up 100% of the width, aligning it vertically with the text below. The code I'm working on is for email newsletters using foundation. Check out my Example Site Unfortunately, I can't seem to ...

Outlook fails to recognize table cell widths when there is an image present

Although this question has been asked previously, the solutions provided did not solve my issue. I am trying to set the width of the <td> element to 70%, but when I insert an image it is affecting the widths of received emails in Outlook (I use MS O ...

Adjust the CSS content using the data-content attribute to include line breaks

My current coding setup includes: <div id="mydiv" data-content="Loading..."></div> This is how I style it with CSS: #mydiv:after{ content: attr(data-content); height: 100%; opacity: 1; position: absolute; text-align: center; ...

Having a challenge with aligning a form in a view, as neither bootstrap nor plain CSS seem to be helping with centering it correctly

What techniques can I use to center this form properly in both bootstrap and plain CSS? So far, I have been able to center some parts of it, but when I try to center others, they shrink and create a mess. When I use bootstrap to center the elements, they b ...

What is the process by which photoswipe applies styles to blur an image upon clicking the share button?

If you want to see an example, check out this link: http://codepen.io/dimsemenov/pen/gbadPv By clicking on the Share button, you'll notice that it blurs the image (and everything else). Despite inspecting it closely, I still can't seem to figu ...

Eclipse now features automatic CSS class suggestions to help streamline your coding

After using NetBeans for a while, I am now considering making the switch to Eclipse. Everything seems fine, but one thing that is bothering me is that Eclipse does not provide CSS class proposals like NetBeans does. In NetBeans, whenever I use or create a ...

Transforming the initial character of a label element into uppercase

When I receive an external HTML page, all the data comes in lowercase. I attempted to capitalize the first letter of each label tag using CSS, but it ended up making the entire text uppercase instead. Here is what I tried: .fontmodal { text-transform ...

Unlocking the res property in index.js from an HTML script tag: A step-by-step guide

Can anyone help me with the access variable issue I am facing? I have two files, index.js and page.ejs. These files require me to create a timer linked with datetimes stored on my local server. //index.js.. router.get('/mieiNoleggi', functio ...

The intricate procedure behind applying a blur effect using CSS3 filters

MDN documentation explains that the filter blur function applies a Gaussian blur to the input image. After comparing it with OpenCV's GaussianBlur, I noticed that their effects are not identical. I am looking to achieve a similar effect using CSS3&ap ...

ng-bind-html is having trouble parsing the HTML correctly and binding it

Here is the code for my controller: myApp.controller('actionEditController', ['$scope', '$stateParams', '$sce',function ($scope, $stateParams, $sce) { $scope.table="<p>OOPSY</p>"; $sc ...

Linking multiple font files of the identical typeface to their respective CSS styles

I recently purchased the Didot font from myfonts.com, which includes different styles such as regular, bold, italics, and bold italics (each in separate files). While using WordPress, I noticed that when my users write articles with bold and italic text, ...

Customize cursor using CSS

I have a div with overflow: hidden that I am making scrollable by allowing the user to click and drag the background. There are links and buttons within this space. Here is the CSS I am using for this: #div-grabscroll { cursor: url(../img/op ...

Using jQuery in Rails 3 to display the id of a td element

I am working with a 3x3 table that contains td elements with unique id's (id='a1'...id='c3'). I want to enable the user to click on any of these 9 td elements and receive an alert displaying the id of the clicked td. Below is my C ...

Tips for eliminating the white flash while transitioning background images with animation?

I am facing an issue with my code where the background image of the site transitions between 5 different images, but every time an animation completes and the next one starts, there's a white flash. I'm not sure how to resolve it or what I might ...

The fading effects are not functioning as expected in the following code

Hey there, I'm not the most tech-savvy person, but I managed to come up with this code for page redirection. Unfortunately, I couldn't quite get the fade out and fade in effects to work properly when executing it. If anyone out there can help me ...

Connect the blade.php file with CSS in Laravel version 5.x

I placed my view.blade.php file in resources\views\admin\login\view.blade.php and used the following code to link it to the CSS file: <link href="{!! HTML::style('css/style.css') !!}" rel="stylesheet">. My CSS file is lo ...

creating an HTML table from JSON data using a specific key

In this json file, I am looking to create separate tables based on the IDs provided. For example, ID: "50" should be displayed in one table, while ID: "57" should be shown in another table within the same context. { "version": "5.2", "user_type": ...