Modifying bootstrap column based on a specific condition

Is it possible to adjust bootstrap columns based on the outcome of a certain expression?

My attempted solution:

<div class="@Installation.Fleet.Type.Equals("Vessel") ? col-lg-9 col-md-9 col-sm-12 : col-lg-12 col-md-12 col-sm-12">

</div>

Unfortunately, even when @Installation.Fleet.Type.Equals("Vessel") returns true, the program consistently displays "col-lg-12 col-md-12 col-sm-12".

Appreciate any help in advance!

Answer №1

When returning your classes as a string, it is recommended to use the @() format for ternary operators in Razor views like this:

<div class="@(Installation.Fleet.Type.Equals("Vessel") ? "col-lg-9 col-md-9 col-sm-12" : "col-lg-12 col-md-12 col-sm-12")"></div>

Answer №2

You have the option to create a variable called classes:

@{

var <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfbcb3beacacbaace29f96afb8aa9099b3babaa1fdbeb2">[email protected]</a>("Vessel") ? "col-lg-9 col-md-9 col-sm-12" : "col-lg-12 col-md-12 col-sm-12";

}

and then:

<div class="@classes">

</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

Showcasing images that vary between mobile and desktop views using Bootstrap 4

I have a website where I display 6 columns of images in a row using Bootstrap 4. However, I want to adjust the layout so that when viewed on mobile devices with a smaller screen width, the images are displayed in rows of 4 or 3 columns instead. <link ...

Center div encroaching on floated left div

https://i.sstatic.net/uwyGY.pngCan someone help me align three divs horizontally? I'm having an issue where the center div is overlapping the left div. What could be causing this problem? <div> <div style={{width:"100px", ...

Ways to convert and download multiple iframes as PDF files

I have a webpage that displays content from five different pages using iframes. I am looking to convert the combined content of these iframes into a PDF after the entire page has finished loading. How can I achieve this? <iframe class="page-inner ...

How can I attach a cookie to a div that becomes visible after a few seconds of video playback?

After 20 seconds of video play, a div element appears. I am trying to set up a cookie so that once the div is shown, it continues to appear unless the user clears their cache (cookie logic). This is my current attempt - http://jsfiddle.net/9L29o365/ Any ...

Utilizing the CSS REM unit to define element dimensions

I recently discovered the versatility of using the REM unit for sizing elements, not just font sizes. It works really well in conjunction with the HTML font-size property. html { font-size:1vw } @media all and (max-width:720px) { html { font-size:10px ...

Create a geometric shape with JavaScript by utilizing the CSS clip-path property

The code snippet above achieves the desired effect. #overlay { background-color: rgba(0, 0, 0, 0.66); position: absolute; z-index: 1; top: 0; left: 0; width: 100%; height: 100%; clip-path: polygon( 0% 0%, /*exterior top left*/ 0% 100%, ...

Implementing jQuery selector for CSS and properly handling special characters in the code

I've been attempting to use jQuery to change the background color of a radio button. I provided the CSS code below, but even after escaping special characters in jQuery as shown below, the solution still isn't working. #opt5 > [type="radio"]: ...

Using Object type for Entity Framework Entity properties

I am currently dealing with a unique situation where I have multiple versions of databases that I cannot modify. My MVC application, which is read-only, is connected to these databases using Entity Framework on various environments. The issue arises when t ...

How can the combination of "hello" + + '/' + "world" result in "hello47world"?

In this scenario with C#, it's interesting to note that a==true: bool a = "hello" + '/' + "world" == "hello/world"; Similarly, in this other situation in C#, b==true: bool b = "hello" + + '/' + "world" == "hello47world"; This ...

Lifecycle Management of IIS Configuration, Ensuring Security of ASP.net Web Services

Recently, I developed a web service using ASP .Net which involves a web config file that stores security details for our Microsoft Dynamics Axapta AOS server, including a username and password for Axapta authentication. This web service interacts with a D ...

The issue of responsive spacing (such as mb-lg-2 mb-sm-3, etc) not functioning as expected has been identified in Bootstrap

Previously in Bootstrap 4, these classes were effective. However, I am finding that they are not functioning properly in Bootstrap 5. Any insights as to why this might be happening? Note: d-block d-lg-flex , text-center text-lg-start text-md-end seem to s ...

employing the display flex property triggers the emergence of a lavender border

This is an example of a basic HTML structure: <section id="teasers"> <div class="wrapper"> <a href=""> <div class="redbox"> <h2 class="two-lines uppercaseme lowercaseme"> ...

Step by step guide to applying a personalized "margin" to your CSS

I have set the body element's margin to 0 in my CSS stylesheet. However, I am struggling to successfully set the margin for the div elements. Therefore, I would like to set all other things' margin to 0; except for the div elements with the cl ...

Is it possible to enhance this straightforward .NET code by utilizing Generics in order to efficiently return the result with strong typing?

Remember that all of the code mentioned below can be found in this .NET Fiddle. I'm struggling once again to understand Generics, covariance, and contravariance. It's really challenging for me, so please bear with me. Imagine I have a fictitiou ...

Arranging images next to each other using CSS and HTML

I've been trying to arrange four images side by side, with two on the top row and two on the bottom. I want to ensure they stay consistent across all browser sizes except for mobile. Here is what I have attempted so far: #imageone{ position: absol ...

FAQs about utilizing percentage width and margins in CSS with Bootstrap

Currently, I am working on a mobile responsive web design using Twitter Bootstrap 3, and I am facing challenges with margins and resizing. I previously asked about creating a mobile-first responsive web design along with responsive images, which you can f ...

Comparing strings while handling null values

Whenever I need to compare two strings, I typically use the following code: if(!string.IsNullOrEmpty(str1) && str1.Equals(str2)){ //they are equal, do my thing } This code takes care of handling the null case first. I am wondering if there i ...

Try placing the div class above the navbar in Bootstrap

I've created these fork me ribbons in CSS with the intention of placing them on top of the navbar, similar to the Github images. Here is how they currently appear: http://jsbin.com/womib/1 .ribbon { background-color: #F38419; overflow: h ...

End of container Bootstrap 4 row with two columns at the edge

I'm currently working on an angular project with bootstrap 4. Within the container, there are two rows. I specifically want one row to always be positioned at the bottom of the container. Despite trying methods like justify-content: flex-end;, botto ...

What is the best way to conceal a column within an asp:Table?

In my ASP.NET project, I currently have a basic table structure created using ASP.NET like this: <asp:Table id="tbl"> <asp:TableHeaderRow id="header"> <asp:TableHeaderCell id="hcell1" /> </asp:TableHeaderRow> &l ...