Struggling to choose an element by ID and classname?

Currently, I'm diving into the world of HTML and CSS and have encountered a question about selecting elements in CSS. I understand that we use .Classname{} to select a class and #IDname{} to select an ID. But my main confusion lies in trying to select items like #ID.Class{}. Below is an example of what I mean. Can someone please help me out?

HTML CODE 
<!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.0" />
    <title>Anime Website Design</title>
    <link rel="stylesheet" href="/style.css" />
</head>

<body>
    <!-- Name Section -->
    <section id="name">
        <div class="name container">
            <div>
                <h1 class="Heading">Hello ,Sumit is here ! </h1>
                <a href="#" type="button" class="cta">Portfolio</a>
            </div>
        </div>
    </section>
</body>
CSS CODE :-
.cta{                     //Works Fine
  font-family:'Neucha',cursive;
  display: inline-block;
  text-decoration:none;
  padding: 1px 10px;
  color: white;
  border: 2px solid crimson;
  border-radius: 7px;
  font-size:22px;
  background-color: transparent;
  margin-top:3px;
  transition: ease .5s background-color;

  text-transform: uppercase;
}

I've tried using #name.cta in my CSS code but it shows an error. However, I've seen it being used effectively in online tutorials. Does anyone know why I can't select it this way? Maybe I'm missing something obvious, so apologies if I sound silly.

#name.cta{             //THIS SHOWS ERROR(NOT ABLE TO GET OUTPUT)
      font-family:'Neucha',cursive;
      display: inline-block;
      text-decoration:none;
      padding: 1px 10px;
      color: white;
      border: 2px solid crimson;
      border-radius: 7px;
      font-size:22px;
      background-color: transparent;
      margin-top:3px;
      transition: ease .5s background-color;
    
      text-transform: uppercase;
    }

Answer №1

.cta #name   

Ensure there is a space between #name and the comma.

Answer №2

Despite not being the recommended approach due to its complexity, it is still achievable. #name .container div .cta{}

Answer №3

Make sure there is space betwwen #name and .cta Give this code a try:

#name .cta{   
  font-family:'Neucha',cursive;
  display: inline-block;
  text-decoration:none;
  padding: 1px 10px;
  color: #000;
  border: 2px solid crimson;
  border-radius: 7px;
  font-size:22px;
  background-color: transparent;
  margin-top:3px;
  transition: ease .5s background-color;
  text-transform: uppercase;
}
<!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.0" />
    <title>Anime Website Design</title>
</head>

<body>
    <!-- Name Section -->
    <section id="name">
        <div class="name container">
            <div>
                <h1 class="Heading">Hello ,Sumit is here ! </h1>
                <a href="#" type="button" class="cta">Portfolio</a>
            </div>
        </div>
    </section>
</body>
</html>

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

What is the best way to include CSS in a CodeIgniter project?

I am facing an issue with loading a CSS file in Codeigniter. It seems like there might be something wrong with my code. Can someone help me understand how to properly load a CSS file in Codeigniter and possibly identify any errors in my current code? < ...

Receiving the result as well as encountering undefined initially during AJAX request

I have a dropdown menu, and when a user selects an option, an AJAX call is made to retrieve and display data based on the selected value. If the dropdown value is 2, it triggers the AJAX request. However, I am encountering two issues: https://i.sstatic.n ...

The Bootstrap Grid Leaves Blank Spaces Unfilled

View the screenshot here Take a look at the image above. I'm struggling to fill the empty space with div elements. I've experimented with display:inline-block and other display properties, but they haven't yielded the desired results. < ...

The feature to swap out the thumb of a range slider with an image is currently not

I'm attempting to design a unique range slider using CSS. <style> .slide-container { width: 300px; } .slider { -webkit-appearance: none; width: 100%; height: 5px; border-radius: 5px; background: #FFFFFF; outline: none; opacity: ...

Issue with sticky navbar in parallax design

I have been working on a website where all pages feature a header and a navbar located just below it. As the user scrolls down the page, I want the navbar to stick to the top of the screen once it reaches that position. However, on one specific page, I am ...

Utilize Angular2's input type number without the option for decimal values

Is there a way to prevent decimals from being entered in number inputs for Angular 2? Instead of using patterns or constraints that only invalidate the field but still allow typing, what is the proper approach? Would manually checking keystrokes with the ...

Attempting to achieve a shadowy overlay effect on my Bootstrap Carousel media

I've been attempting to add a dark overlay to an image or video on my bootstrap 5 website, but every time I do so, it ends up covering the text as well. Here is my current code: .drk:after { content: ""; display: block; position: absolute; ...

Use .empty() method to remove all contents from the tbody element after creating a table

Currently, I am working on a project where I am creating a drop-down list to assist users in selecting media and ink for their printers. The goal is to then generate a table displaying the selected results. While I have managed to successfully generate the ...

Avoid unnecessary borders in the unordered list navigation bar

After countless hours of troubleshooting, I am still unable to pinpoint the source of the border on the horizontal menu items in my website, which is built on WordPress using a child theme called Required+ (based on Zurb's Foundation). I have tried se ...

Guide to inserting a glyphicon within a bootstrap badge

I've been working on a unique way to display hierarchical data using bootstrap badges and AngularJS. My goal is to create a user-friendly experience where people can easily navigate through categories. There are 3 main types of categories: parent: T ...

Is it possible to retrieve elements by their ID when the ID values are constantly changing?

I'm facing an issue with accessing dynamic IDs using `getElementById`. I require this value to perform random calculations involving different elements. MY CODE <div class="col-lg-4" v-for="data in datas"> <button class="btn btn-outline-d ...

Organize the attributes of components on the following line in Visual Studio Code

Is there a method to configure the VS code formatter for Angular 2+ templates to ensure that attributes are wrapped in a new line? I prefer this formatting: <app [input1]="input1$ | async" [input2]="input2$ | async" (inputChanged)="set ...

The rows sent to HTML/Bootstrap from Java through JSON do not neatly wrap across rows evenly

I am having trouble getting images to wrap evenly on an HTML/Bootstrap page that are retrieved by Java and passed through JSON. Despite my expectations, there is a third row created with only one image and a fifth row with 3 extra images. Additionally, whe ...

CSS Grid expands the item width on its own when there is still space left

Having some queries regarding the piece of code provided. Currently, I have a collection of 5 cards displayed in rows of 3 cards each using the styling grid-template-columns: repeat(3, minmax(200px, 1fr));. My concern is whether there is a way for the 4th ...

Tips for utilizing divs and spans in HTML5

When it comes to web development, HTML markup is utilized for structuring content, while CSS is used for styling and presenting that content. In the past, HTML elements like <div> were often assigned semantic meaning through the use of IDs and class ...

jQuery swap- enhancing the appearance of numerical values

I am looking to customize specific characters within my <code> tag. While searching online, I came across the .replace() function but encountered issues when trying to style numbers. My goal is to change their appearance without altering the text its ...

Stop phonegap from altering the default orientation on the device

As a newcomer to phonegap, I am seeking a reliable and straightforward way to determine whether a device is a tablet or a phone. My current method involves comparing the width and height sizes of the screen - if the width is greater, then it is a tablet; o ...

Tips for avoiding the display of the overall scrollbar while utilizing grid with an overflow:

In my react-redux application, I am utilizing the material ui Grid component for layout design. The structure of my code is as follows: <div> <Grid container direction="row" spacing={1}> <Grid item xs={3}> ...

jQuery method for implementing alternating row colors that are not sequential

Starting from scratch here. I've fetched a table from a remote server where odd rows are white and even rows are grey. Some rows have been hidden: $("td").filter(function(){ return $(this).text()=='R1';}).text('Row1'); //white $(" ...

Retrieve the ID of the image element using Jquery from a collection of images within a div container

I'm encountering a simple issue that I can't seem to solve. I am working on a basic slider/gallery with the following functionalities: 1) "If button 1 is clicked, image one will appear." 2) "Clicking on button 2 will make IMAGE 1 slide left and I ...