Class selector in CSS

Asked

Viewed 129 times

2

I’m having trouble referencing a <div>, which is in my index.html file, through my . css file.

I have the following structure in my index.html file:

<!-- Content -->
<div class="container">
    <div class="row">
        <div class="div-address">
            <h3>Endereço 1</h3>
            <p>Endereço 1</p>
        </div>
    </div>
</div>

I’m trying to make a reference to <div class=""div-address>, however, the adjustments I am making to the . css file are not being applied to this div.

The reference in my . css file is given by:

.div-address{
  border: 1px solid;
  font-family: 'Boogaloo', cursive;
}

This structure is implemented just below the structure defined in the .css. I did this thinking that my style could override some existing style in the CSS structure of Bootstrap.

NOTE:

  1. I’m using the Bootstrap framework
  2. The file structure is correct (index.html, css folder, js folder etc.)
  3. In the first line of my . css file I am importing the font used for div (@import url("https://fonts.googleapis.com/css?family=Boogaloo|Yesteryear");)

When I put the ". div-address" style in my index.html file, the style is implemented correctly in the div. I must be making a mistake when referring to classes in CSS or something is overwriting my created style in the . css file.

Well, I’m still new to web development and I ask for your help in solving this problem.

Thank you.

  • 2

    You’re including that file .css on page with <link rel="stylesheet" type="text/css" href="etc...?

  • Hello @Sergio, I am "<link href="css/bootstrap.css" rel="stylesheet">". My file structure is correct. I say this because I was able to implement some adjustments through the . css file.

  • Ok, so are you changing the boostrap file directly/manually? is it static or is it compiled? type of Less for css or Stylus for css?

  • Hello @Samir, I am implementing my style after all styles defined in the . css file.

  • @Samirbraga , what references? Could you be more specific? I’m still new to this subject.

  • Would be my tag head? If it is, it follows: <link href="css/bootstrap.css" rel="stylesheet"> &#xA;<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

  • <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"> </script>&#xA; <script src="js/bootstrap.min.js"></script>

Show 2 more comments

1 answer

1


I think the best would be to put all your styles that are not part of Bootstrap in a different file, and lynch it after all the links css. Just as:

<link href="css/bootstrap.css" rel="stylesheet"> 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.‌​7.0/css/font-awesome‌​.min.css"    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jque‌​ry.min.js"></script> 
<script src="js/bootstrap.min.js"></script>

<!-- Aqui vem seu estilo -->
<link href="css/meu-arquivo-de-estilo.css" rel="stylesheet"> 
  • I got it, I didn’t know I could do it. I believe it should work. I’ll try here and I’ll answer. Thank you!

  • It worked @Samir, thank you very much! I would just like to know if this is good practice? I lose out if I implement this structure with more than one CSS file? I noticed that my personal file inherited from the Bootstrap css file. I believe it’s because it was declared after the bootstrap css link. Thanks again!

  • @Hudsonrodrigues, this depends on some things, the size of the file, how the rules are superimposed, etc. I suggest you research on front-end performance, it’s a very interesting and useful subject :).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.