Eliminate the left margin in Bootstrap while applying filters

Utilizing Bootstrap 2.3.1, I have designed a layout as follows:

<div class="row-fluid">
    <div class="span3">text1</div>
    <div class="span3">text2</div>
    <div class="span3">text3</div>
    <div class="span3">text4</div>
</div>

When filtering to display only the div containing text2, I hide the other divs by setting their display property to none. However, because the div with text1 is still the first child, the div containing text2 inherits a left margin. How can I modify this so that it solely applies margin-left: 0; to the first child with display block?

The filtered view appears like this:

<div class="row-fluid">
    <div class="span3" style="display: none;">text1</div>
    <div class="span3">text2</div>
    <div class="span3" style="display: none;">text3</div>
    <div class="span3" style="display: none;">text4</div>
</div>

The first-child margin was eliminated by the following CSS from bootstrap:

.row-fluid [class*="span"]:first-child {
    margin-left: 0;
}

I believe the correct approach should be something similar to this (albeit with the proper syntax):

.row-fluid [class*="span"]:first-child[display="block"] {
    margin-left: 0;
}

Answer №1

Check out this unique selector (demo):

.row-fluid [class^="span"]:not([style="display: none;"]) {
    margin-left: 0;
}

However, since it's currently not possible to select first-of-class, this rule will apply to all matched elements. I recommend switching Bootstrap classes (.spanX) when displaying/hiding elements.

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

Thymeleaf Checkbox not appearing correctly

Within my Thymeleaf templates with Bootstrap, I have successfully implemented a checkbox. Below is the code snippet used to incorporate the checkbox into the HTML templates: <td> <input type="checkbox" name="products&qu ...

CSS hover effect applied uniformly to all link children

Here is the HTML code snippet I am working with: <a href="">Bioshock 2<span> - Xbox 360 review</span></a> My goal is to style the first part of the link differently from the span. The desired styling should look like this: https: ...

Creating a counter for a list using CSS

I am attempting to utilize the counter increment feature in CSS for my ordered list, but it doesn't seem to be functioning properly. Here is the desired format I want to achieve: 1. Acknowledgements 1.1 blah, blah .... 1.2 blah, blah .... 1 ...

Select a date within the Bootstrap datetimepicker input

I implemented the datetimepicker widget from [insert link to the actual website here]. However, I encountered an issue as there was no clear guidance on how to use certain functions such as date, show, hide, etc. This made it challenging for me to set the ...

Bootstrap 4 cards continue to resize instead of adapting to the constraints of the designated space

I've been attempting to implement functionality with bootstrap 4 cards, but I'm running into issues where the card size expands based on the length of the text. Below is my code: <div class="row row-container"> <div class=& ...

Floating text around an image inside a div with floated IE7

Struggling with positioning text around an image in IE7, it's not floating correctly as expected. The text appears below the image instead of beside it. After researching, I discovered that the issue might be related to placing both the image and tex ...

Format for entering phone numbers

Currently working with Angular and seeking an input field that can display the text format 614-123-1234. I've been exploring options, including a jQuery solution, but unfortunately cannot integrate it into my project. This is how my current input fie ...

My code operates successfully only on the initial execution

I am encountering an issue with my function regarding a login form validation using JSON data. The code seems to be working correctly, but only when I input the correct data immediately after refreshing the page. For example, if I enter an incorrect login/ ...

Move your cursor over X or Y to alter the color of Y exclusively

I am currently designing a navigation bar that includes icons followed by the title of their respective pages (for example, an icon of a home followed by the text 'Home'). I would like to change the color of only(!) the icon from black (default) ...

Ways to alter the color of individual pseudo elements using a CSS loop

While working on creating a typewriter animation effect for my website using only CSS that I discovered through some online research, a question popped into my mind - is it possible to set different colors for each text in the animation? I have included t ...

Begin the ul element from the left-hand side

Check out my latest JSFiddle creation: http://jsfiddle.net/alonshmiel/Ht6Ym/2409/ I'm attempting to align the ul element on the left side of the page: I've experimented with the following CSS rules: margin-left:0px; float: left; Unfortunatel ...

I experienced issues with the brackets software freezing up while using the Bootstrap min CSS file

Recently, I've been using brackets as my text editor and have run into an issue with the bootstrap.min CSS file. For some reason, it keeps freezing whenever I try to load it in brackets. Oddly enough, HTML files work perfectly fine, but ...

Is there a way to use jQuery to centrally align the accordion item that I have chosen?

My attempts to use `this.scrollIntoView({behavior: "smooth"}) were yielding inconsistent results in terms of where the selected item would land on the page. I believe I might need to utilize scrollTop(), but as someone who is new to jQuery, I am ...

Am I using the if statement correctly?

Can someone confirm if I am using the if statement correctly in this script? Or is it not possible to use an if statement within this code? <script type="text/javascript" charset="utf-8"> $(document).ready(function () { $('#customerTable&ap ...

Best practice for showcasing an MVC Form with the use of Bootstrap

I am facing an issue with my form layout while trying to capture user input. The use of Bootstrap is creating two columns for text boxes and their labels, but the alignment goes off track with the last EditorFor element. I'm questioning if I am misusi ...

Navigating through parent folder HTML files from child folder HTML files

Seeking guidance as I embark on a new project! Check out this link to see my skills in action: collegewebsite.zip Now for the query at hand. I am working on a project named Coffee Cafe for my tuition assignment. It involves utilizing CSS and HTML with J ...

Tips on how to align a wrapper-div in the center without affecting the positioning of the

I am looking to keep my page perfectly centered in the browser without affecting the content (similar to how align-text: center works). Specifically, I want to center my wrapper-div. How can I achieve this? Here is a simplified version of my current page ...

What is a simple way to hide the menu when the user clicks anywhere on the screen?

I've encountered an issue with my code that involves the following functionalities: 1: When a user clicks a button, it toggles the drop-down menu on or off. 2: Clicking anywhere within the webslides element should close the menu if it's displayed ...

How can I use Chart.js to assign a unique color to each x-axis label?

I'm currently using Chart Js to create a chart and I want each label to have a different color instead of all labels having the same color. Is there a way to achieve this using the ticks callback function? scales: { xAxes: [{ ...

Tips for dynamically adjusting the width of an included .html file

After designing the home page as a separate index.html file, I have multiple other pages that perform certain operations but lack a UI design. To address this, I decided to include the index.html file on all these pages. However, I encountered an issue whe ...