What is the process for modifying two IDs simultaneously?

I'm struggling to include more than one ID in my CSS. I want the box border to have four different hover effects and three gradient buttons (e.g., play, pictures, etc.).

Here is my HTML:

<h2><a id="hover-1" href="">Hover Effect 1</a></h2>
<h2><a id="hover-2" href="">Hover Effect 2</a></h2>
<a href="" id="play">Play</a><br/>
<a href="" id="picture">Picture</a><br/>

And here is the CSS:

<style>

/* Gradient*/
body {
  padding: 3em;
}
#play {
  color: blue;
  font: bold 3em/1.5 , sans-serif;
  text-decoration: none;
  text-transform: uppercase;
  -webkit-transition: .2s;
}
#play:hover {
  color: hotPink;
}
@media (-webkit-min-device-pixel-ratio:0) {
  #play {
    background-color: skyBlue;
    background-image: -webkit-linear-gradient(left, hotPink 0%, orange 50%, transparent 50%);
    background-position: 100% 0;
    background-size: 200% 200%;
    color: transparent;
    -webkit-transition: .1s .2s;
    -webkit-background-clip: text;
  }
  #play:hover {
    background-position: 0 0;
    color: transparent;
    transition: .4s 0;
  }
}

/*Box Border*/
html {
  box-sizing: border-box
}
*, *:before, *:after {
  box-sizing: border-box;
}

body {
  width: 80%;
  margin: 50px auto;
  color:black;
  font: 16px/1 'Catamaran', sans-serif;
  background: transparent;
}
body:after {
  content: '';
  display: flex;
  clear: both;
}


h2 {
  width: 50%;
  text-align: center;
  height: 44px;
  line-height: 24px;
  font-weight: 400;
  
}
@media screen and (max-width: 768px) {
  h2 {
    width: 100%;
  }
  h1 {
    margin-bottom: 15px;
    line-height: 30px;
  }
}

a, a > span {
  position: relative;
  color: inherit;
  text-decoration: none;
  line-height: 24px;
}
a:before, a:after, a > span:before, a > span:after {
  content: '';
  position: absolute;
  transition: transform .5s ease;
}

#hover-1 {
  padding: 10px;
}
#hover-1:before, #hover-1:after {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-style: solid;
  border-color: black;
}
#hover-1:before {
  border-width: 2px 0 2px 0;
  transform: scaleX(0);
}
#hover-1:after {
  border-width: 0 2px 0 2px;
  transform: scaleY(0);
}
#hover-1:hover:before, #hover-1:hover:after {
  transform: scale(1, 1);
}

</style>

I attempted to add both IDs to all of the CSS like this:

#play, #picture {
  color: blue;
  font: bold 3em/1.5 , sans-serif;
  text-decoration: none;
  text-transform: uppercase;
  -webkit-transition: .2s;
}

But that didn't work for some reason. If you can offer assistance, thank you! Feel free to reach out with any questions!

Answer №1

This particular issue arises from the following:

@media (-webkit-min-device-pixel-ratio:0) {
  #play {
    background-color: skyBlue;
    background-image: -webkit-linear-gradient(left, hotPink 0%, orange 50%, transparent 50%);
    background-position: 100% 0;
    background-size: 200% 200%;
    color: transparent;
    -webkit-transition: .1s .2s;
    -webkit-background-clip: text;
  }

The minimum ratio defined in

@media (-webkit-min-device-pixel-ratio:0)
is set at 0, ensuring that #play will always maintain this styling. You have the option to either incorporate #picture into this styling or eliminate it and add #picure to the following code block:

#play, #picture {
  color: blue;
  font: bold 3em/1.5 , sans-serif;
  text-decoration: none;
  text-transform: uppercase;
  -webkit-transition: .2s;
}

Complete CSS code snippet:

/* Gradient*/
body {
  padding: 3em;
}
#play, #picture {
  color: blue;
  font: bold 3em/1.5 , sans-serif;
  text-decoration: none;
  text-transform: uppercase;
  -webkit-transition: .2s;
}
#play:hover {
  color: hotPink;
}
@media (-webkit-min-device-pixel-ratio:0) {
  #play:hover {
    background-position: 0 0;
    color: transparent;
    transition: .4s 0;
  }
}
#picture:hover {
    background-position: 0 0;
    color: transparent;
    transition: .4s 0;
  }
}

/*Box Border*/
html {
  box-sizing: border-box
}
*, *:before, *:after {
  box-sizing: border-box;
}

body {
  width: 80%;
  margin: 50px auto;
  color:black;
  font: 16px/1 'Catamaran', sans-serif;
  background: transparent;
}
body:after {
  content: '';
  display: flex;
  clear: both;
}


h2 {
  width: 50%;
  text-align: center;
  height: 44px;
  line-height: 24px;
  font-weight: 400;
  
}
@media screen and (max-width: 768px) {
  h2 {
    width: 100%;
  }
  h1 {
    margin-bottom: 15px;
    line-height: 30px;
  }
}

a, a > span {
  position: relative;
  color: inherit;
  text-decoration: none;
  line-height: 24px;
}
a:before, a:after, a > span:before, a > span:after {
  content: '';
  position: absolute;
  transition: transform .5s ease;
}

#hover-1, #hover-2 {
  padding: 10px;
}
#hover-1:before, #hover-1:after {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-style: solid;
  border-color: black;
}
#hover-1:before {
  border-width: 2px 0 2px 0;
  transform: scaleX(0);
}
#hover-1:after {
  border-width: 0 2px 0 2px;
  transform: scaleY(0);
}
#hover-1:hover:before, #hover-1:hover:after {
  transform: scale(1, 1);
}
#hover-2:before, #hover-2:after {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-style: solid;
  border-color: black;
}
#hover-2:before {
  border-width: 2px 0 2px 0;
  transform: scaleX(0);
}
#hover-2:after {
  border-width: 0 2px 0 2px;
  transform: scaleY(0);
}
#hover-2:hover:before, #hover-2:hover:after {
  transform: scale(1, 1);
}

UPDATE: Adjusted CSS per the comment

Answer №2

Utilizing the selector syntax provided should function effectively, as demonstrated in this scenario:

#elem1, #elem2 {
  color: red;
}
<div>
  <p id="elem1">Element 1</p>
  <p id="elem2">Element 2</p>
</div>

However, keep in mind that the purpose of ids is to uniquely identify an element and its corresponding style. If you need to apply the same styles to multiple elements, it's advisable to utilize a class. You can still assign a unique id alongside a class, like this:

.text {
  color: red;
}

#elem1 {
  font-size: 18px;
}
#elem2 {
  font-size: 14px;
}
<div>
  <p class="text" id="elem1">Element 1</p>
  <p class="text" id="elem2">Element 2</p>
</div>

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

How can I turn off shadows for every component?

Is it feasible to deactivate shadows and elevation on all components using a configuration setting? ...

The act of selecting a parent element appears to trigger the selection of its child elements as well

I am attempting to create an accordion using Vanilla JavaScript, but I have encountered an issue. When there is a child div element inside the header of the accordion, it does not seem to work and I'm unsure why. However, if there is no child div elem ...

unassigned variables in a PHP email submission form

My PHP email form is not sending emails because my variables are coming up as null. I have an echo statement after my code to check if the variables have values, but they are not being printed. Only 'done' and 'email $to' are showing up ...

Utilizing :checked selector and toggle() function in jQuery

I'm facing an issue with my jQuery code where the CSS changes are not working as expected. When I test the code, it doesn't apply the CSS changes. If I remove the :checked and just use $("input"), then the CSS works but only when clicking on an i ...

How can I make a clickable button or link within an anchor tag that is still able to be right-clicked?

Hey there, I'm currently working on a notification dropdown menu where each <li> contains a link or an <a> tag. I'm aiming to create something similar to Facebook's notification system. However, the challenge lies in trying to ...

How can the onclick attribute be modified in an HTML document?

I am looking to update the data-pro-bar-percent attribute of a progress bar from 80 to 100 when a specific link is clicked. The change in attribute needs to be as follows: data-pro-bar-percent="80" --> data-pro-bar-percent="100" This is the current HTML ...

Hover over the Div element for inline effect

Hello all, I am currently working on running a while loop from a database to show different records. The twist is that these records are displayed as images, which makes it tricky to customize using standard CSS. To work around this, I'm implementing ...

How about determining the map size based on Divine proportions?

Is there a way to make the map at https://codepen.io/sinanelms/pen/MqdNNY responsive to screen size changes? I attempted the following code but was unable to achieve the desired outcome. <style type="text/css"> body{ background:#fff;} #map ...

Two separate tables displaying unique AJAX JSON response datasets

As a beginner in javascript, I am facing a challenge. I want to fetch JSON responses from 2 separate AJAX requests and create 2 different tables. Currently, I have successfully achieved this for one JSON response and table. In my HTML, I have the followi ...

Overruled fashion

Here is the HTML code from my custom page: <div class="notes quotes-notification member-savings f-left"> <h2>My Notifications</h2> <ul> <li><b>I need to make some changes in the HTML, different from other pages you have ...

The toggle feature of the Bootstrap responsive navbar is not functioning properly

I am currently implementing Twitter Bootstrap in a Rails project, but I'm encountering issues with the responsive navbar. When I resize the screen, the menu toggle button appears along with the navbar options open below it. Upon further shrinking, the ...

Picture not displaying properly in alternative browsers

While working on a simple website using html and css, I encountered an issue where my logo was not displaying for users on different browsers. Here is the image description Below is the HTML code: <section id="header"> <div class=& ...

Is it possible to combine ng-switch and ng-if directives in Angular?

I attempted to combine the angular ng-switch and ng-if directives, but it doesn't seem to be functioning properly. Here is what I tried: <div data-ng-if = "x === 'someValue'" data-ng-switch on = "booleanValue"> <div data-ng-swit ...

Interactive Material Icons with Hover Effects in CSS

I'm having trouble adding a hover effect to material icons in my code. Despite everything else looking good, the hover effect is not working as expected. Below is the code snippet I've been using: import ManageAccountsIcon from '@mui/icons-m ...

Removing HTML tags from a string while preserving specific tags in JavaScript

Here is a JavaScript string that I am working with: var test = "<p>test</p> FOLER.PRODUCTS<12345><level-2>"; I'm trying to remove the HTML tags from the string because the service I'm using doesn't accept them. Here ...

Explore bar with search button

I'm facing an issue with the code I have for searching on my website. Currently, when a user fills in their search word and presses enter, it executes the command. However, I would like to only run the search script when the user clicks a button inste ...

What is the best way to add a `<div>` before or after a specific `<p>` element based on the client's height?

I am facing an issue with inserting a div before a paragraph element based on the given clientHeight. Specifically, I need to locate the closest paragraph element from the specified clientHeight and then add a div before or after that particular element. ...

Unable to output the string using htmlspecialchars

Oops! I made a mistake... just came across a JavaScript alert box! I just included htmlspecialchars. $src = './imgs/flag.jpg'; echo sprintf("<img alt=\"'.htmlspecialchars($name).'\" src=\"%s\" />", $src); I ...

Adjusting the array when items in the multi-select dropdown are changed (selected or unselected)

I am looking to create a multi-select dropdown in Angular where the selected values are displayed as chip tags. Users should be able to unselect a value by clicking on the 'X' sign next to the chip tag, removing it from the selection. <searcha ...

Extending the href value using jQuery at the end

Can someone help me with this link: <a id="Link" href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2745425453424b4b524940674e0a4355464e4909494253">[email protected]</a>?subject=I-Drain Bestellung& ...