When it comes to styling a specific element, using CSS classes is not effective

I am having some trouble styling a form with CSS. I want to apply specific formatting to the form without affecting other parts of my website. Specifically, I need to add spacing between input fields, labels, and buttons within the form. I suspect that one of the 20 CSS files in my project is overriding my styles. Is there a way to override these conflicting styles and apply them specifically to the "box-body" class?

<!-- To Do List -->
        <div class="col-lg-6">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">To Do List</h3>
                    <div class="box-tools pull-right">
                        <button type="button" class="btn btn-box-tool" data-
                        widget="collapse"><i class="fa fa-minus"></i>
                        </button>
                        <button type="button" class="btn btn-box-tool" data-
                        widget="remove"><i class="fa fa-times"></i></button>
                    </div>
                </div>

                <div class="box-body">

            <!-- <link href='https://fonts.googleapis.com/css? 
               family=Lato:300,400,700' rel='stylesheet' type='text/css'> ->

            <p>
                <label for="new-task">Add Item</label><input id="new-task"
            type="text"><button>Add</button>
            </p>

            <h3>To Do</h3>
            <ul id="incomplete-tasks">
                <li><input type="checkbox"><label>Pay Bills</label><input
                type="text"><button class="edit">Edit</button><button
                class="delete">Delete</button></li>
                <li class="editMode"><input type="checkbox"><label>Go
                  Shopping</label><input type="text" value="Go Shopping">
                  <button class="edit">Edit</button><button
                   class="delete">Delete</button></li>

               </ul>

                <h3>Completed</h3>
                <ul id="completed-tasks">
                <li><input type="checkbox" checked><label>See the
                Doctor</label><input type="text"><button
               class="edit">Edit</button>
            <button class="delete">Delete</button></li>
            </ul>

            <script type="text/javascript" src="app.js"></script>
            <script  src="js/index.js"></script>
        </div>
        </div>

    </div>
    <!-- /.container-fluid -->



     </section>
      <!-- /.content -->
         </div>
            <!-- /.content-wrapper -->

Current layout: current view

Desired layout for box body: desired view

 /* Styling for To Do List */

.containerToDo {
display: block;
width: 400px;
margin: 100px auto 0;
}

.box-body {
background: #fff;
color: #333;
font-family: Lato, sans-serif;
}

ul {
margin: 0;
padding: 0;
}

li * {
float: left;
}

li, h3 {
clear:both;
list-style:none;
}

input, button {
outline: none;
}

button {
background: none;
border: 0px;
color: #888;
font-size: 15px;
width: 60px;
margin: 10px 0 0;
font-family: Lato, sans-serif;
cursor: pointer;
}

button:hover {
color: #333;
}

/* Heading */

h3,
label[for='new-task'] {
color: #333;
font-weight: 700;
font-size: 15px;
border-bottom: 2px solid #333;
padding: 30px 0 10px;
margin: 10px;
text-transform: uppercase;
}

input[type="text"] {
margin: 0;
font-size: 18px;
line-height: 18px;
height: 18px;
padding: 10px;
border: 1px solid #ddd;
background: #fff;
border-radius: 6px;
font-family: Lato, sans-serif;
color: #888;
}

input[type="text"]:focus {
color: #333;
}

/* New Task */

label[for='new-task'] {
display: block;
margin: 0 0 20px;
}

input#new-task {
float: left;
 width: 318px;
}

p > button:hover {
color: #0FC57C;
}

/* Task list */

li {
overflow: hidden;
padding: 20px 0;
border-bottom: 1px solid #eee;
}

li > input[type="checkbox"] {
margin: 0 10px;
position: relative;
top: 15px;
}

li > label {
font-size: 18px;
line-height: 40px;
width: 237px;
padding: 0 0 0 11px;
}

li >  input[type="text"] {
width: 226px;
}

li > .delete:hover {
color: #CF2323;
}

/* Completed */

#completed-tasks label {
text-decoration: line-through;
color: #888;
}

/* Edit Task */
ul li input[type=text] {
display:none;
}

ul li.editMode input[type=text] {
display:block;
}

ul li.editMode label {
display:none;
}

.input#new-task{
margin-left: 20px;
padding:20px;

Answer №1

Start every CSS selector with .box-body, such as .box-body button.

Answer №2

If you want to customize a .box-body div with specific styles, you can follow these steps:

<style>

.box-body {
background: #fff;
color: #333;
font-family: Lato, sans-serif;
}

</style>

<div class="box-body">

            <link href='https://fonts.googleapis.com/css? 
               family=Lato:300,400,700' rel='stylesheet' type='text/css'> ->

            <p>
                <label for="new-task">Add Item</label><input id="new-task" 
            type="text"><button>Add</button>
            </p>

            <script type="text/javascript" src="app.js"></script>
            <script  src="js/index.js"></script>

</div>

To apply the customized box-body styles, create a separate HTML file named box-body.html. Then on the main page, remove the .box-body div and add this code instead:

<div id="box-body"></div>

Finally, before the closing </body> tag in your main code, include the following script:

<script>
      $('#box-body').load('./box-body.html');
</script>

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

Tips for perfectly centering text within p tags using CSS

Currently, I am troubleshooting the JSFiddle where my goal is to vertically center text using CSS. Below is the HTML code that I utilized to create the JSFiddle: <div class="poster text-center pt-4"> <div class="item"> <img class=" ...

The HTML modal window is experiencing loading issues

I am attempting to implement a modal box that appears on click in an HTML document. The HTML code looks like this: <a href="#openModal">Open Modal</a> <div id="openModal" class="modalDialog"> </div> <a href="#openModal">O ...

Creating a visually striking layout with Bootstrap card columns masonry effect by seamlessly adjusting card heights to prevent any

When using the bootstrap card columns masonry and a user clicks on a button inside a card, the height of the card changes dynamically by adding a card-footer. However, in certain situations, the cards change position causing a jumpy effect. To see this i ...

What is the solution to resolving a JavaScript error involving the insertBefore() method?

<body> <div class="container mt-4"> <h1 class="display-4 text-center"> <i class="fas fa-car text-success"></i> My<span class="text-success ">Car</span>List</h1> <form id="ca ...

Side Panel Extending Off Screen Upon Resizing

I'm encountering an issue with the sidebar on my HTML page. The problem arises when I click the 'Upload Data' button, causing the sidebar's header to extend beyond the screen if I resize the window. The only way to fix this is by refres ...

Utilizing Python's urllib and urllib2 to automatically populate web forms

My goal is to automatically submit an HTML form using both urllib2 and urllib. import urllib import urllib2 url = 'site.com/registration.php' values = {'password' : 'password', 'username': 'username& ...

Unexpected token error in jQuery caused by margin-left issue

While working on editing CSS values of some elements using jQuery, I encountered an issue when trying to change the margin-left value of an element. This resulted in an "Unexpected token" error due to the "-" in margin-left. Is there a way to adjust margin ...

What is the best way to superimpose a new div on the entire body of an HTML document using J

I am currently experiencing a similar issue to the one mentioned here.. When making an Ajax request, I am attempting to set a background image of a loading icon with a greyed-out background, but for some reason the greyed background does not extend to the ...

Enhancing the appearance of ng2-select2 in Angular2 with custom CSS styling

In my Angular2 project, I'm utilizing ng2-select2 and I am looking to customize the style by adjusting properties such as width, height, border-radius, font-weight, font-size, ... Unfortunately, I have been unable to achieve this. This is what my Htm ...

IE9 crashes when displaying elements with float:left style

After clicking the "off" and then "on" hyperlink in the provided HTML snippet, IE9 crashes. Here is the simplified version of the code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD& ...

Arranging text and images strategically

I am trying to position an image and text within separate containers using div. The desired layout is to have the img floated left and the text centered on the page, but I am having trouble achieving this. Each element has its own div. Can you provide as ...

Guidelines for creating a glowing effect with font-awesome using CSS

Recently, I utilized font-awesome with the following code: <i class="fa fa-circle-o text-red"></i> Instead of a circle with a red outline, I would like it to be a solid red circle that blinks. I'm not well-versed in front-end developmen ...

Connect ngx-time picker to form input in Angular

Currently, I have successfully implemented Angular material date pickers in my project, however, I am facing a challenge with integrating time pickers as it is not natively supported by Angular Material for version 8. To address this issue, I am utilizing ...

Adjust the window size when the keyboard appears on a mobile device

I am currently working on creating a mobile version of the website. Following the responsive design principles, the block sizes are set in percentages. html, body{ width: 100%; height: 100% } One issue I encountered is that when an input box is foc ...

How can I use jQuery to show the text value of a selected checkbox, dropdown menu, and flipswitch in a popup?

This form's HTML is set up for input with a popup display feature upon submission. Currently, only text can be displayed in the popup. It doesn't show the text of selected checkboxes or dropdown lists - just numbers for the dropdown and "ON" for ...

How to center a div both vertically and horizontally within a flex-fill using Bootstrap 4

Hello there! I am currently using Bootstrap 4 and the layout I have implemented seems to be working fine as all my pages start from the top. However, now I am trying to center the elements. <style> body, wrapper { min-height: 100vh; ...

Tips for detecting HTML updates using Python requests

My goal is to monitor a page for updates while maintaining the same session and cookies, without sending a completely new request. How can I determine if there are HTML updates within my current request? The page will redirect but keep the same URL. This ...

struggling to align the div elements

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Cougar Inn Directions</title> <link rel="stylesheet" type="text/css" href="case.css" /> <link rel="stylesheet" href="http://code.jquer ...

Show/Hide Section

I am struggling to implement two buttons - one for expanding a div and one for collapsing it. Despite multiple attempts to modify the code, I have not been successful. It appears that I am having trouble understanding how to prevent a link from toggling. ...

Eliminating the appearance of horizontal scroll bar by employing transform scale to zoom out

When you run the code provided in the link below and scale down the HTML to 50% while increasing the width to fit the window, a scrollbar becomes visible. This only occurs in Chrome and not in Firefox. Click here The content of the DOM can be modified and ...