Issues arising from the visibility and concealment of elements using bootstrap

Struggling with hiding certain content in my code. I'm fairly new to coding, having just started about a week ago. So far, I've learned HTML, CSS (which I find the most important), and how to utilize Bootstrap 4. My issue lies in wanting to hide specific content on small screens. Despite hours of searching online, all I could find were the d-none and d-sm-block tags for hiding and showing elements. I've attempted to implement these solutions into my code without success, so I'm hoping someone can provide guidance. Specifically, I want the search bar, login, and register buttons to disappear on smaller screens, only to be replaced by a small dropdown menu containing the login and register options. While I realize I didn't use Bootstrap as a navbar at the top due to limited knowledge at the time and a preference for button size, I still hope for assistance.

The beginning of my HTML code. (Note: The hot pink buttons appear larger in actuality because there is additional text included)

<head>
    <title>hello world</title>
    <link rel="stylesheet" href="../test_sublime/css/bootstrap.css">
    <link href="test1.css" rel="stylesheet" type="text/css">
</head>
<body>
    <header>
        <h2><em><u>Header</u></em>.no</h2>
        <nav class="headnav">
            <ul>
                <li class="hotpink"><a class="b_link" href="#">Test</a></li>
                <li class="hotpink"><a class="b_link" href="#">Test</a></li>
                <li class="hotpink"><a class="b_link" href="#">Test</a></li>
                <li class="hotpink"><a class="b_link" href="#">Test</a></li>
                <li class="hotpink"><a class="b_link" href="#">Test</a></li>
            </ul>
        </nav>      
        <div class="btn-group">
            <a href="../test_sublime/logg in.html" class="btn btn-primary" role="button">Log In</a>
            <a href="../test_sublime/registrer.html" class="btn btn-primary" role="button">Register</a>
        <!--This is the search bar I want to hide when the screen is small-->
        </div>
            <form class="form-inline my-lg sok">
                <input class="form-control mr-sm-2 msok" type="search" placeholder="Search" aria-label="Search">
                <button class="btn btn-outline-success my-2 my-sm-0 msok" type="submit">Search</button>
            </form>
        <!--I want this dropdown menu to show up when the screen is small-->
        <div class="dropdown-menu d-block d-sm-none" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="../test_sublime/logg in.html">Log In</a>
          <a class="dropdown-item" href="../test_sublime/registrer.html">Register</a>
          <div class="dropdown-divider"></div>
        </div>
    </header>

        ...

    <footer>
        ...
    <script src="https://code.jquery.com/jquery-3.3.1.js"
            integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
            crossorigin="anonymous"></script>
    <script>window.jQuery || document.write('<script scr="../test_sublime/jQuery/jquery.js"><\/script>');</script>
    <script type="text/javascript" src="../test_sublime/js/test.js"></script>
    <script src="test_sublime/js/bootstrap.min.js"></script>
    </footer>
</body>

Excerpts from my CSS

body {
background: pink;
margin-left: 12px;
margin-right: 12px;
margin-top: 10px;
}

h2 {
display:inline;
background: mediumvioletred;
padding: 20px 40px 7px 40px;
margin: 0px 5px 40px -15px;
border-radius: 4px;
}

ul {
display: inline;
margin: 0px 0px 0px -38px
}

.sok {
display: inline-block;
float: right;
margin-right: 35px;
margin-top: 10px;
}

.msok {
margin-top: 0px;
}

.btn-group { 
padding: 0px 10px 0px -10px
display: inline;
float: right;
margin-top: 10px;
}

nav.headnav {
display: inline-block;
}

Are there any Bootstrap-specific solutions or do I need to resort to JavaScript? (Apologies for the color choices)

Answer №2

Try this solution with the navbar class to fix your issue.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="bootstrap.css">
<script src="jquery.js"></script>
<script src="bootstrap.js"></script>
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#">yourbrand</a>
      </div>

      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav">
          <li class="active"><a href="#">Home <span class="sr-only">(current)</span></a></li>
          <li><a href="#">About</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">Separated link</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">One more separated link</a></li>
            </ul>
          </li>
        </ul>
        <form class="navbar-form navbar-left">
                <div class="input-group">
                        <input type="text" class="form-control" placeholder="Search">
                        <span class="btn input-group-addon">Search</span>
                </div>
        </form>
        <ul class="nav navbar-nav navbar-right">
            <div class="btn-group">
                <a href="../test_sublime/logg in.html" class="btn btn-primary" role="button">Log In</a>
                <a href="../test_sublime/registrer.html" class="btn btn-primary" role="button">Register</a>
            </div>
        </ul>
      </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
  </nav>
</body>
</html>

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

Hover effect for child element not activating CSS3 Transition

I need my list item to activate a css3 transition on its child element .pusher when it is hovered over. I usually achieve this using JS, but I want to try implementing it with css3 transitions. After reading some other questions on SO, I attempted to do it ...

Display the list in a grid format with 4 columns and x number of rows by utilizing Angular and Bootstrap

I need to display a list of values [1,2,3,4,5,6,7,8,9,10] as a bootstrap grid (class="col-x") using AngularJS. My goal is to create a grid with 4 columns and 3 rows from this list. Can you suggest the most efficient method to achieve this? ...

Utilize the v-for second argument in VueJS 2 to showcase the index and index+1

For a VueJS 2 project, I am tasked with enhancing the display of the first and second elements in an array by making them stand out from the rest. To achieve this, I am utilizing the v-for syntax to iterate over a child component within a parent component. ...

Tips for adjusting the maximum height of the column panel within the DataGrid element

I'm trying to adjust the max-height of a column panel that opens when clicking the "Columns" button in the Toolbar component used in the DataGrid. I am working with an older version of @material-ui/data-grid: "^4.0.0-alpha.8". https://i.stack.imgur.c ...

Activate the Twitter Bootstrap Lightbox when the page is loaded

Is there a way to make my twitter bootstrap lightbox automatically trigger when the HTML page loads? Currently, I have this script in my 'main.js' file: function lightbox(){ $('#myLightbox').lightbox(); }; I heard that I can us ...

How to trigger the submission of a form within the submission event of another form using jQuery

I am encountering an issue with having two forms on a single page. Whenever I click on the submit button of the parent form, the parent form's submit event is triggered. In this event, I have included logic to submit the second form using the submit m ...

Is it possible to integrate React Bootstrap with Next.js?

Is it possible to integrate react-bootstrap with Next.js? I have the latest versions of both, but none of my react-bootstrap components are showing up in my app. I've searched online for solutions, but haven't found anything helpful. If needed, I ...

Create a dynamic MUI icon that adapts to different screen sizes

Struggling to make the MUI DeleteIcon responsive and clickable. <ListItem> <ListItemAvatar> <Avatar src={sprites.front_default}> <ImageIcon /> </Avatar> </ListItemAvatar> <ListItemText pr ...

Tips for setting up a popup menu when clicking a button on a webpage

I am currently working on developing a popup menu with a greyed-out background that appears when the user clicks on a button in React. My code implementation is as follows: // The ifButtonClicked function is called when another button is clicked // Some ...

What causes IE11 to sporadically run inappropriate media queries?

My website has been displaying incorrectly on IE11 due to a media query being executed for widths less than 767px, even though the window width is actually more than that. Interestingly, this issue only occurs randomly and never when the debug window is op ...

Using div tags may cause rendering issues

I am trying to use multiple div tags with webkit borders, but for some reason only the one called 'Wrapper' is displaying properly. Here is my code: .wrapper { margin: 20px auto 20px auto; width: 800px; background: url('images/background_1. ...

Tips for styling Ajax.ActionLink elements with CSS

Hi there, I'm trying to style a navigation bar using CSS. I'm pulling the navigation bar values from a database using Ajax.ActionLink. I attempted to use JavaScript but encountered an error stating "jQuery is not defined", Here's the cod ...

Is it possible to make the v-toolbar-title fixed within a v-navigation-drawer using Vuetify?

Can the <v-toolbar-title> be fixed within a <v-navigation-drawer>? <v-card class="d-inline-block elevation-12"> <v-navigation-drawer hide-overlay permanent stateless height="440" value="true"> <v-toolbar color="whi ...

What steps are involved in creating a webpage cleaner similar to Arc90's Readability or Instapaper?

Curious about cleaning up an HTML page to present it in a more polished manner - eliminating clutter and restructuring the main text for better readability, similar to resources like or Instapaper. Would the process involve basic page parsing and filteri ...

Safari: The onbeforeunload event

Welcome! To experience the Leave | Stay confirmation box on your page, please make sure you are using Safari 10. I am currently facing an issue with getting the confirmation box to display properly across different browsers. To begin, please visit and l ...

Challenges encountered while working with OpenWeather API

I created a weather prediction web application using p5.js. It functions perfectly on my local server. However, I keep encountering this issue on the GitHub page: Mixed Content: The page at '' was loaded over HTTPS, but requested an insecure ...

Clicking on an anchor tag will open a div and change the background color

.nav_bar { background: #c30015; margin-left: 50px; float: left; } .nav_bar ul { padding: 0; margin: 0; display: flex; border-bottom: thin white solid; } .nav_bar ul li { list-style: none; } .nav_bar ul li a { ...

I struggle to format a classic HTML form dropdown menu that is populated using JavaScript

Hey everyone, I'm having an issue with styling a drop down menu that is populated by JavaScript. I've tried different things but nothing seems to be working. Any suggestions on how I can style the elements in the drop down? <form action="" me ...

Monitoring the modifications of a linked component in React: A guide

I am facing an issue where I need to store the text of a referenced element in an array. My goal is to first display the text of each paragraph element with the "ebookName" class in the console before storing it in the array. However, I have encountered a ...

CSS border margin-bottom attribute not functioning correctly

I am trying to create a page border by wrapping it around the content using a <div> element. The parent element is the actual page itself. However, I'm having trouble with the margin-bottom property as it doesn't seem to be working properly ...