Blending the widths of native elements with those of Bootstrap columns

Having trouble aligning spans in a Bootstrap 3 form to degrade into a stack on mobile:

From [station1] to [station2] at [time]

From
[station1]
to
[station2]
at
[time]

While this code works to an extent:

  <div class="row">
     <div class="col-md-1">From</div>
     <div class="col-md-3"><select>...</select></div>
     <div class="col-md-1">To</div>
     <div class="col-md-3"><select>...</select></div>
     ...
  </div>

It doesn't look great on wide screens:

    From       [station1]     to      [station2]     at     [time]

Spans without col-X-Y classes don't work well with Bootstrap, and mixing grid and non-grid elements leads to ordering issues. Here's a JSFiddle link illustrating the problem: here. Any suggestions?

Answer №1

While Bootstrap can be helpful, it's important to remember that it is not a one-size-fits-all solution. Sometimes, you will still need to write your own CSS to fine-tune the styling of your website. If you want to customize your column widths for larger screens, using the appropriate Bootstrap classes may not always be sufficient.

It can be more effective to create your own CSS styles, such as making elements display as inline-block and adding margin and padding where necessary. For more advanced customization, consider writing your own media queries to handle styles at different screen widths.

Take a look at line 260 in the variables file within Bootstrap for reference.

@screen-xs:                  480px;
@screen-xs-min:              @screen-xs;
@screen-phone:               @screen-xs-min;

You can utilize these variables to create CSS that specifically targets different viewport sizes.

@media (max-width: $screen-xs) {
  // Adjust styles for smaller screens
  span.my-field {
    display: block;
    margin-bottom: 10px;
  }
}

If you're not using preprocessors like Sass or Less, you can simply replace the variable placeholders with hardcoded values, such as using "480px" instead of "$screen-xs".

Answer №2

One way to adjust the column width is to use a smaller class like col-sm-5 or col-sm-6..

<div class="row">
  <div class="col-sm-4">
     <div class="col-lg-2">Starting Point</div>
     <div class="col-lg-2"><select><option>station</option></select></div>
     <div class="col-lg-2">Destination</div>
     <div class="col-lg-2"><select><option>station</option></select></div>
     <div class="col-lg-2">Departure Time</div>
     <div class="col-lg-2"><select><option>time</option></select></div>
  </div>
</div>

See it in action here: http://www.bootply.com/116599

Answer №3

Here's a different method:

<section>Starting with</section>
<br class="viewable-phone viewable-tablet"/>
<section>...</section>
<br class="viewable-phone viewable-tablet"/>

It may not look pretty, but it appears to be functioning smoothly. So far, no issues have arisen.

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

What techniques can be used to resize an image to perfectly fit a square on a webpage?

A challenge on the web page is to display images in a square format of 90 * 90 pixels. However, the sizes of these images are not consistent and may vary from 80*100 to 100*80 or even 90 * 110. The requested solution is to stretch the image as follows: ...

Utilize ngFor in Angular Ionic to dynamically highlight rows based on specific criteria

I'm working on an application where I need to highlight rows based on a count value using ngFor in Angular. After trying different approaches, I was only able to highlight the specific row based on my count. Can someone please assist me? Check out m ...

Tips for arranging columns and rows in a mat-dialog box

In my Angular project, I am working on a mat dialog box and trying to achieve a layout with 1 row at the top and 3 rows at the bottom, similar to the image below. However, I am facing issues in making it work properly. Additionally, I want to hide the hori ...

Modify the text color upon clicking with a TouchableOpacity component

Would appreciate help from experienced coders. I'm just starting out with coding and React. My goal is to be able to change the text color with a click, and then change it back to the original color with another click. function handleColorChange() { ...

How can you customize gutter widths for specific rows in Bootstrap 3?

Currently, I am constructing my own website using Bootstrap 3 and have come across a challenge that I would like to address: My goal is to assign distinctive gutter widths to certain rows in my design. The remaining sections of the site will adhere to th ...

Tips for customizing column width in v-simple-table with Vuetify.js component

For my most recent projects UI component, I decided to use vuetify.js. I attempted to adjust the width of the th and td elements within a v-simple-table using CSS, but unfortunately, nothing seemed to happen. My goal was to set the width of every th and td ...

Is it possible to insert JavaScript code with the <link> element?

Is it possible to include JavaScript code using the <link> tag on my website? For instance, if I have a JavaScript file named test.js that includes the simple code alert('hello'); Can I trigger a popup window to appear by using the follow ...

using an SVG mask declared in HTML to apply masking

I've been experimenting with masking using an SVG shape that I created in the HTML content. I've tried various options: mask, -webkit-mask mask-image, -webkit-mask-image different MaskUnits and MaskContentUnits mask-type: luminance or not Desp ...

Tips for maintaining a stationary element with fluctuating height positioned at the bottom in React

I am trying to create a fixed element with dynamic height, meaning its size changes when the browser window is resized. You can see an example of what I'm talking about here: https://stackblitz.com/edit/react-yuqarh?file=demo.tsx This element acts li ...

The results of running 'npm run dev' and 'npm run build prod' are different from each other

Currently, I am in the process of developing a progressive web app using Vue.js. During development, I utilize the command npm run dev to initiate the local server that serves the files over at http://localhost:8080/. When it comes time to build for produ ...

Turn off Appbar padding at the top and bottom

I am looking to create a customized box within the Appbar that spans the full height, as illustrated in the image below: https://i.stack.imgur.com/CFMo0.jpg However, the default Appbar provides padding from all sides to its internal elements, leading to ...

Utilizing Bootstrap 5 for Angular Projects

With the release of version 5, the Bootstrap framework has eliminated the need for jQuery. I am curious about how this change impacts Angular applications. Can we still utilize all of Bootstrap's features in Angular, such as dropdowns? In the past, ...

Emphasizes the P tag by incorporating forward and backward navigation options

My goal is to enable users to navigate up and down a list by pressing the up and down arrow keys. For example, if "roma" is currently highlighted, I want it to change to "milan" when the user presses the down arrow key. Here is the HTML code I am working w ...

Reverse the color of H1 text within a vertical div

Is it feasible to reverse the coloring of a segment within an h1 element using a div, horizontally? Refer to the illustration shown in the image below. https://i.sstatic.net/QAKwD.jpg ...

Real estate for a targeted audience

1. Overview I have a list of selectors that should always apply certain properties. Some selectors require additional properties to be added. I'm struggling to find a way to achieve this without repeating code. 2. Minimal CSS Example (MCVE) 2.1 ...

Closing the Bootstrap navbar collapse by clicking anywhere outside of the menu area

Excuse my lack of experience, but I have a question. I am trying to make Bootstrap "navbar-collapse" close when clicking away or on one of the list items. I stumbled upon this code that seems to do the trick. $(document).on('click',function() { ...

"Encountering a Challenge with Setting Up Forms on

I've recently started learning to code and I'm facing an issue with my form appearing stretched out. You can view it here: I initially thought it was due to margins, so I increased them. Then, I tried adjusting the width to 50%, but that didn&ap ...

Styling Lists in HTML/CSS: How to Highlight an Entire Row with a Background Color When Using list-style?

I've been working on revamping the menu layout on my website. Currently, I am using a list with a circle style type to display the menu options. Here's a glimpse: Here is the code snippet: <li class='category'><a href=' ...

Is it possible to leverage the className attribute in Material UI components?

Currently using React alongside Material-UI(MUI) for the frontend development. Encountering an issue with the Button Component in MUI, specifically the className prop. Struggling to apply custom styles using classes defined in the style.css file. Conside ...

Bootstrap: Problem arises when columns do not total up to 12 and are pushed onto separate rows

So, I've been working with Bootstrap to structure columns and rows. It seems like I have the container, rows, and columns set up correctly for each post. However, I am puzzled as to why a new row is created for every post I make, causing them to stack ...