3

I am using <hr /> element in my HTML. In Bootstrap.css file they applied some styles to <hr /> tags. I don't want to apply those styles to one of my <hr /> tag. How can I do that?

4
  • Can you show us the CSS and HTML? Commented Mar 5, 2014 at 8:03
  • 1
    Override the applied styles for that particular element. Commented Mar 5, 2014 at 8:03
  • You can customize your bootstrap... Commented Mar 5, 2014 at 8:06
  • But I need those styles for other hr elements, I just want to avoid it to perticular hr tag Commented Mar 5, 2014 at 8:06

10 Answers 10

3

Suppose you have an id to the div enclosing the hr

<div id="hrDiv">
   <hr>
</div>

To remove style you can use removeAttr property over the selector

$("#hrDiv hr").removeAttr("style");

If you are not using inline style then you need to override the propeties in css

#hrVid hr
{
//oveeride property
}

You can also put id to hr tag directly

Sign up to request clarification or add additional context in comments.

5 Comments

The style is applied via css from the stylesheet, not inline. The style attribute will be empty already.
Then you can override the css properties using selector #hrDiv hr
Without knowing more about OP's markup, why put the id on the parent div and not the hr?
You can also do that but i usually avoid it for good practice sake.
How is adding new markup better practice than applying a class to an element you actually want to style? It's just bloat that can break the structure of a page, I don't see any benefits.
1

Simply override the styles.

Say bootstrap applies:

hr{ border: 1px solid red; padding: 10px; }

In a stylesheet declared after bootstrap, override then like this:

hr{ border: none; padding: 0; }

Edited addition:

Based on the replies, if it's a particular HR tag (but not all), give the specific one a class:

<hr class="specialHr" />

And apply the style:

hr.specialHr{ border: none; padding: 0; }

1 Comment

But I need those styles for other hr elements, I just want to avoid it to perticular hr tag
1

You can set a class to your <hr/> and apply different styles to it. Or use the css :not() selector.

Comments

1

You can't do that.

You have to override every CSS property explicitly.

You can also modify your css file to create a class (instead of applying the style to all tags). However, you must explicitly declare this class in each <hr> tag where you want to apply the style (inverted your problem)

Comments

1

I would suggest you edit the Bootstrap CSS so that you need to add a class in order to get the BootStrap styling e.g. <hr class="hr">

hr.hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
    -moz-box-sizing: content-box;
    box-sizing: content-box;
    height: 0;
}

You can also create a class that specify the default styling to override Bootstrap. The default styling can differ from different browsers so I guess you need to decide which one to use. I took this from the user agent stylesheet in Chrome.

hr.hr {
    display: block;
    -webkit-margin-before: 0.5em;
    -webkit-margin-after: 0.5em;
    -webkit-margin-start: auto;
    -webkit-margin-end: auto;
    border-style: inset;
    border-width: 1px;
}

If you take that and make a CSS style rule specifying the same appearance you could mimic the default styling for that browser.

Comments

1

If this is something bigger than <hr> and you need to un-use many styles, you can put the contents in <iframe>.

Comments

0

at the end of your tag override with !important

example

<hr style="width:200px" !important>

this will overide with your changes

1 Comment

Inline css is defined in markup (rather than js that animates for example) is considered quite bad practice (since it breaks separation of concerns). !important can also be easily abused, and this isn't a case to use it. Check out css-tricks.com/when-using-important-is-the-right-choice
0

There are few approaches... Give this particular < hr /> a class (or id) and add your styles in your css:

 <hr class="myspecialhr" />
<style>     
 .myspecialhr {height:5px;}
</style>

You could also add you style overrides inline with the element:

 <hr style ="height:5px;"/>

You could "tag" this < hr /> with the class or id of a parent item of that particular page.

 <div class ="page1">
  <hr />
 </div>
 <style>
  .page1 hr {height:5px;}
 </style>

Finally, you could use CSS borders to achieve your layout goals and replace the


in your pages.

Comments

0

Just create an individual style for the <hr> tag.

So for example, to make the <hr> 500 pixels wide use:

<hr style="width:500px;" />

Comments

0

I think you can do this now:

hr {
  all: reset;
}

1 Comment

Best answer, and I guess you mean all: revert?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.